diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2019-07-23 14:09:48 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2019-07-23 14:09:48 +0000 |
commit | 55575c2bbbeccb531faa6ade2b2c2e9c8bdeb6ea (patch) | |
tree | 6a403f804da9f807f4c8f066419291baef962b7c /sbin | |
parent | 64d4529c2d34f48dd6ba7d8bc3a04a1567ea01c3 (diff) |
Compilers may not be as magical as I hope, so revert to using memcpy()
when treating various sized integers as arrays of bytes.
Doubts expressed by kettenis@ on behalf of strict alignment
architectures.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/clparse.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 91c63922107..b1bdfa795a9 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.192 2019/07/22 17:20:06 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.193 2019/07/23 14:09:47 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -821,22 +821,25 @@ parse_option(FILE *cfile, int *code, struct option_data *options) if (parse_number(cfile, &number, INT32_MIN, INT32_MAX) == 0) return 0; - *(int32_t *)buf = htobe32((int32_t)number); + number = htobe64(number); len = sizeof(int32_t); + memcpy(buf, (char *)&number + (sizeof(number) - len), len); dp = buf; break; case 'L': /* Unsigned 32-bit integer. */ if (parse_number(cfile, &number, 0, UINT32_MAX) == 0) return 0; - *(uint32_t *)buf = htobe32((uint32_t)number); + number = htobe64(number); len = sizeof(uint32_t); + memcpy(buf, (char *)&number + (sizeof(number) - len), len); dp = buf; break; case 'S': /* Unsigned 16-bit integer. */ if (parse_number(cfile, &number, 0, UINT16_MAX) == 0) return 0; - *(uint16_t *)buf = htobe16((uint16_t)number); + number = htobe64(number); len = sizeof(uint16_t); + memcpy(buf, (char *)&number + (sizeof(number) - len), len); dp = buf; break; case 'B': /* Unsigned 8-bit integer. */ |