nuttx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xiaoxi...@apache.org
Subject [incubator-nuttx] 01/02: libc/netdb: make getaddrinfo re-entrant also when querying with service name
Date Mon, 27 Apr 2020 11:52:36 GMT
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit ba0a17ca8ca4f1d68d2169ecb7138f3d0fe5c66d
Author: Juha Niskanen <juha.niskanen@haltian.com>
AuthorDate: Fri Apr 24 12:11:03 2020 +0300

    libc/netdb: make getaddrinfo re-entrant also when querying with service name
    
    Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
---
 libs/libc/netdb/lib_getaddrinfo.c   | 5 +++--
 libs/libc/netdb/lib_netdb.c         | 2 +-
 libs/libc/netdb/lib_parsehostfile.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libs/libc/netdb/lib_getaddrinfo.c b/libs/libc/netdb/lib_getaddrinfo.c
index 93c2775..501984e 100644
--- a/libs/libc/netdb/lib_getaddrinfo.c
+++ b/libs/libc/netdb/lib_getaddrinfo.c
@@ -161,8 +161,9 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
 
   if (servname != NULL)
     {
-      FAR char *endp;
+      struct servent ent;
       FAR struct servent *sp;
+      FAR char *endp;
 
       port = strtol(servname, &endp, 10);
       if (port > 0 && port <= 65535 && *endp == '\0')
@@ -175,7 +176,7 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
         {
           return EAI_NONAME;
         }
-      else if ((sp = getservbyname(servname, NULL)) != NULL)
+      else if (getservbyname_r(servname, NULL, &ent, NULL, 0, &sp) == OK)
         {
           /* The s_port field of struct servent is required to
            * be in network byte order (per OpenGroup.org)
diff --git a/libs/libc/netdb/lib_netdb.c b/libs/libc/netdb/lib_netdb.c
index f93b30a..fa72da0 100644
--- a/libs/libc/netdb/lib_netdb.c
+++ b/libs/libc/netdb/lib_netdb.c
@@ -69,7 +69,7 @@ bool convert_hostent(const FAR struct hostent_s *in,
   int i;
   int j;
 
-  /* Initialize the ouptut of hostent */
+  /* Initialize the output of hostent */
 
   out->h_name = in->h_name;
   out->h_aliases = in->h_aliases;
diff --git a/libs/libc/netdb/lib_parsehostfile.c b/libs/libc/netdb/lib_parsehostfile.c
index 4507b8c..caf81f0 100644
--- a/libs/libc/netdb/lib_parsehostfile.c
+++ b/libs/libc/netdb/lib_parsehostfile.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * libs/libc/netdb/lib_parsehostile.c
+ * libs/libc/netdb/lib_parsehostfile.c
  *
  *   Copyright (C) 2015 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gnutt@nuttx.org>


Mime
View raw message