]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4969: GCC-9 build failure: stringop-truncation (#441)
authorAmos Jeffries <yadij@users.noreply.github.com>
Fri, 19 Jul 2019 15:11:49 +0000 (15:11 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sun, 28 Jul 2019 02:52:56 +0000 (02:52 +0000)
GCC-9 with Squid use of -Werror makes these warning hard
errors which can no longer be ignored. We are thus required
to alter this third-party code when built for Squid.

Truncation of these strings is fine. Rather than suppress
GCC warnings, switch to xstrncpy() which has similar
behaviour but guarantees c-string terminator exists within
the copied range limit (removing need for two -1 hacks).

This change will add terminators on path and device_type
values in the rare case of overly long configured values.
It is not clear what ancient Domain Controllers would do
when handed un-terminated c-string in those cases, but was
unlikely to be good.

lib/smblib/smblib-util.c

index 10e6220b7f99f9d450ea0a5ff4d1b6f4e4513b63..fcff357eeda2e983fdb7925d4f40126757f42dd0 100644 (file)
@@ -401,7 +401,7 @@ int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[])
 
         p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset + Con_Handle -> Encrypt_Key_Len);
 
-        strncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom) - 1);
+        xstrncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom));
 
         break;
 
@@ -424,7 +424,7 @@ int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[])
 
         p = (SMB_Hdr(pkt) + SMB_negrLM_buf_offset + Con_Handle -> Encrypt_Key_Len);
 
-        strncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom) - 1);
+        xstrncpy(p, Con_Handle -> Svr_PDom, sizeof(Con_Handle -> Svr_PDom));
 
         break;
 
@@ -538,8 +538,8 @@ SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type Con_Handle,
 
     tree -> next = tree -> prev = NULL;
     tree -> con = Con_Handle;
-    strncpy(tree -> path, path, sizeof(tree -> path));
-    strncpy(tree -> device_type, device, sizeof(tree -> device_type));
+    xstrncpy(tree -> path, path, sizeof(tree -> path));
+    xstrncpy(tree -> device_type, device, sizeof(tree -> device_type));
 
     /* Now plug in the values ... */