]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
keyword-filesize: add units
authorAndreas Herz <andi@geekosphere.org>
Fri, 4 Aug 2017 23:06:22 +0000 (01:06 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 11 Dec 2017 08:21:32 +0000 (09:21 +0100)
doc/userguide/rules/file-keywords.rst
src/detect-filesize.c

index 44c5b667a9ecc788e95ccc0038a0bf562a1f5cbe..9a173bd8e5165620a9687c314e357e62b9a5e9b6 100644 (file)
@@ -124,12 +124,14 @@ Syntax::
 
   filesize:<value>;
 
+Possible units are KB, MB and GB, without any unit the default is bytes.
+
 Examples::
 
   filesize:100; # exactly 100 bytes
   filesize:100<>200; # greater than 100 and smaller than 200
-  filesize:>100; # greater than 100
-  filesize:<100; # smaller than 100
+  filesize:>100MB; # greater than 100 megabytes
+  filesize:<100MB; # smaller than 100 megabytes
 
 **Note**: For files that are not completely tracked because of packet
 loss or stream.depth being reached on the "greater than" is
index 48c1a0e2eef1482a55d6895e017f6e0f44026345..1e18178ec49f747b00f8174e45b6bbe8ed127047 100644 (file)
@@ -28,6 +28,7 @@
 #include "app-layer-htp.h"
 #include "util-unittest.h"
 #include "util-unittest-helper.h"
+#include "util-misc.h"
 
 #include "detect.h"
 #include "detect-parse.h"
@@ -43,7 +44,7 @@
 /**
  * \brief Regex for parsing our filesize
  */
-#define PARSE_REGEX  "^(?:\\s*)(<|>)?(?:\\s*)([0-9]{1,23})(?:\\s*)(?:(<>)(?:\\s*)([0-9]{1,23}))?\\s*$"
+#define PARSE_REGEX  "^(?:\\s*)(<|>)?(?:\\s*)([0-9]{1,23}[a-zA-Z]{0,2})(?:\\s*)(?:(<>)(?:\\s*)([0-9]{1,23}[a-zA-Z]{0,2}))?\\s*$"
 
 static pcre *parse_regex;
 static pcre_extra *parse_regex_study;
@@ -214,8 +215,8 @@ static DetectFilesizeData *DetectFilesizeParse (const char *str)
     }
 
     /** set the first value */
-    if (ByteExtractStringUint64(&fsd->size1,10,strlen(arg2),arg2) <= 0){
-        SCLogError(SC_ERR_INVALID_ARGUMENT,"Invalid size :\"%s\"",arg2);
+    if (ParseSizeStringU64(arg2, &fsd->size1) < 0) {
+        SCLogError(SC_ERR_SIZE_PARSE, "Error parsing filesize value - %s", arg2);
         goto error;
     }
 
@@ -227,9 +228,8 @@ static DetectFilesizeData *DetectFilesizeParse (const char *str)
             goto error;
         }
 
-        if(ByteExtractStringUint64(&fsd->size2,10,strlen(arg4),arg4) <= 0)
-        {
-            SCLogError(SC_ERR_INVALID_ARGUMENT,"Invalid size :\"%s\"",arg4);
+        if (ParseSizeStringU64(arg4, &fsd->size2) < 0) {
+            SCLogError(SC_ERR_SIZE_PARSE, "Error parsing filesize value - %s", arg4);
             goto error;
         }