]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1785 in SNORT/snort3 from ~MIALTIZE/snort3:cksum_alignment to...
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Tue, 8 Oct 2019 15:23:53 +0000 (11:23 -0400)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Tue, 8 Oct 2019 15:23:53 +0000 (11:23 -0400)
Squashed commit of the following:

commit e4482a20e1e3c5720bd83d999baba9e6baffe5da
Author: Michael Altizer <mialtize@cisco.com>
Date:   Mon Oct 7 15:13:32 2019 -0400

    codecs: Fix checksumming a single byte of unaligned data

src/codecs/ip/checksum.h

index d8a62d1428b1fe74fb0b30bdbf2020a1429e39da..53e303d5ce62e5cb3fa1c01fd04f2d19db1ffaca 100644 (file)
@@ -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);