From: Victor Julien Date: Thu, 1 Mar 2012 09:46:34 +0000 (+0100) Subject: Another batch of minor fixed for issues found by Coverity. X-Git-Tag: suricata-1.3beta1~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=372ab9c43369470e8bf6cd2d52c274d02a7fd203;p=thirdparty%2Fsuricata.git Another batch of minor fixed for issues found by Coverity. --- diff --git a/src/flow-timeout.c b/src/flow-timeout.c index 9da2e85bfc..74a84aa67f 100644 --- a/src/flow-timeout.c +++ b/src/flow-timeout.c @@ -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 { diff --git a/src/log-pcap.c b/src/log-pcap.c index 0ec9bb93cc..32d5664660 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -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; diff --git a/src/stream-tcp-sack.c b/src/stream-tcp-sack.c index caa628fd67..2ec593af0c 100644 --- a/src/stream-tcp-sack.c +++ b/src/stream-tcp-sack.c @@ -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); diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 2062a972b5..134ad94773 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -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)) diff --git a/src/tm-threads.c b/src/tm-threads.c index bf1bb6912d..efc565973a 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -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); diff --git a/src/util-runmodes.c b/src/util-runmodes.c index c5fbc2e33e..cdbc3216e2 100644 --- a/src/util-runmodes.c +++ b/src/util-runmodes.c @@ -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);