]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
fix for bug #557.
authorAnoop Saldanha <anoopsaldanha@gmail.com>
Wed, 26 Sep 2012 17:17:53 +0000 (22:47 +0530)
committerVictor Julien <victor@inliniac.net>
Tue, 2 Oct 2012 08:20:09 +0000 (10:20 +0200)
Reset hhd buffers list len if we exit before allocating the buffer.

src/detect-engine-hhd.c

index 306b3ca40633f8027d61c644df872fd081c65612..9a8649d1ac7f64895fae9c934587dc35b85d836f 100644 (file)
@@ -100,18 +100,21 @@ static void DetectEngineBufferHttpHeaders(DetectEngineThreadCtx *det_ctx, Flow *
     /* assign space to hold buffers.  Each per transaction */
     det_ctx->hhd_buffers = SCMalloc(det_ctx->hhd_buffers_list_len * sizeof(uint8_t *));
     if (det_ctx->hhd_buffers == NULL) {
+        det_ctx->hhd_buffers_list_len = 0;
         goto end;
     }
     memset(det_ctx->hhd_buffers, 0, det_ctx->hhd_buffers_list_len * sizeof(uint8_t *));
 
     det_ctx->hhd_buffers_len = SCMalloc(det_ctx->hhd_buffers_list_len * sizeof(uint32_t));
     if (det_ctx->hhd_buffers_len == NULL) {
+        det_ctx->hhd_buffers_list_len = 0;
         goto end;
     }
     memset(det_ctx->hhd_buffers_len, 0, det_ctx->hhd_buffers_list_len * sizeof(uint32_t));
 
     idx = AppLayerTransactionGetInspectId(f);
     if (idx == -1) {
+        det_ctx->hhd_buffers_list_len = 0;
         goto end;
     }
 
@@ -153,6 +156,7 @@ static void DetectEngineBufferHttpHeaders(DetectEngineThreadCtx *det_ctx, Flow *
             /* the extra 4 bytes if for ": " and "\r\n" */
             headers_buffer = SCRealloc(headers_buffer, headers_buffer_len + size1 + size2 + 4);
             if (headers_buffer == NULL) {
+                headers_buffer_len = 0;
                 continue;
             }
 
@@ -279,16 +283,16 @@ void DetectEngineCleanHHDBuffers(DetectEngineThreadCtx *det_ctx)
             if (det_ctx->hhd_buffers[i] != NULL)
                 SCFree(det_ctx->hhd_buffers[i]);
         }
-        if (det_ctx->hhd_buffers != NULL) {
-            SCFree(det_ctx->hhd_buffers);
-            det_ctx->hhd_buffers = NULL;
-        }
-        if (det_ctx->hhd_buffers_len != NULL) {
-            SCFree(det_ctx->hhd_buffers_len);
-            det_ctx->hhd_buffers_len = NULL;
-        }
-        det_ctx->hhd_buffers_list_len = 0;
     }
+    if (det_ctx->hhd_buffers != NULL) {
+        SCFree(det_ctx->hhd_buffers);
+        det_ctx->hhd_buffers = NULL;
+    }
+    if (det_ctx->hhd_buffers_len != NULL) {
+        SCFree(det_ctx->hhd_buffers_len);
+        det_ctx->hhd_buffers_len = NULL;
+    }
+    det_ctx->hhd_buffers_list_len = 0;
 
     return;
 }