]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
detect: allows <> syntax for uint ranges master
authorPhilippe Antoine <contact@catenacyber.fr>
Thu, 18 Feb 2021 14:43:03 +0000 (15:43 +0100)
committerVictor Julien <vjulien@oisf.net>
Wed, 24 Nov 2021 07:15:16 +0000 (08:15 +0100)
src/detect-engine-uint.c

index 2a21c42d9d6699d4efe89b8791b57c345d0ba2a8..d44c6bfaf2e11766f8b955b9a075d10f06704ae1 100644 (file)
@@ -165,32 +165,39 @@ DetectU32Data *DetectU32Parse (const char *u32str)
         switch(arg2[0]) {
             case '<':
             case '>':
-                if (strlen(arg3) == 0)
-                    return NULL;
+                if (strlen(arg2) == 1) {
+                    if (strlen(arg3) == 0)
+                        return NULL;
 
-                if (ByteExtractStringUint32(&u32da.arg1, 10, strlen(arg3), arg3) < 0) {
-                    SCLogError(SC_ERR_BYTE_EXTRACT_FAILED, "ByteExtractStringUint32 failed");
-                    return NULL;
-                }
+                    if (ByteExtractStringUint32(&u32da.arg1, 10, strlen(arg3), arg3) < 0) {
+                        SCLogError(SC_ERR_BYTE_EXTRACT_FAILED, "ByteExtractStringUint32 failed");
+                        return NULL;
+                    }
 
-                SCLogDebug("u32 is %"PRIu32"",u32da.arg1);
-                if (strlen(arg1) > 0)
-                    return NULL;
+                    SCLogDebug("u32 is %" PRIu32 "", u32da.arg1);
+                    if (strlen(arg1) > 0)
+                        return NULL;
 
-                if (arg2[0] == '<') {
-                    if (arg2[1] == '=') {
-                        u32da.mode = DETECT_UINT_LTE;
-                    } else {
+                    if (arg2[0] == '<') {
                         u32da.mode = DETECT_UINT_LT;
+                    } else { // arg2[0] == '>'
+                        u32da.mode = DETECT_UINT_GT;
                     }
-                } else { // arg2[0] == '>'
-                    if (arg2[1] == '=') {
+                    break;
+                } else if (strlen(arg2) == 2) {
+                    if (arg2[0] == '<' && arg2[1] == '=') {
+                        u32da.mode = DETECT_UINT_LTE;
+                        break;
+                    } else if (arg2[0] == '>' || arg2[1] == '=') {
                         u32da.mode = DETECT_UINT_GTE;
-                    } else {
-                        u32da.mode = DETECT_UINT_GT;
+                        break;
+                    } else if (arg2[0] != '<' || arg2[1] != '>') {
+                        return NULL;
                     }
+                } else {
+                    return NULL;
                 }
-                break;
+                // fall through
             case '-':
                 if (strlen(arg1)== 0)
                     return NULL;
@@ -413,29 +420,36 @@ DetectU8Data *DetectU8Parse (const char *u8str)
         switch(arg2[0]) {
             case '<':
             case '>':
-                if (StringParseUint8(&u8da.arg1, 10, strlen(arg3), arg3) < 0) {
-                    SCLogError(SC_ERR_BYTE_EXTRACT_FAILED, "ByteExtractStringUint8 failed");
-                    return NULL;
-                }
+                if (strlen(arg2) == 1) {
+                    if (StringParseUint8(&u8da.arg1, 10, strlen(arg3), arg3) < 0) {
+                        SCLogError(SC_ERR_BYTE_EXTRACT_FAILED, "ByteExtractStringUint8 failed");
+                        return NULL;
+                    }
 
-                SCLogDebug("u8 is %"PRIu8"",u8da.arg1);
-                if (strlen(arg1) > 0)
-                    return NULL;
+                    SCLogDebug("u8 is %" PRIu8 "", u8da.arg1);
+                    if (strlen(arg1) > 0)
+                        return NULL;
 
-                if (arg2[0] == '<') {
-                    if (arg2[1] == '=') {
-                        u8da.mode = DETECT_UINT_LTE;
-                    } else {
+                    if (arg2[0] == '<') {
                         u8da.mode = DETECT_UINT_LT;
+                    } else { // arg2[0] == '>'
+                        u8da.mode = DETECT_UINT_GT;
                     }
-                } else { // arg2[0] == '>'
-                    if (arg2[1] == '=') {
+                    break;
+                } else if (strlen(arg2) == 2) {
+                    if (arg2[0] == '<' && arg2[1] == '=') {
+                        u8da.mode = DETECT_UINT_LTE;
+                        break;
+                    } else if (arg2[0] == '>' || arg2[1] == '=') {
                         u8da.mode = DETECT_UINT_GTE;
-                    } else {
-                        u8da.mode = DETECT_UINT_GT;
+                        break;
+                    } else if (arg2[0] != '<' || arg2[1] != '>') {
+                        return NULL;
                     }
+                } else {
+                    return NULL;
                 }
-                break;
+                // fall through
             case '-':
                 u8da.mode = DETECT_UINT_RA;
                 if (StringParseUint8(&u8da.arg1, 10, strlen(arg1), arg1) < 0) {