]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
defrag: unit test for tracker reuse (current fails)
authorJason Ish <ish@unx.ca>
Thu, 18 Jun 2015 20:18:49 +0000 (14:18 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 8 Oct 2015 08:35:44 +0000 (10:35 +0200)
Will be fixed in subsequent commits as tracker reuse is fixed.

src/defrag.c

index 7418b93c665f6107fec4ade30d9615621ad70b14..6f0260e3ef0bbe561e13dce7cdc18b5041921be9 100644 (file)
@@ -2328,6 +2328,70 @@ end:
     return ret;
 }
 
+static int DefragTrackerReuseTest(void)
+{
+    int ret = 0;
+    int id = 1;
+    Packet *p1 = NULL;
+    DefragTracker *tracker1 = NULL, *tracker2 = NULL;
+
+    DefragInit();
+
+    /* Build a packet, its not a fragment but shouldn't matter for
+     * this test. */
+    p1 = BuildTestPacket(id, 0, 0, 'A', 8);
+    if (p1 == NULL) {
+        goto end;
+    }
+
+    /* Get a tracker. It shouldn't look like its already in use. */
+    tracker1 = DefragGetTracker(NULL, NULL, p1);
+    if (tracker1 == NULL) {
+        goto end;
+    }
+    if (tracker1->seen_last) {
+        goto end;
+    }
+    if (tracker1->remove) {
+        goto end;
+    }
+    DefragTrackerRelease(tracker1);
+
+    /* Get a tracker again, it should be the same one. */
+    tracker2 = DefragGetTracker(NULL, NULL, p1);
+    if (tracker2 == NULL) {
+        goto end;
+    }
+    if (tracker2 != tracker1) {
+        goto end;
+    }
+    DefragTrackerRelease(tracker1);
+
+    /* Now mark the tracker for removal. It should not be returned
+     * when we get a tracker for a packet that may have the same
+     * attributes. */
+    tracker1->remove = 1;
+
+    tracker2 = DefragGetTracker(NULL, NULL, p1);
+    if (tracker2 == NULL) {
+        goto end;
+    }
+    if (tracker2 == tracker1) {
+        goto end;
+    }
+    if (tracker2->remove) {
+        goto end;
+    }
+
+    ret = 1;
+end:
+    if (p1 != NULL) {
+        SCFree(p1);
+    }
+    DefragDestroy();
+    return ret;
+}
+
 #endif /* UNITTESTS */
 
 void
@@ -2374,6 +2438,8 @@ DefragRegisterTests(void)
     UtRegisterTest("DefragVlanTest", DefragVlanTest, 1);
     UtRegisterTest("DefragVlanQinQTest", DefragVlanQinQTest, 1);
 
+    UtRegisterTest("DefragTrackerReuseTest", DefragTrackerReuseTest, 1);
+
     UtRegisterTest("DefragTimeoutTest",
         DefragTimeoutTest, 1);
 #endif /* UNITTESTS */