]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Another batch of minor fixed for issues found by Coverity.
authorVictor Julien <victor@inliniac.net>
Thu, 1 Mar 2012 09:46:34 +0000 (10:46 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 1 Mar 2012 09:46:34 +0000 (10:46 +0100)
src/flow-timeout.c
src/log-pcap.c
src/stream-tcp-sack.c
src/stream-tcp.c
src/tm-threads.c
src/util-runmodes.c

index 9da2e85bfcb5581fe3c49354e52ea92607a5422e..74a84aa67f2572f571331116658b96f0f5482972 100644 (file)
@@ -377,7 +377,6 @@ int FlowForceReassemblyForFlowV2(Flow *f)
         } else if (server_ok == 2) {
             p1 = FlowForceReassemblyPseudoPacketGet(1, f, ssn, 1);
             if (p1 == NULL) {
-                TmqhOutputPacketpool(NULL, p1);
                 return 1;
             }
         } else {
index 0ec9bb93cce96786408dcadcc8cd61a680ad0fe7..32d5664660c90df22fc681daaaf9c6fe46f403d4 100644 (file)
@@ -423,16 +423,18 @@ OutputCtx *PcapLogInitCtx(ConfNode *conf)
 {
     SCMutexLock(&plog_lock);
     const char *filename = NULL;
+
     if (conf != NULL) { /* To faciliate unit tests. */
         filename = ConfNodeLookupChildValue(conf, "filename");
     }
+
     if (filename == NULL)
         filename = DEFAULT_LOG_FILENAME;
 
     if ((pl->prefix = SCStrdup(filename)) == NULL) {
-
-            SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for directory name");
-            return NULL;
+        SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for directory name");
+        SCMutexUnlock(&plog_lock);
+        return NULL;
     }
 
     pl->size_limit = DEFAULT_LIMIT;
index caa628fd6788b82445ee10d663ce7a69f308df5a..2ec593af0c1eca112756bb2a81ec8402382de7b5 100644 (file)
@@ -262,37 +262,21 @@ void StreamTcpSackPruneList(TcpStream *stream) {
     SCEnter();
 
     StreamTcpSackRecord *rec = stream->sack_head;
-    StreamTcpSackRecord *prev = NULL;
 
     while (rec != NULL) {
         if (SEQ_LT(rec->re, stream->last_ack)) {
             SCLogDebug("removing le %u re %u", rec->le, rec->re);
 
-            // fully before last_ack, remove
-            if (prev != NULL) {
-                if (rec == stream->sack_tail) {
-                    stream->sack_tail = prev;
-                    prev->next = NULL;
-                    SCFree(rec);
-                    break;
-                } else {
-                    prev->next = rec->next;
-                    SCFree(rec);
-                    rec = prev->next;
-                    continue;
-                }
+            if (rec->next != NULL) {
+                stream->sack_head = rec->next;
+                SCFree(rec);
+                rec = stream->sack_head;
+                continue;
             } else {
-                if (rec->next != NULL) {
-                    stream->sack_head = rec->next;
-                    SCFree(rec);
-                    rec = stream->sack_head;
-                    continue;
-                } else {
-                    stream->sack_head = NULL;
-                    stream->sack_tail = NULL;
-                    SCFree(rec);
-                    break;
-                }
+                stream->sack_head = NULL;
+                stream->sack_tail = NULL;
+                SCFree(rec);
+                break;
             }
         } else if (SEQ_LT(rec->le, stream->last_ack)) {
             SCLogDebug("adjusting record to le %u re %u", rec->le, rec->re);
index 2062a972b59620c974f0cb61e951b80a8cccb3f4..134ad94773f96f3b5b8079b91219d2068bafd6cd 100644 (file)
@@ -667,6 +667,9 @@ void StreamTcpSetOSPolicy(TcpStream *stream, Packet *p)
  *  \param  tv      Thread Variable containig  input/output queue, cpu affinity
  *  \param  p       Packet which has to be handled in this TCP state.
  *  \param  stt     Strean Thread module registered to handle the stream handling
+ *
+ *  \retval 0 ok
+ *  \retval -1 error
  */
 static int StreamTcpPacketStateNone(ThreadVars *tv, Packet *p,
                         StreamTcpThread *stt, TcpSession *ssn, PacketQueue *pq)
@@ -924,6 +927,7 @@ static int StreamTcpPacketStateNone(ThreadVars *tv, Packet *p,
             SCLogDebug("default case");
             break;
     }
+
     return 0;
 }
 
@@ -3749,39 +3753,40 @@ static int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
      * inject a fake packet into the system, forcing reassembly of the
      * opposing direction.
      * There should be only one, but to be sure we do a while loop. */
-    while (stt->pseudo_queue.len > 0) {
-        SCLogDebug("processing pseudo packet / stream end");
-        Packet *np = PacketDequeue(&stt->pseudo_queue);
-        if (np != NULL) {
-            /* process the opposing direction of the original packet */
-            if (PKT_IS_TOSERVER(np)) {
-                SCLogDebug("pseudo packet is to server");
-                StreamTcpReassembleHandleSegment(tv, stt->ra_ctx, ssn,
-                        &ssn->client, np, NULL);
-            } else {
-                SCLogDebug("pseudo packet is to client");
-                StreamTcpReassembleHandleSegment(tv, stt->ra_ctx, ssn,
-                        &ssn->server, np, NULL);
+    if (ssn != NULL) {
+        while (stt->pseudo_queue.len > 0) {
+            SCLogDebug("processing pseudo packet / stream end");
+            Packet *np = PacketDequeue(&stt->pseudo_queue);
+            if (np != NULL) {
+                /* process the opposing direction of the original packet */
+                if (PKT_IS_TOSERVER(np)) {
+                    SCLogDebug("pseudo packet is to server");
+                    StreamTcpReassembleHandleSegment(tv, stt->ra_ctx, ssn,
+                            &ssn->client, np, NULL);
+                } else {
+                    SCLogDebug("pseudo packet is to client");
+                    StreamTcpReassembleHandleSegment(tv, stt->ra_ctx, ssn,
+                            &ssn->server, np, NULL);
+                }
+
+                /* enqueue this packet so we inspect it in detect etc */
+                PacketEnqueue(pq, np);
             }
+            SCLogDebug("processing pseudo packet / stream end done");
+        }
 
-            /* enqueue this packet so we inspect it in detect etc */
-            PacketEnqueue(pq, np);
+        /* Process stream smsgs we may have in queue */
+        if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx) < 0) {
+            goto error;
         }
-        SCLogDebug("processing pseudo packet / stream end done");
-    }
 
-    /* Process stream smsgs we may have in queue */
-    if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx) < 0) {
-        goto error;
-    }
+        /* recalc the csum on the packet if it was modified */
+        if (p->flags & PKT_STREAM_MODIFIED) {
+            ReCalculateChecksum(p);
+        }
 
-    /* recalc the csum on the packet if it was modified */
-    if (p->flags & PKT_STREAM_MODIFIED) {
-        ReCalculateChecksum(p);
-    }
+        /* check for conditions that may make us not want to log this packet */
 
-    /* check for conditions that may make us not want to log this packet */
-    if (ssn != NULL) {
         /* streams that hit depth */
         if ((ssn->client.flags & STREAMTCP_STREAM_FLAG_DEPTH_REACHED ||
              ssn->server.flags & STREAMTCP_STREAM_FLAG_DEPTH_REACHED))
index bf1bb6912d723420af4700cac3e423f1bba97017..efc565973a4fef41f1374782c58ad47ddd3f4757 100644 (file)
@@ -105,7 +105,6 @@ void *TmThreadsSlot1NoIn(void *td)
 {
     ThreadVars *tv = (ThreadVars *)td;
     TmSlot *s = (TmSlot *)tv->tm_slots;
-    Packet *p = NULL;
     char run = 1;
     TmEcode r = TM_ECODE_OK;
 
@@ -136,7 +135,7 @@ void *TmThreadsSlot1NoIn(void *td)
         TmThreadTestThreadUnPaused(tv);
 
         PACKET_PROFILING_TMM_START(p, s->tm_id);
-        r = s->SlotFunc(tv, p, s->slot_data, &s->slot_pre_pq, &s->slot_post_pq);
+        r = s->SlotFunc(tv, NULL, s->slot_data, &s->slot_pre_pq, &s->slot_post_pq);
         PACKET_PROFILING_TMM_END(p, s->tm_id);
 
         /* handle error */
@@ -147,8 +146,6 @@ void *TmThreadsSlot1NoIn(void *td)
             TmqhReleasePacketsToPacketPool(&s->slot_post_pq);
             SCMutexUnlock(&s->slot_post_pq.mutex_q);
 
-            if (p != NULL)
-                TmqhOutputPacketpool(tv, p);
             TmThreadsSetFlag(tv, THV_FAILED);
             break;
         }
@@ -160,10 +157,6 @@ void *TmThreadsSlot1NoIn(void *td)
                 tv->tmqh_out(tv, extra_p);
         }
 
-        tv->tmqh_out(tv, p);
-        if (p != NULL)
-            tv->tmqh_out(tv, p);
-
         /* handle post queue */
         if (s->slot_post_pq.top != NULL) {
             SCMutexLock(&s->slot_post_pq.mutex_q);
@@ -557,7 +550,7 @@ void *TmThreadsSlotPktAcqLoop(void *td) {
         SCLogError(SC_ERR_FATAL, "TmSlot or ThreadVars badly setup: s=%p,"
                                  " PktAcqLoop=%p, tmqh_in=%p,"
                                  " tmqh_out=%p",
-                   s, s->PktAcqLoop, tv->tmqh_in, tv->tmqh_out);
+                   s, s ? s->PktAcqLoop : NULL, tv->tmqh_in, tv->tmqh_out);
         EngineKill();
 
         TmThreadsSetFlag(tv, THV_CLOSED);
index c5fbc2e33e1a6da07db9b8581be4f4b54243a873..cdbc3216e2e12d7219a92e9aad5ad73b365d614f 100644 (file)
@@ -792,10 +792,6 @@ int RunModeSetIPSAuto(DetectEngineCtx *de_ctx,
         }
         memset(tname, 0, sizeof(tname));
         snprintf(tname, sizeof(tname), "Recv-Q%s", cur_queue);
-        if (tname == NULL) {
-            printf("ERROR: Unable to build thread name\n");
-            exit(EXIT_FAILURE);
-        }
 
         char *thread_name = SCStrdup(tname);
         ThreadVars *tv_receivenfq =
@@ -1003,10 +999,6 @@ int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx,
         }
         memset(tname, 0, sizeof(tname));
         snprintf(tname, sizeof(tname), "Recv-Q%s", cur_queue);
-        if (tname == NULL) {
-            printf("ERROR: Unable to build thread name\n");
-            exit(EXIT_FAILURE);
-        }
 
         char *thread_name = SCStrdup(tname);