]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcap-log: unify lock handling, fixes Coverity warn
authorVictor Julien <victor@inliniac.net>
Wed, 30 Jul 2014 08:58:30 +0000 (10:58 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 30 Jul 2014 10:34:00 +0000 (12:34 +0200)
*** CID 1229124:  Data race condition  (MISSING_LOCK)
/src/log-pcap.c: 363 in PcapLog()
357         {
358             return TM_ECODE_OK;
359         }
360
361         PcapLogLock(pl);
362
>>>     CID 1229124:  Data race condition  (MISSING_LOCK)
>>>     Accessing "pl->pkt_cnt" without holding lock "PcapLogData_.plog_lock". Elsewhere, "PcapLogData_.pkt_cnt" is accessed with "PcapLogData_.plog_lock" held 1 out of 2 times (1 of these accesses strongly imply that it is necessary).
363         pl->pkt_cnt++;
364         pl->h->ts.tv_sec = p->ts.tv_sec;
365         pl->h->ts.tv_usec = p->ts.tv_usec;
366         pl->h->caplen = GET_PKT_LEN(p);
367         pl->h->len = GET_PKT_LEN(p);
368         len = sizeof(*pl->h) + GET_PKT_LEN(p);

src/log-pcap.c

index 7b8cebd778e5be9ae5555c1314a532f2f1983089..bc27414670f7cc2159a5327a7b69dcafd0c3a14e 100644 (file)
@@ -481,7 +481,7 @@ static TmEcode PcapLogDataInit(ThreadVars *t, void *initdata, void **data)
         td->pcap_log = pl;
     BUG_ON(td->pcap_log == NULL);
 
-    SCMutexLock(&td->pcap_log->plog_lock);
+    PcapLogLock(td->pcap_log);
 
     /** Use the Ouptut Context (file pointer and mutex) */
     td->pcap_log->pkt_cnt = 0;
@@ -496,7 +496,7 @@ static TmEcode PcapLogDataInit(ThreadVars *t, void *initdata, void **data)
     struct tm *tms = SCLocalTime(ts.tv_sec, &local_tm);
     td->pcap_log->prev_day = tms->tm_mday;
 
-    SCMutexUnlock(&td->pcap_log->plog_lock);
+    PcapLogUnlock(td->pcap_log);
 
     /* count threads in the global structure */
     SCMutexLock(&pl->plog_lock);