]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fixed of-by-one error in tor_inet_ntop
authorAnders Sundman <anders@4zm.org>
Fri, 11 Nov 2011 06:47:00 +0000 (07:47 +0100)
committerAnders Sundman <anders@4zm.org>
Fri, 11 Nov 2011 06:47:00 +0000 (07:47 +0100)
The of-by-one error could lead to 1 byte buffer over runs IPv6 for addresses.

src/common/compat.c

index 2cf7f463c1cd828ecf796cc55b33e8bb6608d8a2..ba49af757cbd2fde5d8a2f21e8ed0fa0d30654b2 100644 (file)
@@ -1632,7 +1632,7 @@ tor_inet_ntop(int af, const void *src, char *dst, size_t len)
                      addr->s6_addr[12], addr->s6_addr[13],
                      addr->s6_addr[14], addr->s6_addr[15]);
       }
-      if (strlen(buf) > len)
+      if ((strlen(buf) + 1) > len) /* +1 for \0 */
         return NULL;
       strlcpy(dst, buf, len);
       return dst;
@@ -1673,7 +1673,7 @@ tor_inet_ntop(int af, const void *src, char *dst, size_t len)
       }
     }
     *cp = '\0';
-    if (strlen(buf) > len)
+    if ((strlen(buf) + 1) > len) /* +1 for \0 */
       return NULL;
     strlcpy(dst, buf, len);
     return dst;