From: Michael Altizer (mialtize) Date: Tue, 8 Oct 2019 15:23:53 +0000 (-0400) Subject: Merge pull request #1785 in SNORT/snort3 from ~MIALTIZE/snort3:cksum_alignment to... X-Git-Tag: 3.0.0-262~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=900c723709891c928005357841dccda75954889c;p=thirdparty%2Fsnort3.git Merge pull request #1785 in SNORT/snort3 from ~MIALTIZE/snort3:cksum_alignment to master Squashed commit of the following: commit e4482a20e1e3c5720bd83d999baba9e6baffe5da Author: Michael Altizer Date: Mon Oct 7 15:13:32 2019 -0400 codecs: Fix checksumming a single byte of unaligned data --- diff --git a/src/codecs/ip/checksum.h b/src/codecs/ip/checksum.h index d8a62d142..53e303d5c 100644 --- a/src/codecs/ip/checksum.h +++ b/src/codecs/ip/checksum.h @@ -100,9 +100,6 @@ inline uint16_t cksum_add(const uint16_t* buf, std::size_t len, uint32_t cksum) cksum += *sp++; len -= 2; } - // if len was odd, sum in the last byte... - if ( len ) - cksum += (uint16_t) *(const uint8_t *)sp; } else if ( len > 1 ) { @@ -168,11 +165,12 @@ inline uint16_t cksum_add(const uint16_t* buf, std::size_t len, uint32_t cksum) cksum += sp[15]; sp += 16; } - // if len is odd, sum in the last byte... - if ( len & 0x01) - cksum += (uint16_t) *(const uint8_t *)sp; } + // if len is odd, sum in the last byte... + if ( len & 0x01 ) + cksum += *((const uint8_t*) sp); + cksum = (cksum >> 16) + (cksum & 0x0000ffff); cksum += (cksum >> 16);