Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from

Commits on Jul 3, 2018

  1. 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 <kspillner@acm.org>
    sl4mmy committed Jul 3, 2018
    Configuration menu
    Copy the full SHA
    cb26e2f View commit details
    Browse the repository at this point in the history