From: Nickolai Zeldovich Date: Sun, 6 Jan 2013 04:44:55 +0000 (-0500) Subject: ubik/udebug.c: check array index before dereferencing X-Git-Tag: upstream/1.6.3^2~95 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=6751327f6f7ba1389c6caf1207abe78e9cdb0d70;p=packages%2Fo%2Fopenafs.git ubik/udebug.c: check array index before dereferencing Avoid out-of-bounds array accesses by first checking that the index is in-bounds, and then dereferencing; not the other way around. Reviewed-on: http://gerrit.openafs.org/8879 Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman Tested-by: BuildBot (cherry picked from commit 0e83cde60e6e91fbe20ffac0f0a77afe8497d950) Change-Id: I7a5018011939d43b702c63a272d53a2018df7d33 Reviewed-on: http://gerrit.openafs.org/9513 Reviewed-by: Derrick Brashear Reviewed-by: Andrew Deason Reviewed-by: Stephan Wiesand Tested-by: BuildBot --- diff --git a/src/ubik/udebug.c b/src/ubik/udebug.c index 83a395f27..0bb742850 100644 --- a/src/ubik/udebug.c +++ b/src/ubik/udebug.c @@ -163,7 +163,7 @@ CommandProc(struct cmd_syndesc *as, void *arock) times[24] = 0; if (!oldServer) { printf("Host's addresses are: "); - for (j = 0; udebug.interfaceAddr[j] && (j < UBIK_MAX_INTERFACE_ADDR); + for (j = 0; (j < UBIK_MAX_INTERFACE_ADDR) && udebug.interfaceAddr[j]; j++) printf("%s ", afs_inet_ntoa_r(htonl(udebug.interfaceAddr[j]), hoststr)); printf("\n"); @@ -296,7 +296,7 @@ CommandProc(struct cmd_syndesc *as, void *arock) /* otherwise print the structure */ printf("\nServer (%s", afs_inet_ntoa_r(htonl(usdebug.addr), hoststr)); for (j = 0; - ((usdebug.altAddr[j]) && (j < UBIK_MAX_INTERFACE_ADDR - 1)); + ((j < UBIK_MAX_INTERFACE_ADDR - 1) && (usdebug.altAddr[j])); j++) printf(" %s", afs_inet_ntoa_r(htonl(usdebug.altAddr[j]), hoststr)); printf("): (db %d.%d)", usdebug.remoteVersion.epoch,