From 618343f0261bb5ffa036d93f1a3bc313ed76a037 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. Reviewed-on: http://gerrit.openafs.org/10599 Tested-by: BuildBot Reviewed-by: Jeffrey Altman (cherry picked from commit d8f75d3206eaa56b3a819a5bc13a4bf3a9130512) Change-Id: I2568577b05f47ebc75b34a9cd106fceac8a31ef7 Reviewed-on: http://gerrit.openafs.org/10603 Tested-by: BuildBot Reviewed-by: Andrew Deason Reviewed-by: Benjamin Kaduk Reviewed-by: Stephan Wiesand --- 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 b00d3191e..59a5cd889 100644 --- a/src/auth/cellconfig.c +++ b/src/auth/cellconfig.c @@ -1328,7 +1328,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) @@ -1447,8 +1447,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; @@ -1458,7 +1461,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