From d8f75d3206eaa56b3a819a5bc13a4bf3a9130512 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Tue, 10 Dec 2013 17:02:34 -0600 Subject: [PATCH] cellconfig: Do not use 'long' for dbserver IPs A few places in this file assume that our dbserver IP addresses are "long"s. A long int can be 8 bytes on some platforms, but we know these IP addresses are all 4-byte integers. In the rare instances where we have the maximum number of dbservers, this can overwrite a bit of extra memory. This can also result in a misaligned access on platforms such as SPARC v9, since the elements of he->h_addr_list are not guaranteed to be 8-byte aligned. So instead, treat these as 4-byte integers. For copying out of he->h_addr_list, also use a memcpy anyway to be safe, since we are not guaranteed alignment. Change-Id: I1afd6e49df32693f86392cb39ce8d7477422aa94 Reviewed-on: http://gerrit.openafs.org/10599 Tested-by: BuildBot Reviewed-by: Jeffrey Altman --- src/auth/cellconfig.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/auth/cellconfig.c b/src/auth/cellconfig.c index 2509ec761..9ff408251 100644 --- a/src/auth/cellconfig.c +++ b/src/auth/cellconfig.c @@ -1296,7 +1296,7 @@ afsconf_GetAfsdbInfo(char *acellName, char *aservice, for (i = 0; i < numServers; i++) { memcpy(&acellInfo->hostAddr[i].sin_addr.s_addr, &cellHostAddrs[i], - sizeof(long)); + sizeof(afs_uint32)); memcpy(acellInfo->hostName[i], cellHostNames[i], MAXHOSTCHARS); acellInfo->hostAddr[i].sin_family = AF_INET; if (aservice) @@ -1415,8 +1415,11 @@ afsconf_GetCellInfo(struct afsconf_dir *adir, char *acellName, char *aservice, /* check to see if this is a new address; if so insert it into the list */ int k, dup; for (k=0, dup=0; !dup && k < numServers; k++) { - if (hostAddr[k].sin_addr.s_addr == *(u_long *)he->h_addr_list[i]) + afs_uint32 addr; + memcpy(&addr, he->h_addr_list[i], sizeof(addr)); + if (hostAddr[k].sin_addr.s_addr == addr) { dup = 1; + } } if (dup) continue; @@ -1426,7 +1429,7 @@ afsconf_GetCellInfo(struct afsconf_dir *adir, char *acellName, char *aservice, #ifdef STRUCT_SOCKADDR_HAS_SA_LEN hostAddr[numServers].sin_len = sizeof(struct sockaddr_in); #endif - memcpy(&hostAddr[numServers].sin_addr.s_addr, he->h_addr_list[i], sizeof(long)); + memcpy(&hostAddr[numServers].sin_addr.s_addr, he->h_addr_list[i], sizeof(afs_uint32)); strcpy(hostName[numServers], acellInfo->hostName[j]); foundAddr = 1; numServers++; -- 2.39.5