Skip to content

Commit 9ae8424

Browse files
committed
networkd/sd-dhcp-server: Fix unaligned access in parse_request().
1 parent aa91232 commit 9ae8424

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/libsystemd-network/sd-dhcp-server.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "in-addr-util.h"
3030
#include "siphash24.h"
3131
#include "string-util.h"
32+
#include "unaligned.h"
3233

3334
#define DHCP_DEFAULT_LEASE_TIME_USEC USEC_PER_HOUR
3435
#define DHCP_MAX_LEASE_TIME_USEC (USEC_PER_HOUR*12)
@@ -604,17 +605,17 @@ static int parse_request(uint8_t code, uint8_t len, const void *option, void *us
604605
switch(code) {
605606
case SD_DHCP_OPTION_IP_ADDRESS_LEASE_TIME:
606607
if (len == 4)
607-
req->lifetime = be32toh(*(be32_t*)option);
608+
req->lifetime = unaligned_read_be32(option);
608609

609610
break;
610611
case SD_DHCP_OPTION_REQUESTED_IP_ADDRESS:
611612
if (len == 4)
612-
req->requested_ip = *(be32_t*)option;
613+
memcpy(&req->requested_ip, option, sizeof(be32_t));
613614

614615
break;
615616
case SD_DHCP_OPTION_SERVER_IDENTIFIER:
616617
if (len == 4)
617-
req->server_id = *(be32_t*)option;
618+
memcpy(&req->server_id, option, sizeof(be32_t));
618619

619620
break;
620621
case SD_DHCP_OPTION_CLIENT_IDENTIFIER:
@@ -633,8 +634,7 @@ static int parse_request(uint8_t code, uint8_t len, const void *option, void *us
633634
break;
634635
case SD_DHCP_OPTION_MAXIMUM_MESSAGE_SIZE:
635636
if (len == 2)
636-
req->max_optlen = be16toh(*(be16_t*)option) -
637-
- sizeof(DHCPPacket);
637+
req->max_optlen = unaligned_read_be16(option) - sizeof(DHCPPacket);
638638

639639
break;
640640
}

0 commit comments

Comments
 (0)