]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
classification: cleanups
authorVictor Julien <victor@inliniac.net>
Wed, 8 Apr 2015 13:15:29 +0000 (15:15 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 24 Apr 2015 10:37:47 +0000 (12:37 +0200)
Reduce hash table size as regular classification files are usually
below 100 in size. It's not performance critical anyway.

Convert pcre_get_substring calls to pcre_copy_substring.

src/util-classification-config.c

index db79b7a21340a3338becc4d00236d8aa2256955c..51d18fdb2e770f6cddb0572f63bc345990be21c3 100644 (file)
@@ -81,7 +81,7 @@ int SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx)
     int opts = 0;
 
     /* init the hash table to be used by the classification config Classtypes */
-    de_ctx->class_conf_ht = HashTableInit(4096, SCClassConfClasstypeHashFunc,
+    de_ctx->class_conf_ht = HashTableInit(128, SCClassConfClasstypeHashFunc,
                                           SCClassConfClasstypeHashCompareFunc,
                                           SCClassConfClasstypeHashFree);
     if (de_ctx->class_conf_ht == NULL) {
@@ -235,9 +235,9 @@ static char *SCClassConfStringToLowercase(const char *str)
  */
 int SCClassConfAddClasstype(char *rawstr, uint8_t index, DetectEngineCtx *de_ctx)
 {
-    const char *ct_name = NULL;
-    const char *ct_desc = NULL;
-    const char *ct_priority_str = NULL;
+    char ct_name[64];
+    char ct_desc[512];
+    char ct_priority_str[16];
     int ct_priority = 0;
     uint8_t ct_id = index;
 
@@ -256,23 +256,23 @@ int SCClassConfAddClasstype(char *rawstr, uint8_t index, DetectEngineCtx *de_ctx
     }
 
     /* retrieve the classtype name */
-    ret = pcre_get_substring((char *)rawstr, ov, 30, 1, &ct_name);
+    ret = pcre_copy_substring((char *)rawstr, ov, 30, 1, ct_name, sizeof(ct_name));
     if (ret < 0) {
-        SCLogInfo("pcre_get_substring() failed");
+        SCLogInfo("pcre_copy_substring() failed");
         goto error;
     }
 
     /* retrieve the classtype description */
-    ret = pcre_get_substring((char *)rawstr, ov, 30, 2, &ct_desc);
+    ret = pcre_copy_substring((char *)rawstr, ov, 30, 2, ct_desc, sizeof(ct_desc));
     if (ret < 0) {
-        SCLogInfo("pcre_get_substring() failed");
+        SCLogInfo("pcre_copy_substring() failed");
         goto error;
     }
 
     /* retrieve the classtype priority */
-    ret = pcre_get_substring((char *)rawstr, ov, 30, 3, &ct_priority_str);
+    ret = pcre_copy_substring((char *)rawstr, ov, 30, 3, ct_priority_str, sizeof(ct_priority_str));
     if (ret < 0) {
-        SCLogInfo("pcre_get_substring() failed");
+        SCLogInfo("pcre_copy_substring() failed");
         goto error;
     }
     if (ct_priority_str == NULL) {
@@ -299,16 +299,9 @@ int SCClassConfAddClasstype(char *rawstr, uint8_t index, DetectEngineCtx *de_ctx
         SCFree(ct_new);
     }
 
-    if (ct_name) SCFree((char *)ct_name);
-    if (ct_desc) SCFree((char *)ct_desc);
-    if (ct_priority_str) SCFree((char *)ct_priority_str);
     return 0;
 
  error:
-    if (ct_name) SCFree((char *)ct_name);
-    if (ct_desc) SCFree((char *)ct_desc);
-    if (ct_priority_str) SCFree((char *)ct_priority_str);
-
     return -1;
 }