]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix string truncation in getnameinfo() (#462)
authorAmos Jeffries <yadij@users.noreply.github.com>
Sun, 5 Jan 2020 13:29:29 +0000 (13:29 +0000)
committerAmos Jeffries <yadij@users.noreply.github.com>
Thu, 19 Mar 2020 10:49:01 +0000 (23:49 +1300)
strncpy can leave strings unterminated. Use xstrncpy instead
of relying on callers to terminate their buffers.

compat/getnameinfo.cc

index 251daf6a364425f233f104cfe69ef66244750ccc..c2dea9b5620781df77aa80c202fb6028ddb6cd5c 100644 (file)
@@ -203,12 +203,12 @@ found:
         if (sp) {
             if (strlen(sp->s_name) + 1 > servlen)
                 return EAI_OVERFLOW;
-            strncpy(serv, sp->s_name, servlen);
+            xstrncpy(serv, sp->s_name, servlen);
         } else {
             snprintf(numserv, sizeof(numserv), "%u", ntohs(port));
             if (strlen(numserv) + 1 > servlen)
                 return EAI_OVERFLOW;
-            strncpy(serv, numserv, servlen);
+            xstrncpy(serv, numserv, servlen);
         }
     }
 
@@ -301,7 +301,7 @@ found:
 #endif
                 return EAI_OVERFLOW;
             }
-            strncpy(host, hp->h_name, hostlen);
+            xstrncpy(host, hp->h_name, hostlen);
 #if USE_GETIPNODEBY
             freehostent(hp);
 #endif
@@ -351,7 +351,7 @@ int flags;
     numaddrlen = strlen(numaddr);
     if (numaddrlen + 1 > hostlen) /* don't forget terminator */
         return EAI_OVERFLOW;
-    strncpy(host, numaddr, hostlen);
+    xstrncpy(host, numaddr, hostlen);
 
     if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) {
         char zonebuf[SQUIDHOSTNAMELEN];