cellconfig: Do not use 'long' for dbserver IPs
authorAndrew Deason <adeason@sinenomine.net>
Tue, 10 Dec 2013 23:02:34 +0000 (17:02 -0600)
committerJeffrey Altman <jaltman@your-file-system.com>
Wed, 18 Dec 2013 22:43:58 +0000 (14:43 -0800)
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 <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

src/auth/cellconfig.c

index 2509ec7..9ff4082 100644 (file)
@@ -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++;