You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by br...@apache.org on 2018/07/10 10:50:12 UTC

zookeeper git commit: ZOOKEEPER-3079: avoid unsafe use of sprintf(3)

Repository: zookeeper
Updated Branches:
  refs/heads/master b593a8de1 -> 5d187ff0a


ZOOKEEPER-3079: avoid unsafe use of sprintf(3)

The function format_endpoint_info declares both addrstr and buf as 128
element char arrays, however on non-Windows platforms it calls
sprintf(3) to write into buf the value of addrstr followed by ':'
followed by the the port number.  This causes a compiler error when
building with GCC 8 because this could potentially overflow buf if the
value of addrstr was ever 127 characters long (or a little less
depending on how many digits are in port).  Of course, this couldn't
actually happen because addrstr is initialized by inet_ntop(3) which
won't write more than INET6_ADDRSTRLEN bytes (defined in <netinet/in.h>
on POSIX-compliant systems).  Of course, GCC doesn't know that, so let's
just declare addrstr as a char array of only size INET6_ADDRSTRLEN
instead of 128.

Signed-off-by: Kent R. Spillner <kspillneracm.org>

Author: Kent R. Spillner <ks...@acm.org>

Reviewers: Benjamin Reed <br...@apache.org>

Closes #559 from sl4mmy/zookeeper-3079


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/5d187ff0
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/5d187ff0
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/5d187ff0

Branch: refs/heads/master
Commit: 5d187ff0adc836e6d18fd4c78188f52cdbb56c25
Parents: b593a8d
Author: Kent R. Spillner <ks...@acm.org>
Authored: Tue Jul 10 03:50:07 2018 -0700
Committer: benjamin reed <br...@apache.org>
Committed: Tue Jul 10 03:50:07 2018 -0700

----------------------------------------------------------------------
 src/c/src/zookeeper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/5d187ff0/src/c/src/zookeeper.c
----------------------------------------------------------------------
diff --git a/src/c/src/zookeeper.c b/src/c/src/zookeeper.c
index 7d82bf5..0db547e 100644
--- a/src/c/src/zookeeper.c
+++ b/src/c/src/zookeeper.c
@@ -4357,7 +4357,7 @@ int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
 static const char* format_endpoint_info(const struct sockaddr_storage* ep)
 {
     static char buf[128] = { 0 };
-    char addrstr[128] = { 0 };
+    char addrstr[INET6_ADDRSTRLEN] = { 0 };
     void *inaddr;
 #ifdef _WIN32
     char * addrstring;