]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
memcmp: compare the first byte as well
authorVictor Julien <victor@inliniac.net>
Tue, 16 Dec 2014 18:12:20 +0000 (19:12 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 15 Jan 2015 10:35:07 +0000 (11:35 +0100)
MemcmpLowercase would not compare the first byte of both input buffers
leading to two non-identical buffers to be considered the same.

Affects SSE_4_1 and SSE_4_2 implementations of SCMemcmpLowercase, as well
as the non-SIMD implementation. SSE_3 and Tile version are not affected.

src/util-memcmp.h

index 4a5be891ee17de2668b44ba56418f2d6f1321fc0..875652b1092140118054448ebeaf38311f151c43 100644 (file)
@@ -41,12 +41,12 @@ void MemcmpRegisterTests(void);
 static inline int
 MemcmpLowercase(const void *s1, const void *s2, size_t n)
 {
-    size_t i;
+    ssize_t i;
 
     /* check backwards because we already tested the first
      * 2 to 4 chars. This way we are more likely to detect
      * a miss and thus speed up a little... */
-    for (i = n - 1; i; i--) {
+    for (i = n - 1; i >= 0; i--) {
         if (((uint8_t *)s1)[i] != u8_tolower(*(((uint8_t *)s2)+i)))
             return 1;
     }