]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
rxdebug: NUL-terminate version before printing
authorAndrew Deason <adeason@dson.org>
Thu, 15 Feb 2018 22:41:33 +0000 (16:41 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 23 Feb 2018 04:18:14 +0000 (23:18 -0500)
Currently, 'rxdebug -version' never initializes the buffer we read the
version string into. Usually this is not noticeable, since all OpenAFS
binaries tend to pad the Rx version response packet with NULs, so we
get back several NULs to terminate the string. However, this is not
guaranteed, and if we do not get back a NUL-terminated string, we can
easily read beyond the end of the buffer.

To avoid this, initialize the 'version' buffer with NULs before we do
anything, and set the last byte to NUL, in case we exactly filled the
buffer.

Reviewed-on: https://gerrit.openafs.org/12908
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Andrew Deason <adeason@sinenomine.net>
(cherry picked from commit a66629eac4dda4eea37b4f06e0850641cb2a7387)

Change-Id: I850ce16840ee264dce506e8b3c887004bca11e20
Reviewed-on: https://gerrit.openafs.org/12912
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
src/rxdebug/rxdebug.c

index e4dcfcf4633dcb54d71ed73e8018509569e1e6e0..3d4bf0a513c7d5145ba2b7c99f069d313035ba84 100644 (file)
@@ -213,6 +213,7 @@ MainCommand(struct cmd_syndesc *as, void *arock)
     }
 
     if (version_flag) {
+        memset(version, 0, sizeof(version));
 
        code = rx_GetServerVersion(s, host, port, length, version);
        if (code < 0) {
@@ -220,6 +221,7 @@ MainCommand(struct cmd_syndesc *as, void *arock)
                   errno);
            exit(1);
        }
+        version[sizeof(version) - 1] = '\0';
        printf("AFS version: %s\n", version);
        fflush(stdout);