Avoid access to unaligned data.

This commit is contained in:
joerg 2017-01-11 12:18:22 +00:00
parent 6ff696c6b4
commit 8ef27f1e3d
1 changed files with 8 additions and 15 deletions

View File

@ -22,7 +22,7 @@ SOFTWARE.
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: readfile.c,v 1.19 2011/10/07 10:06:39 joerg Exp $"); __RCSID("$NetBSD: readfile.c,v 1.20 2017/01/11 12:18:22 joerg Exp $");
#endif #endif
@ -1582,23 +1582,21 @@ makelower(char *s)
PRIVATE struct in_addr_list * PRIVATE struct in_addr_list *
get_addresses(char **src) get_addresses(char **src)
{ {
struct in_addr tmpaddrlist[MAXINADDRS]; __aligned(4) struct in_addr tmpaddrlist[MAXINADDRS];
struct in_addr *address1, *address2;
struct in_addr_list *result; struct in_addr_list *result;
unsigned addrcount, totalsize; unsigned addrcount, totalsize, address;
address1 = tmpaddrlist; for (address = 0, addrcount = 0; addrcount < MAXINADDRS; addrcount++) {
for (addrcount = 0; addrcount < MAXINADDRS; addrcount++) {
while (isspace((unsigned char)**src) || (**src == ',')) { while (isspace((unsigned char)**src) || (**src == ',')) {
(*src)++; (*src)++;
} }
if (!**src) { /* Quit if nothing more */ if (!**src) { /* Quit if nothing more */
break; break;
} }
if (prs_inetaddr(src, &(address1->s_addr)) < 0) { if (prs_inetaddr(src, &tmpaddrlist[address].s_addr) < 0) {
break; break;
} }
address1++; /* Point to next address slot */ address++; /* Point to next address slot */
} }
if (addrcount < 1) { if (addrcount < 1) {
result = NULL; result = NULL;
@ -1608,13 +1606,8 @@ get_addresses(char **src)
result = (struct in_addr_list *) smalloc(totalsize); result = (struct in_addr_list *) smalloc(totalsize);
result->linkcount = 1; result->linkcount = 1;
result->addrcount = addrcount; result->addrcount = addrcount;
address1 = tmpaddrlist; for (address = 0; address < addrcount; ++address)
address2 = result->addr; result->addr[address] = tmpaddrlist[address];
for (; addrcount > 0; addrcount--) {
address2->s_addr = address1->s_addr;
address1++;
address2++;
}
} }
return result; return result;
} }