From c655ec77ca937f773ed5905a8972d00eb59581e8 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Tue, 2 Jun 2020 09:25:28 +0200 Subject: executor: fix endianness problem in internet checksum csum_inet_update does not handle odd number of bytes on big-endian architectures correctly. When calculating the checksum of odd number of bytes, the last byte must be interpreted as LSB on little-endian architectures and as MSB on big-endian ones in a 16-bit half-word. Futhermore, the checksum tests assume that the underlying architecture is always little-endian. When a little-endian machine stores a calculated checksum into memory, then the checksum's bytes are automatically swapped. But this is NOT true on a big-endian architecture. Signed-off-by: Alexander Egorenkov --- executor/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'executor/common.h') diff --git a/executor/common.h b/executor/common.h index cb409e763..757f439a5 100644 --- a/executor/common.h +++ b/executor/common.h @@ -372,7 +372,7 @@ static void csum_inet_update(struct csum_inet* csum, const uint8* data, size_t l csum->acc += *(uint16*)&data[i]; if (length & 1) - csum->acc += (uint16)data[length - 1]; + csum->acc += le16toh((uint16)data[length - 1]); while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); -- cgit mrf-deployment