]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Bug #710 fix the length being copied in getnameinfo
authorDanny Mayer <mayer@ntp.org>
Mon, 18 Sep 2006 12:46:18 +0000 (08:46 -0400)
committerDanny Mayer <mayer@ntp.org>
Mon, 18 Sep 2006 12:46:18 +0000 (08:46 -0400)
bk: 450e951aOOHA9PuPMJk5n4K9o5xL7A

libntp/ntp_rfc2553.c

index ddd421d073ca144b69c3d6686cb2bafe3be7b6a6..a3b3f2801e1ed8a589462dafd4f19e536539a0e3 100644 (file)
@@ -288,6 +288,7 @@ getnameinfo (const struct sockaddr *sa, u_int salen, char *host,
        size_t hostlen, char *serv, size_t servlen, int flags)
 {
        struct hostent *hp;
+       int namelen;
 
        if (sa->sa_family != AF_INET)
                return (EAI_FAMILY);
@@ -300,9 +301,15 @@ getnameinfo (const struct sockaddr *sa, u_int salen, char *host,
                else
                        return (EAI_FAIL);
        }
-       if (host != NULL) {
-               strncpy(host, hp->h_name, hostlen);
-               host[hostlen - 1] = '\0';
+       if (host != NULL && hostlen > 0) {
+               /*
+                * Don't exceed buffer
+                */
+               namelen = min(strlen(hp->h_name), hostlen - 1);
+               if (namelen > 0) {
+                       strncpy(host, hp->h_name, namelen);
+                       host[namelen - 1] = '\0';
+               }
        }
        return (0);
 }