mirror of
https://github.com/systemd/systemd.git
synced 2025-02-28 05:57:33 +03:00
libsystemd-dhcp: Fix checksum computation for buffer with odd size
Fix off-by-one error and notice that summing may need more than one round for the result to be in the lower 16 bits.
This commit is contained in:
parent
77e8d29dd2
commit
0c6a3c888a
@ -382,10 +382,13 @@ static uint16_t client_checksum(void *buf, int len)
|
||||
|
||||
if (len & 0x01) {
|
||||
odd = buf;
|
||||
sum += odd[len];
|
||||
sum += odd[len - 1];
|
||||
}
|
||||
|
||||
return ~((sum & 0xffff) + (sum >> 16));
|
||||
while (sum >> 16)
|
||||
sum = (sum & 0xffff) + (sum >> 16);
|
||||
|
||||
return ~sum;
|
||||
}
|
||||
|
||||
static void client_append_ip_headers(DHCPPacket *packet, uint16_t len)
|
||||
|
@ -102,10 +102,13 @@ static uint16_t client_checksum(void *buf, int len)
|
||||
|
||||
if (len & 0x01) {
|
||||
odd = buf;
|
||||
sum += odd[len];
|
||||
sum += odd[len - 1];
|
||||
}
|
||||
|
||||
return ~((sum & 0xffff) + (sum >> 16));
|
||||
while (sum >> 16)
|
||||
sum = (sum & 0xffff) + (sum >> 16);
|
||||
|
||||
return ~sum;
|
||||
}
|
||||
|
||||
static void test_checksum(void)
|
||||
|
Loading…
x
Reference in New Issue
Block a user