From dcbbf71cb2c2c6f0f327dc8804735073c49b5f2e Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 25 Jan 2023 11:31:12 +0000 Subject: [PATCH] Coverity suppressions --- client/sub_client_output.c | 1 + lib/socks_mosq.c | 7 +++++++ plugins/examples/delayed-auth/mosquitto_delayed_auth.c | 3 ++- src/bridge.c | 2 ++ src/keepalive.c | 1 + src/plugin_public.c | 1 + test/unit/keepalive_test.c | 1 + 7 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client/sub_client_output.c b/client/sub_client_output.c index 51f0d51f..e954e3c0 100644 --- a/client/sub_client_output.c +++ b/client/sub_client_output.c @@ -857,6 +857,7 @@ void print_message(struct mosq_config *lcfg, const struct mosquitto_message *mes #ifdef WIN32 rand_s(&r); #else + /* coverity[dont_call] - we don't care about random() not being cryptographically secure here */ r = random(); #endif if((long)(r%10000) >= lcfg->random_filter){ diff --git a/lib/socks_mosq.c b/lib/socks_mosq.c index b50c2d51..8909d986 100644 --- a/lib/socks_mosq.c +++ b/lib/socks_mosq.c @@ -406,6 +406,13 @@ int socks5__read(struct mosquitto *mosq) packet__cleanup(&mosq->in_packet); return MOSQ_ERR_PROTOCOL; } + /* coverity[tainted_data] - we know the value of + * mosq->in_packet.packet_lenth is within a bound. At the start of + * this if statement, it was 5. The next set of if statements add + * either (4+2-1)=5 to its value, or (16+2-1)=17 to its value, or + * the contents of a uint8_t, which can be a maximum of 255. So the + * range is 10 to 260 bytes. Coverity most likely doesn't realise + * this because the += promotes to the size of packet_length. */ payload = mosquitto__realloc(mosq->in_packet.payload, mosq->in_packet.packet_length); if(payload){ mosq->in_packet.payload = payload; diff --git a/plugins/examples/delayed-auth/mosquitto_delayed_auth.c b/plugins/examples/delayed-auth/mosquitto_delayed_auth.c index 4c147942..c79993d5 100644 --- a/plugins/examples/delayed-auth/mosquitto_delayed_auth.c +++ b/plugins/examples/delayed-auth/mosquitto_delayed_auth.c @@ -125,7 +125,8 @@ static int tick_callback(int event, void *event_data, void *userdata) #ifdef WIN32 r = rand() % 1000; #else - r = random() % 1000; + /* coverity[dont_call] - we don't care about random() not being cryptographically secure here */ + r = random() % 1000; #endif if(r > 740){ mosquitto_complete_basic_auth(client->id, MOSQ_ERR_AUTH); diff --git a/src/bridge.c b/src/bridge.c index ef6c8d3f..f5b73a7d 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -464,7 +464,9 @@ int bridge__connect(struct mosquitto *context) mosquitto__set_state(context, mosq_cs_new); context->sock = INVALID_SOCKET; + /* coverity[missing_lock] - broker is single threaded, so no lock required */ context->last_msg_in = db.now_s; + /* coverity[missing_lock] - broker is single threaded, so no lock required */ context->next_msg_out = db.now_s + context->bridge->keepalive; context->keepalive = context->bridge->keepalive; context->clean_start = context->bridge->clean_start; diff --git a/src/keepalive.c b/src/keepalive.c index 7edfa6c9..05ba074d 100644 --- a/src/keepalive.c +++ b/src/keepalive.c @@ -212,6 +212,7 @@ int keepalive__update(struct mosquitto *context) { #ifndef WITH_OLD_KEEPALIVE keepalive__remove(context); + /* coverity[missing_lock] - broker is single threaded, so no lock required */ context->last_msg_in = db.now_s; keepalive__add(context); #else diff --git a/src/plugin_public.c b/src/plugin_public.c index 726933ba..e4d13450 100644 --- a/src/plugin_public.c +++ b/src/plugin_public.c @@ -771,6 +771,7 @@ BROKER_EXPORT int mosquitto_persist_base_msg_add(struct mosquitto_base_msg *msg_ if(message_expiry_interval_tt > UINT32_MAX){ message_expiry_interval = UINT32_MAX; }else{ + /* coverity[store_truncates_time_t] - we check above whether the value will fit in a uint32_t */ message_expiry_interval = (uint32_t)message_expiry_interval_tt; } } diff --git a/test/unit/keepalive_test.c b/test/unit/keepalive_test.c index 21fa01bc..2d3cf150 100644 --- a/test/unit/keepalive_test.c +++ b/test/unit/keepalive_test.c @@ -188,6 +188,7 @@ static void TEST_100k_random_clients(void) for(int i=0; i