diff --git a/.splintrc b/.splintrc index 76ca479c..67949a4a 100644 --- a/.splintrc +++ b/.splintrc @@ -38,7 +38,6 @@ +charint +matchanyintegral +voidabstract --boolops -branchstate -compdef -compdestroy @@ -46,7 +45,6 @@ -exportlocal -fcnuse -fixedformalarray --formatcode -globstate -immediatetrans -incondefs @@ -61,7 +59,6 @@ -nullret -nullstate -observertrans --predboolothers -retvalother -shiftnegative -statictrans diff --git a/src/alloc.c b/src/alloc.c index 8507224f..9dda87e7 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -39,7 +39,7 @@ INTERNAL /*@only@*/ /*@notnull@*/ void *otrng_xmalloc(size_t size) { if (oom_handler != NULL) { oom_handler(); } - fprintf(stderr, "fatal: memory exhausted (xmalloc of %zu bytes).\n", size); + fprintf(stderr, "fatal: memory exhausted (xmalloc of %lu bytes).\n", size); exit(EXIT_FAILURE); } @@ -59,7 +59,7 @@ otrng_xrealloc(/*@only@*/ /*@null@*/ void *ptr, size_t size) { if (oom_handler != NULL) { oom_handler(); } - fprintf(stderr, "fatal: memory exhausted (xrealloc of %zu bytes).\n", size); + fprintf(stderr, "fatal: memory exhausted (xrealloc of %lu bytes).\n", size); exit(EXIT_FAILURE); } diff --git a/src/client.c b/src/client.c index 78a97503..7df02d20 100644 --- a/src/client.c +++ b/src/client.c @@ -585,7 +585,9 @@ otrng_client_build_prekey_messages(uint8_t num_messages, for (i = 0; i < num_messages; i++) { ecdh_keypair_s ecdh; dh_keypair_s dh; - otrng_generate_ephemeral_keys(&ecdh, &dh); + if (!otrng_generate_ephemeral_keys(&ecdh, &dh)) { + return NULL; + } messages[i] = otrng_prekey_message_build(instance_tag, &ecdh, &dh); if (!messages[i]) { diff --git a/src/client_profile.c b/src/client_profile.c index 3d6b62fb..3af4da96 100644 --- a/src/client_profile.c +++ b/src/client_profile.c @@ -188,7 +188,7 @@ tstatic uint32_t client_profile_body_serialize_pre_transitional_signature( num_fields++; /* DSA key */ - if (client_profile->dsa_key && client_profile->dsa_key_len) { + if ((client_profile->dsa_key != NULL) && (client_profile->dsa_key_len != 0)) { w += otrng_serialize_uint16(dst + w, OTRNG_CLIENT_PROFILE_FIELD_DSA_KEY); w += otrng_serialize_bytes_array(dst + w, client_profile->dsa_key, client_profile->dsa_key_len); diff --git a/src/fingerprint.c b/src/fingerprint.c index 7eb5dc62..938dede3 100644 --- a/src/fingerprint.c +++ b/src/fingerprint.c @@ -55,7 +55,7 @@ INTERNAL otrng_result otrng_serialize_fingerprint(otrng_fingerprint fp, memset(ser, 0, ED448_POINT_BYTES); - if (!fp) { + if (fp == NULL) { // TODO: unsure about this check. This is an array return OTRNG_ERROR; } diff --git a/src/fragment.c b/src/fragment.c index c50633cd..4e3bddc5 100644 --- a/src/fragment.c +++ b/src/fragment.c @@ -327,8 +327,8 @@ INTERNAL otrng_result otrng_expire_fragments(time_t now, fragment_context_s *ctx = current->data; list_element_s *to_free = NULL; - if (ctx && - difftime(now, ctx->last_fragment_received_at) < expiration_time) { + if ((ctx != NULL) && + (difftime(now, ctx->last_fragment_received_at) < expiration_time)) { *contexts = otrng_list_remove_element(current, *contexts); otrng_fragment_context_free(ctx); to_free = current; diff --git a/src/instance_tag.c b/src/instance_tag.c index 35700441..d54b5923 100644 --- a/src/instance_tag.c +++ b/src/instance_tag.c @@ -38,7 +38,7 @@ API otrng_bool otrng_instag_get(otrng_instag_s *otrng_instag, OtrlInsTag *tmp_instag; OtrlUserState us = otrl_userstate_create(); - if (!us) { + if (us == NULL) { // TODO: unsure about this check return otrng_false; } diff --git a/src/list.c b/src/list.c index ba6aa73b..55e384e7 100644 --- a/src/list.c +++ b/src/list.c @@ -181,7 +181,7 @@ otrng_list_get(const void *wanted, list_element_s *head, list_element_s *cursor = head; while (cursor) { - if (fn && fn(cursor->data, wanted)) { + if ((fn != NULL) && fn(cursor->data, wanted)) { return cursor; } diff --git a/src/otrng.c b/src/otrng.c index e6dc01f5..e912c660 100644 --- a/src/otrng.c +++ b/src/otrng.c @@ -335,12 +335,14 @@ tstatic otrng_result message_to_display_without_tag(otrng_response_s *response, } tstatic void set_running_version_from_tag(otrng_s *otr, const string_p msg) { - if (allow_version(otr, OTRNG_ALLOW_V4) && strstr(msg, tag_version_v4)) { + if (allow_version(otr, OTRNG_ALLOW_V4) && + (strstr(msg, tag_version_v4) != NULL)) { otr->running_version = OTRNG_PROTOCOL_VERSION_4; return; } - if (allow_version(otr, OTRNG_ALLOW_V3) && strstr(msg, tag_version_v3)) { + if (allow_version(otr, OTRNG_ALLOW_V3) && + (strstr(msg, tag_version_v3) != NULL)) { otr->running_version = OTRNG_PROTOCOL_VERSION_3; return; } @@ -355,9 +357,9 @@ tstatic otrng_bool message_is_query(const string_p msg) { tstatic void set_running_version_from_query_message(otrng_s *otr, const string_p msg) { - if (allow_version(otr, OTRNG_ALLOW_V4) && strstr(msg, "4")) { + if (allow_version(otr, OTRNG_ALLOW_V4) && (strstr(msg, "4") != NULL)) { otr->running_version = OTRNG_PROTOCOL_VERSION_4; - } else if (allow_version(otr, OTRNG_ALLOW_V3) && strstr(msg, "3")) { + } else if (allow_version(otr, OTRNG_ALLOW_V3) && (strstr(msg, "3") != NULL)) { otr->running_version = OTRNG_PROTOCOL_VERSION_3; } } @@ -1225,7 +1227,8 @@ tstatic otrng_bool verify_non_interactive_auth_message( free(t); t = NULL; - if (initiator.exp_client_profile && initiator.exp_prekey_profile) { + if ((initiator.exp_client_profile != NULL) && + (initiator.exp_prekey_profile != NULL)) { /* the fallback */ if (!build_fallback_non_interactive_rsign_tag( &t, &t_len, &initiator, &responder, @@ -2251,7 +2254,8 @@ static otrng_result receive_defragmented_message(otrng_response_s *response, response->to_display = NULL; /* A DH-Commit sets our running version to 3 */ - if (allow_version(otr, OTRNG_ALLOW_V3) && strstr(msg, "?OTR:AAMC")) { + if (allow_version(otr, OTRNG_ALLOW_V3) && + (strstr(msg, "?OTR:AAMC") != NULL)) { otr->running_version = OTRNG_PROTOCOL_VERSION_3; } diff --git a/src/persistence.c b/src/persistence.c index f64c1280..41c7247e 100644 --- a/src/persistence.c +++ b/src/persistence.c @@ -40,7 +40,7 @@ static char *otrng_client_get_storage_id(const otrng_client_s *client) { return NULL; } - if (account_name && protocol_name) { + if ((account_name != NULL) && (protocol_name != NULL)) { size_t n = strlen(protocol_name) + strlen(account_name) + 2; key = otrng_xmalloc(n); @@ -296,7 +296,8 @@ INTERNAL otrng_result otrng_client_instance_tag_read_from(otrng_client_s *client, FILE *instagf) { gcry_error_t ret; - if (!client->global_state->user_state_v3) { + if (client->global_state->user_state_v3 == + NULL) { // TODO: unsure about this check. It is not a pointer return OTRNG_ERROR; } diff --git a/src/protocol.c b/src/protocol.c index fc9b305a..e410990b 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -222,9 +222,11 @@ tstatic otrng_result send_data_message(string_p *to_send, const uint8_t *msg, memset(enc_key, 0, ENC_KEY_BYTES); memset(mac_key, 0, MAC_KEY_BYTES); - otrng_key_manager_derive_chain_keys(enc_key, mac_key, otr->keys, NULL, - otr->client->max_stored_msg_keys, 0, 's', - warn); + if (!otrng_key_manager_derive_chain_keys(enc_key, mac_key, otr->keys, NULL, + otr->client->max_stored_msg_keys, 0, + 's', warn)) { + return OTRNG_ERROR; + } data_msg = generate_data_message(otr, ratchet_id); if (!data_msg) { diff --git a/src/smp_protocol.c b/src/smp_protocol.c index a2288442..564b413a 100644 --- a/src/smp_protocol.c +++ b/src/smp_protocol.c @@ -1196,7 +1196,10 @@ INTERNAL otrng_smp_event otrng_reply_with_smp_message_2(tlv_s **to_send, *to_send = NULL; - generate_smp_message_2(&msg_2, smp->message1, smp); + if (!generate_smp_message_2(&msg_2, smp->message1, smp)) { + return OTRNG_SMP_EVENT_ERROR; + } + if (!smp_message_2_serialize(&buffer, &buff_len, &msg_2)) { return OTRNG_SMP_EVENT_ERROR; } diff --git a/src/v3.c b/src/v3.c index 80d93114..2888e3d7 100644 --- a/src/v3.c +++ b/src/v3.c @@ -712,7 +712,7 @@ INTERNAL otrng_result otrng_v3_receive_message(char **to_send, *to_send = otrng_v3_retrieve_injected_message(conn); - if (to_display && new_msg) { + if ((to_display != NULL) && (new_msg != NULL)) { *to_display = otrng_xstrdup(new_msg); } @@ -777,7 +777,7 @@ INTERNAL otrng_result otrng_v3_smp_start(char **to_send, size_t secretlen, otrng_v3_conn_s *conn) { char *q = NULL; - if (question && q_len > 0) { + if ((question != NULL) && q_len > 0) { q = otrng_xmalloc(q_len + 1); q = memcpy(q, question, q_len); q[q_len] = 0; @@ -822,7 +822,7 @@ tstatic void otrng_v3_store_injected_message(const char *msg, // TODO: @client This is where we should ADD a new element to the list. // We are just ignoring for now. - if (conn->injected_message && msg) { + if ((conn->injected_message != NULL) && (msg != NULL)) { free(conn->injected_message); }