]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 710] Backport Danny's latest patch
authorHarlan Stenn <stenn@ntp.org>
Mon, 18 Sep 2006 22:06:02 +0000 (18:06 -0400)
committerHarlan Stenn <stenn@ntp.org>
Mon, 18 Sep 2006 22:06:02 +0000 (18:06 -0400)
bk: 450f184a8CsMdTo5yjd3M-EzF0-nZQ

libntp/ntp_rfc2553.c

index ddd421d073ca144b69c3d6686cb2bafe3be7b6a6..b5e0ecacc9646bdedbcfe06476b8fd71b1aa804e 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] = '\0';
+               }
        }
        return (0);
 }