aboutsummaryrefslogtreecommitdiffstats
path: root/executor/common.h
diff options
context:
space:
mode:
authorAlexander Egorenkov <Alexander.Egorenkov@ibm.com>2020-06-02 09:25:28 +0200
committerAndrey Konovalov <andreyknvl@gmail.com>2020-06-19 20:49:11 +0200
commitc655ec77ca937f773ed5905a8972d00eb59581e8 (patch)
tree6a9a0e503a1c7eb08e1c83c526eab413db6e4ece /executor/common.h
parent81abc33188b4caf19873b9676ab1d8dc0e3511ca (diff)
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 <Alexander.Egorenkov@ibm.com>
Diffstat (limited to 'executor/common.h')
-rw-r--r--executor/common.h2
1 files changed, 1 insertions, 1 deletions
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);