diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-12-20 17:16:15 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2013-12-22 14:28:00 +0100 |
commit | 0c6a3c888abd720b5ab28162d1ba4eadffde5272 (patch) | |
tree | 9f3ecc81db7317b071caf74d6a9563abb5c88860 /src/libsystemd-dhcp/test-dhcp-client.c | |
parent | 77e8d29dd2ecfa7f11c31c8d96021d323ab3fe3a (diff) |
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.
Diffstat (limited to 'src/libsystemd-dhcp/test-dhcp-client.c')
-rw-r--r-- | src/libsystemd-dhcp/test-dhcp-client.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libsystemd-dhcp/test-dhcp-client.c b/src/libsystemd-dhcp/test-dhcp-client.c index d398510745..7400cc6837 100644 --- a/src/libsystemd-dhcp/test-dhcp-client.c +++ b/src/libsystemd-dhcp/test-dhcp-client.c @@ -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) |