From 0e83cde60e6e91fbe20ffac0f0a77afe8497d950 Mon Sep 17 00:00:00 2001 From: Nickolai Zeldovich Date: Sat, 5 Jan 2013 23:44:55 -0500 Subject: [PATCH] ubik/udebug.c, vol/vol-info.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. Change-Id: Ib36a28ca6181a7a7fd602de45cb5a15fad099a44 Reviewed-on: http://gerrit.openafs.org/8879 Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman Tested-by: BuildBot --- src/ubik/udebug.c | 4 ++-- src/vol/vol-info.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ubik/udebug.c b/src/ubik/udebug.c index 99fd11083e..7954a84cec 100644 --- a/src/ubik/udebug.c +++ b/src/ubik/udebug.c @@ -144,7 +144,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"); @@ -277,7 +277,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, diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index c1fe3dbf32..0c8b2d1d1c 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -2116,7 +2116,7 @@ ModeMaskMatch(unsigned int modeBits) { int i; - for (i = 0; ModeMask[i] && i <= sizeof(ModeMask) / sizeof(*ModeMask); i++) { + for (i = 0; i < sizeof(ModeMask) / sizeof(*ModeMask) && ModeMask[i]; i++) { if ((ModeMask[i] & modeBits) == 0) { return 0; /* at least one mode bit is not present */ }