]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: workaround scan-build warnings
authorVictor Julien <vjulien@oisf.net>
Wed, 3 Sep 2025 16:38:11 +0000 (18:38 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 8 Sep 2025 16:47:16 +0000 (18:47 +0200)
stream-tcp.c:1938:16: warning: Access to field 'next' results in a dereference of a null pointer (loaded from variable 'tail') [core.NullDereference]
 1938 |     tail->next = old_head;
      |     ~~~~       ^
1 warning generated.

stream-tcp.c:1982:5: warning: Potential leak of memory pointed to by 'q' [unix.Malloc]
 1982 |     ssn->queue_len++;
      |     ^~~
1 warning generated.

src/stream-tcp.c

index cc49cb3fcc76533fce2e644af09cdbcc2edef4c0..d366828fe6f5bf2d10496d76fde5e074b28115ac 100644 (file)
@@ -1951,7 +1951,8 @@ static int StreamTcp3whsStoreSyn(TcpSession *ssn, Packet *p)
     if (ssn->queue != NULL && StreamTcp3whsFindSyn(ssn, &search, &tail, false) != NULL)
         return 0;
 
-    if (ssn->queue_len == stream_config.max_syn_queued) {
+    if (ssn->queue_len > 0 && ssn->queue_len == stream_config.max_syn_queued) {
+        DEBUG_VALIDATE_BUG_ON(ssn->queue == NULL);
         SCLogDebug("%" PRIu64 ": ssn %p: =~ SYN queue limit reached, rotate", p->pcap_cnt, ssn);
         StreamTcpSetEvent(p, STREAM_3WHS_SYN_FLOOD);
 
@@ -1974,10 +1975,12 @@ static int StreamTcp3whsStoreSyn(TcpSession *ssn, Packet *p)
 
     *q = search;
     /* put in list */
-    if (tail)
+    if (tail) {
         tail->next = q;
-    if (ssn->queue == NULL)
+    } else {
+        DEBUG_VALIDATE_BUG_ON(ssn->queue != NULL);
         ssn->queue = q;
+    }
     ssn->queue_len++;
     SCLogDebug("%" PRIu64 ": ssn %p: =~ SYN with SEQ %u added (queue_len %u)", p->pcap_cnt, ssn,
             q->seq, ssn->queue_len);