Fix potential deadlock in output

Coverity:
** CID 1296115:  Program hangs  (ORDER_REVERSAL)
/src/tm-threads.c: 1670 in TmThreadClearThreadsFamily()

The problem is with the by default unused '%m' output parameter.
To get the thread vars it takes the tv_root_lock. This may already
be locked by the calling thread. Also, it could lead to a case of
wrong lock order between the tv_root_lock and the thread_store_lock.

Very unlikely to happen though.

As the %m param isn't really used (by default) this patch just
disables it.
pull/1454/head
Victor Julien 10 years ago
parent 94321b8a2f
commit b9aaf5a9ab

@ -358,12 +358,19 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
substr = temp_fmt;
substr++;
break;
case SC_LOG_FMT_TM:
temp_fmt[0] = '\0';
/* disabled to prevent dead lock:
* log or alloc (which calls log on error) can call TmThreadsGetCallingThread
* which will lock tv_root_lock. This can happen while we already hold this
* lock. */
#if 0
ThreadVars *tv = TmThreadsGetCallingThread();
cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - *msg),
"%s%s", substr, ((tv != NULL)? tv->name: "UNKNOWN TM"));
#endif
cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - *msg),
"%s%s", substr, "N/A");
if (cw < 0)
goto error;
temp += cw;
@ -371,7 +378,6 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file,
substr = temp_fmt;
substr++;
break;
case SC_LOG_FMT_LOG_LEVEL:
temp_fmt[0] = '\0';
s = SCMapEnumValueToName(log_level, sc_log_level_map);

Loading…
Cancel
Save