diff options
| author | Alexander Egorenkov <Alexander.Egorenkov@ibm.com> | 2020-06-02 09:25:28 +0200 |
|---|---|---|
| committer | Andrey Konovalov <andreyknvl@gmail.com> | 2020-06-19 20:49:11 +0200 |
| commit | c655ec77ca937f773ed5905a8972d00eb59581e8 (patch) | |
| tree | 6a9a0e503a1c7eb08e1c83c526eab413db6e4ece /pkg/csource/generated.go | |
| parent | 81abc33188b4caf19873b9676ab1d8dc0e3511ca (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 'pkg/csource/generated.go')
| -rw-r--r-- | pkg/csource/generated.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 33362b51b..6c1f343be 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -354,7 +354,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); |
