ThreadSafe: Fix CVE 1670700 thread number logging

This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2026-04-16 13:10:43 +01:00
1 parent c50ea5bb37
commit 5d76f75c24
2 files changed
+17 -10

No files matched your search

+6
View File
@@ -1344,7 +1344,13 @@ coap_log_impl(coap_log_t level, const char *format, ...) {
#if COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING
if (thread_no == 0) {
/*
* All other call to coap_mutex_lock(&m_io_threads) immediately
* by setting thread_no if 0. So deadlock should never occur.
*/
coap_mutex_lock(&m_io_threads);
thread_no = ++max_thread_no;
coap_mutex_unlock(&m_io_threads);
}
fprintf(log_fd, "%2d ", thread_no);
#endif /* COAP_THREAD_SAFE && COAP_THREAD_NUM_LOGGING */
+11 -10
View File
@@ -212,6 +212,10 @@ coap_io_process_configure_threads(coap_context_t *context, uint32_t thread_count
return 0;
coap_mutex_lock(&m_io_threads);
/* Need to make sure it is non zero incase coap_log*() is called */
if (thread_no == 0) {
thread_no = ++max_thread_no;
}
#ifdef _WIN32
old_sigint_handler = signal(COAP_THREAD_KILL_SIG, coap_thread_sigint_handler);
#else /* ! _WIN32 */
@@ -247,16 +251,9 @@ coap_io_process_configure_threads(coap_context_t *context, uint32_t thread_count
if (context->thread_id_count) {
coap_io_process_kill_threads(context);
}
if (thread_no == 0) {
/* Set this thread with its thread number */
thread_no = 1;
base_thread = thread_no + 1;
max_thread_no = 1 + thread_count;
} else {
/* Existing thread starting things up */
base_thread = max_thread_no + 1;
max_thread_no = base_thread + thread_count - 1;
}
base_thread = max_thread_no + 1;
max_thread_no = base_thread + thread_count - 1;
context->thread_id = coap_malloc_type(COAP_STRING, thread_count * sizeof(pthread_t));
if (!context->thread_id) {
coap_log_err("thread start up memory allocate failure\n");
@@ -293,6 +290,10 @@ void
coap_io_process_remove_threads_lkd(coap_context_t *context) {
coap_lock_unlock();
coap_mutex_lock(&m_io_threads);
/* Need to make sure it is non zero incase coap_log*() is called */
if (thread_no == 0) {
thread_no = ++max_thread_no;
}
if (context->thread_id_count) {
coap_io_process_kill_threads(context);