]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/replace: fix mem leak in error path
authorVictor Julien <victor@inliniac.net>
Tue, 23 Oct 2018 12:37:05 +0000 (14:37 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 1 Nov 2018 14:46:10 +0000 (15:46 +0100)
src/detect-content.c
src/detect-replace.c

index 1fa14e102faa1218d8e341d3812444f7ee750dcf..c70501fe1ff4a040234003b1d5471047e06e0326 100644 (file)
@@ -350,7 +350,7 @@ error:
 /**
  * \brief this function will SCFree memory associated with DetectContentData
  *
- * \param cd pointer to DetectCotentData
+ * \param cd pointer to DetectContentData
  */
 void DetectContentFree(void *ptr)
 {
index cfc4f1556a000dd417e1b00a3c30ce5c49cb3cbe..3f9410bfad5ab9547c1486505c7645a3361468d8 100644 (file)
@@ -76,18 +76,16 @@ int DetectReplaceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *replac
 {
     uint8_t *content = NULL;
     uint16_t len = 0;
-    SigMatch *pm = NULL;
-    DetectContentData *ud = NULL;
 
     if (s->init_data->negated) {
         SCLogError(SC_ERR_INVALID_VALUE, "Can't negate replacement string: %s",
                    replacestr);
-        goto error;
+        return -1;
     }
 
     int ret = DetectContentDataParse("replace", replacestr, &content, &len);
     if (ret == -1)
-        goto error;
+        return -1;
 
     switch (run_mode) {
         case RUNMODE_NFQ:
@@ -102,7 +100,7 @@ int DetectReplaceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *replac
     }
 
     /* add to the latest "content" keyword from pmatch */
-    pm = DetectGetLastSMByListId(s, DETECT_SM_LIST_PMATCH,
+    const SigMatch *pm = DetectGetLastSMByListId(s, DETECT_SM_LIST_PMATCH,
             DETECT_CONTENT, -1);
     if (pm == NULL) {
         SCLogError(SC_ERR_WITHIN_MISSING_CONTENT, "replace needs"
@@ -112,7 +110,7 @@ int DetectReplaceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *replac
     }
 
     /* we can remove this switch now with the unified structure */
-    ud = (DetectContentData *)pm->ctx;
+    DetectContentData *ud = (DetectContentData *)pm->ctx;
     if (ud == NULL) {
         SCLogError(SC_ERR_INVALID_ARGUMENT, "invalid argument");
         SCFree(content);
@@ -145,6 +143,8 @@ int DetectReplaceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *replac
     return 0;
 
 error:
+    SCFree(ud->replace);
+    ud->replace = NULL;
     SCFree(content);
     return -1;
 }