Fix an IPv6 breakage I introduced by adding an strlcpy truncation check. Found by...
authorJeremy Allison <jra@samba.org>
Sat, 31 Mar 2012 04:21:57 +0000 (21:21 -0700)
committerJeremy Allison <jra@samba.org>
Sat, 31 Mar 2012 05:59:15 +0000 (07:59 +0200)
The truncate of the strlcpy() here was a *desired* side effect.
strlcpy()/strlcat() should never be used like that. Be more
explicit about the truncation and don't use strlcpy here.

Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Sat Mar 31 07:59:16 CEST 2012 on sn-devel-104

lib/util/util_net.c

index 69e5324180f5d597105ae3bd9543ecac4552465d..36b3fcbc4a6f2a3eb9d4dd7c365ae27dec87ed38 100644 (file)
@@ -107,11 +107,18 @@ static bool interpret_string_addr_pref(struct sockaddr_storage *pss,
                 */
 
                if (p && (p > str) && ((scope_id = if_nametoindex(p+1)) != 0)) {
-                       size_t len = MIN(PTR_DIFF(p,str)+1, sizeof(addr));
-                       if (strlcpy(addr, str, len) >= len) {
-                               /* Truncate. */
+                       /* Length of string we want to copy.
+                          This is IP:v6:addr (removing the %ifname).
+                        */
+                       size_t len = PTR_DIFF(p,str);
+
+                       if (len+1 > sizeof(addr)) {
+                               /* string+nul too long for array. */
                                return false;
                        }
+                       memcpy(addr, str, len);
+                       addr[len] = '\0';
+
                        str = addr;
                }
        }