Another batch of minor fixed for issues found by Coverity.

remotes/origin/master
Victor Julien 14 years ago
parent 11bdf4838f
commit 372ab9c433

@ -377,7 +377,6 @@ int FlowForceReassemblyForFlowV2(Flow *f)
} else if (server_ok == 2) { } else if (server_ok == 2) {
p1 = FlowForceReassemblyPseudoPacketGet(1, f, ssn, 1); p1 = FlowForceReassemblyPseudoPacketGet(1, f, ssn, 1);
if (p1 == NULL) { if (p1 == NULL) {
TmqhOutputPacketpool(NULL, p1);
return 1; return 1;
} }
} else { } else {

@ -423,16 +423,18 @@ OutputCtx *PcapLogInitCtx(ConfNode *conf)
{ {
SCMutexLock(&plog_lock); SCMutexLock(&plog_lock);
const char *filename = NULL; const char *filename = NULL;
if (conf != NULL) { /* To faciliate unit tests. */ if (conf != NULL) { /* To faciliate unit tests. */
filename = ConfNodeLookupChildValue(conf, "filename"); filename = ConfNodeLookupChildValue(conf, "filename");
} }
if (filename == NULL) if (filename == NULL)
filename = DEFAULT_LOG_FILENAME; filename = DEFAULT_LOG_FILENAME;
if ((pl->prefix = SCStrdup(filename)) == NULL) { if ((pl->prefix = SCStrdup(filename)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for directory name");
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for directory name"); SCMutexUnlock(&plog_lock);
return NULL; return NULL;
} }
pl->size_limit = DEFAULT_LIMIT; pl->size_limit = DEFAULT_LIMIT;

@ -262,37 +262,21 @@ void StreamTcpSackPruneList(TcpStream *stream) {
SCEnter(); SCEnter();
StreamTcpSackRecord *rec = stream->sack_head; StreamTcpSackRecord *rec = stream->sack_head;
StreamTcpSackRecord *prev = NULL;
while (rec != NULL) { while (rec != NULL) {
if (SEQ_LT(rec->re, stream->last_ack)) { if (SEQ_LT(rec->re, stream->last_ack)) {
SCLogDebug("removing le %u re %u", rec->le, rec->re); SCLogDebug("removing le %u re %u", rec->le, rec->re);
// fully before last_ack, remove if (rec->next != NULL) {
if (prev != NULL) { stream->sack_head = rec->next;
if (rec == stream->sack_tail) { SCFree(rec);
stream->sack_tail = prev; rec = stream->sack_head;
prev->next = NULL; continue;
SCFree(rec);
break;
} else {
prev->next = rec->next;
SCFree(rec);
rec = prev->next;
continue;
}
} else { } else {
if (rec->next != NULL) { stream->sack_head = NULL;
stream->sack_head = rec->next; stream->sack_tail = NULL;
SCFree(rec); SCFree(rec);
rec = stream->sack_head; break;
continue;
} else {
stream->sack_head = NULL;
stream->sack_tail = NULL;
SCFree(rec);
break;
}
} }
} else if (SEQ_LT(rec->le, stream->last_ack)) { } else if (SEQ_LT(rec->le, stream->last_ack)) {
SCLogDebug("adjusting record to le %u re %u", rec->le, rec->re); SCLogDebug("adjusting record to le %u re %u", rec->le, rec->re);

@ -667,6 +667,9 @@ void StreamTcpSetOSPolicy(TcpStream *stream, Packet *p)
* \param tv Thread Variable containig input/output queue, cpu affinity * \param tv Thread Variable containig input/output queue, cpu affinity
* \param p Packet which has to be handled in this TCP state. * \param p Packet which has to be handled in this TCP state.
* \param stt Strean Thread module registered to handle the stream handling * \param stt Strean Thread module registered to handle the stream handling
*
* \retval 0 ok
* \retval -1 error
*/ */
static int StreamTcpPacketStateNone(ThreadVars *tv, Packet *p, static int StreamTcpPacketStateNone(ThreadVars *tv, Packet *p,
StreamTcpThread *stt, TcpSession *ssn, PacketQueue *pq) StreamTcpThread *stt, TcpSession *ssn, PacketQueue *pq)
@ -924,6 +927,7 @@ static int StreamTcpPacketStateNone(ThreadVars *tv, Packet *p,
SCLogDebug("default case"); SCLogDebug("default case");
break; break;
} }
return 0; 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 * inject a fake packet into the system, forcing reassembly of the
* opposing direction. * opposing direction.
* There should be only one, but to be sure we do a while loop. */ * There should be only one, but to be sure we do a while loop. */
while (stt->pseudo_queue.len > 0) { if (ssn != NULL) {
SCLogDebug("processing pseudo packet / stream end"); while (stt->pseudo_queue.len > 0) {
Packet *np = PacketDequeue(&stt->pseudo_queue); SCLogDebug("processing pseudo packet / stream end");
if (np != NULL) { Packet *np = PacketDequeue(&stt->pseudo_queue);
/* process the opposing direction of the original packet */ if (np != NULL) {
if (PKT_IS_TOSERVER(np)) { /* process the opposing direction of the original packet */
SCLogDebug("pseudo packet is to server"); if (PKT_IS_TOSERVER(np)) {
StreamTcpReassembleHandleSegment(tv, stt->ra_ctx, ssn, SCLogDebug("pseudo packet is to server");
&ssn->client, np, NULL); StreamTcpReassembleHandleSegment(tv, stt->ra_ctx, ssn,
} else { &ssn->client, np, NULL);
SCLogDebug("pseudo packet is to client"); } else {
StreamTcpReassembleHandleSegment(tv, stt->ra_ctx, ssn, SCLogDebug("pseudo packet is to client");
&ssn->server, np, NULL); 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 */ /* Process stream smsgs we may have in queue */
PacketEnqueue(pq, np); if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx) < 0) {
goto error;
} }
SCLogDebug("processing pseudo packet / stream end done");
}
/* Process stream smsgs we may have in queue */ /* recalc the csum on the packet if it was modified */
if (StreamTcpReassembleProcessAppLayer(stt->ra_ctx) < 0) { if (p->flags & PKT_STREAM_MODIFIED) {
goto error; ReCalculateChecksum(p);
} }
/* recalc the csum on the packet if it was modified */ /* check for conditions that may make us not want to log this packet */
if (p->flags & PKT_STREAM_MODIFIED) {
ReCalculateChecksum(p);
}
/* check for conditions that may make us not want to log this packet */
if (ssn != NULL) {
/* streams that hit depth */ /* streams that hit depth */
if ((ssn->client.flags & STREAMTCP_STREAM_FLAG_DEPTH_REACHED || if ((ssn->client.flags & STREAMTCP_STREAM_FLAG_DEPTH_REACHED ||
ssn->server.flags & STREAMTCP_STREAM_FLAG_DEPTH_REACHED)) ssn->server.flags & STREAMTCP_STREAM_FLAG_DEPTH_REACHED))

@ -105,7 +105,6 @@ void *TmThreadsSlot1NoIn(void *td)
{ {
ThreadVars *tv = (ThreadVars *)td; ThreadVars *tv = (ThreadVars *)td;
TmSlot *s = (TmSlot *)tv->tm_slots; TmSlot *s = (TmSlot *)tv->tm_slots;
Packet *p = NULL;
char run = 1; char run = 1;
TmEcode r = TM_ECODE_OK; TmEcode r = TM_ECODE_OK;
@ -136,7 +135,7 @@ void *TmThreadsSlot1NoIn(void *td)
TmThreadTestThreadUnPaused(tv); TmThreadTestThreadUnPaused(tv);
PACKET_PROFILING_TMM_START(p, s->tm_id); 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); PACKET_PROFILING_TMM_END(p, s->tm_id);
/* handle error */ /* handle error */
@ -147,8 +146,6 @@ void *TmThreadsSlot1NoIn(void *td)
TmqhReleasePacketsToPacketPool(&s->slot_post_pq); TmqhReleasePacketsToPacketPool(&s->slot_post_pq);
SCMutexUnlock(&s->slot_post_pq.mutex_q); SCMutexUnlock(&s->slot_post_pq.mutex_q);
if (p != NULL)
TmqhOutputPacketpool(tv, p);
TmThreadsSetFlag(tv, THV_FAILED); TmThreadsSetFlag(tv, THV_FAILED);
break; break;
} }
@ -160,10 +157,6 @@ void *TmThreadsSlot1NoIn(void *td)
tv->tmqh_out(tv, extra_p); tv->tmqh_out(tv, extra_p);
} }
tv->tmqh_out(tv, p);
if (p != NULL)
tv->tmqh_out(tv, p);
/* handle post queue */ /* handle post queue */
if (s->slot_post_pq.top != NULL) { if (s->slot_post_pq.top != NULL) {
SCMutexLock(&s->slot_post_pq.mutex_q); 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," SCLogError(SC_ERR_FATAL, "TmSlot or ThreadVars badly setup: s=%p,"
" PktAcqLoop=%p, tmqh_in=%p," " PktAcqLoop=%p, tmqh_in=%p,"
" tmqh_out=%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(); EngineKill();
TmThreadsSetFlag(tv, THV_CLOSED); TmThreadsSetFlag(tv, THV_CLOSED);

@ -792,10 +792,6 @@ int RunModeSetIPSAuto(DetectEngineCtx *de_ctx,
} }
memset(tname, 0, sizeof(tname)); memset(tname, 0, sizeof(tname));
snprintf(tname, sizeof(tname), "Recv-Q%s", cur_queue); 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); char *thread_name = SCStrdup(tname);
ThreadVars *tv_receivenfq = ThreadVars *tv_receivenfq =
@ -1003,10 +999,6 @@ int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx,
} }
memset(tname, 0, sizeof(tname)); memset(tname, 0, sizeof(tname));
snprintf(tname, sizeof(tname), "Recv-Q%s", cur_queue); 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); char *thread_name = SCStrdup(tname);

Loading…
Cancel
Save