Skip to content

Commit

Permalink
Merge pull request #203 from peterpalau/master
Browse files Browse the repository at this point in the history
Fix some Splint warnings adding related to `nullret` rule in some functions
  • Loading branch information
claucece authored Jun 20, 2019
2 parents 1f81d6a + 634a084 commit 1944361
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 76 deletions.
17 changes: 9 additions & 8 deletions src/otrng.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ tstatic otrng_result serialize_and_encode_auth_r(string_p *dst,
return OTRNG_SUCCESS;
}

tstatic char *
tstatic /*@null@*/ char *
otrng_generate_session_state_string(const otrng_shared_session_state_s *state) {
char *sss;
size_t sss_len;
Expand Down Expand Up @@ -589,7 +589,7 @@ otrng_generate_session_state_string(const otrng_shared_session_state_s *state) {
return sss;
}

static const char *get_shared_session_state(otrng_s *otr) {
/*@null@*/ static const char *get_shared_session_state(otrng_s *otr) {
otrng_shared_session_state_s state;

if (otr->shared_session_state) {
Expand Down Expand Up @@ -978,7 +978,8 @@ tstatic otrng_result reply_with_non_interactive_auth_message(string_p *dst,
}

/* This is only used for tests */
INTERNAL prekey_ensemble_s *otrng_build_prekey_ensemble(otrng_s *otr) {
INTERNAL /*@null@*/ prekey_ensemble_s *
otrng_build_prekey_ensemble(otrng_s *otr) {
ecdh_keypair_s ecdh;
dh_keypair_s dh;
otrng_client_s *client;
Expand Down Expand Up @@ -1779,7 +1780,8 @@ tstatic otrng_result receive_auth_i(char **dst, const uint8_t *buffer,
return otrng_send_message(dst, "", NULL, MSG_FLAGS_IGNORE_UNREADABLE, otr);
}

tstatic tlv_list_s *deserialize_received_tlvs(const uint8_t *src, size_t len) {
/*@null@*/ tstatic tlv_list_s *deserialize_received_tlvs(const uint8_t *src,
size_t len) {
uint8_t *tlvs_start = NULL;
size_t tlvs_len;

Expand Down Expand Up @@ -1838,7 +1840,7 @@ tstatic unsigned int extract_word(const unsigned char *bufp) {
return use;
}

tstatic tlv_s *process_tlv(const tlv_s *tlv, otrng_s *otr) {
/*@null@*/ tstatic tlv_s *process_tlv(const tlv_s *tlv, otrng_s *otr) {
if (tlv->type == OTRNG_TLV_NONE || tlv->type == OTRNG_TLV_PADDING) {
return NULL;
}
Expand All @@ -1864,9 +1866,8 @@ tstatic tlv_s *process_tlv(const tlv_s *tlv, otrng_s *otr) {
return otrng_process_smp_tlv(tlv, otr);
}

tstatic otrng_result process_received_tlvs(tlv_list_s **to_send,
otrng_response_s *response,
otrng_s *otr) {
/*@null@*/ tstatic otrng_result process_received_tlvs(
tlv_list_s **to_send, otrng_response_s *response, otrng_s *otr) {
const tlv_list_s *current = response->tlvs;
while (current) {
tlv_s *tlv = process_tlv(current->data, otr);
Expand Down
5 changes: 3 additions & 2 deletions src/otrng.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ API otrng_result otrng_send_non_interactive_auth(

API otrng_result otrng_init(otrng_bool die);

INTERNAL prekey_ensemble_s *otrng_build_prekey_ensemble(otrng_s *otr);
INTERNAL /*@null@*/ prekey_ensemble_s *
otrng_build_prekey_ensemble(otrng_s *otr);

API int otrng_get_msg_type(const string_p msg);

Expand All @@ -121,7 +122,7 @@ tstatic otrng_shared_session_state_s
tstatic
otrng_get_shared_session_state(otrng_s *otr);

tstatic char *
tstatic /*@null@*/ char *
otrng_generate_session_state_string(const otrng_shared_session_state_s *state);

tstatic tlv_s *process_tlv(const tlv_s *tlv, otrng_s *otr);
Expand Down
73 changes: 38 additions & 35 deletions src/prekey_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static otrng_result prekey_message_decode(const char *msg, uint8_t **buffer,
/*
The returned value will be owned by the caller
*/
static char *
/*@null@*/ static char *
serialize_dake1(/*@notnull@*/ otrng_prekey_dake1_message_s *dake1) {
uint8_t *ser = NULL;
size_t ser_len = 0;
Expand Down Expand Up @@ -572,9 +572,9 @@ create_rsig_auth_for_dake3(otrng_client_s *client,
return ret;
}

tstatic char *send_dake3(otrng_client_s *client,
otrng_prekey_request_s *request,
const otrng_prekey_dake2_message_s *msg) {
/*@null@*/ tstatic char *send_dake3(otrng_client_s *client,
otrng_prekey_request_s *request,
const otrng_prekey_dake2_message_s *msg) {
/*
t = 0x01 || KDF(usage_receiver_client_profile, Alices_Client_Profile, 64) ||
KDF(usage_receiver_prekey_composite_identity,
Expand Down Expand Up @@ -611,9 +611,9 @@ tstatic char *send_dake3(otrng_client_s *client,
return ret;
}

static char *process_received_dake2(otrng_client_s *client,
otrng_prekey_request_s *request,
const otrng_prekey_dake2_message_s *msg) {
/*@null@*/ static char *
process_received_dake2(otrng_client_s *client, otrng_prekey_request_s *request,
const otrng_prekey_dake2_message_s *msg) {
if (msg->client_instance_tag != otrng_client_get_instance_tag(client)) {
return NULL;
}
Expand Down Expand Up @@ -648,9 +648,10 @@ void otrng_prekey_check_account_request(otrng_client_s *client) {
}
}

static char *receive_dake2(otrng_client_s *client,
otrng_prekey_request_s *request,
const uint8_t *decoded, size_t decoded_len) {
/*@null@*/ static char *receive_dake2(otrng_client_s *client,
otrng_prekey_request_s *request,
const uint8_t *decoded,
size_t decoded_len) {
otrng_prekey_dake2_message_s msg;
char *ret = NULL;

Expand All @@ -666,7 +667,7 @@ static char *receive_dake2(otrng_client_s *client,
return ret;
}

static char *receive_success_or_failure(
/*@null@*/ static char *receive_success_or_failure(
otrng_client_s *client, otrng_prekey_request_s *request,
const uint8_t *decoded, size_t decoded_len, const size_t len,
const uint8_t usage, const uint8_t error_code,
Expand Down Expand Up @@ -708,27 +709,29 @@ static char *receive_success_or_failure(
return NULL;
}

static char *receive_success(otrng_client_s *client,
otrng_prekey_request_s *request,
const uint8_t *decoded, size_t decoded_len) {
/*@null@*/ static char *receive_success(otrng_client_s *client,
otrng_prekey_request_s *request,
const uint8_t *decoded,
size_t decoded_len) {
assert(client->prekey_manager != NULL);
return receive_success_or_failure(
client, request, decoded, decoded_len, OTRNG_PREKEY_SUCCESS_MSG_LEN,
USAGE_SUCCESS_MAC, OTRNG_PREKEY_CLIENT_INVALID_SUCCESS,
client->prekey_manager->callbacks->success_received);
}

static char *receive_failure(otrng_client_s *client,
otrng_prekey_request_s *request,
const uint8_t *decoded, size_t decoded_len) {
/*@null@*/ static char *receive_failure(otrng_client_s *client,
otrng_prekey_request_s *request,
const uint8_t *decoded,
size_t decoded_len) {
assert(client->prekey_manager != NULL);
return receive_success_or_failure(
client, request, decoded, decoded_len, OTRNG_PREKEY_FAILURE_MSG_LEN,
USAGE_FAILURE_MAC, OTRNG_PREKEY_CLIENT_INVALID_FAILURE,
client->prekey_manager->callbacks->failure_received);
}

static char *process_received_storage_status(
/*@null@*/ static char *process_received_storage_status(
otrng_client_s *client, const otrng_prekey_request_s *request,
const otrng_prekey_storage_status_message_s *msg) {
assert(client->prekey_manager != NULL);
Expand Down Expand Up @@ -759,10 +762,10 @@ static char *process_received_storage_status(
return NULL;
}

static char *receive_storage_status(otrng_client_s *client,
otrng_prekey_request_s *request,
const uint8_t *decoded,
size_t decoded_len) {
/*@null@*/ static char *receive_storage_status(otrng_client_s *client,
otrng_prekey_request_s *request,
const uint8_t *decoded,
size_t decoded_len) {
otrng_prekey_storage_status_message_s msg;
char *ret;

Expand All @@ -777,9 +780,9 @@ static char *receive_storage_status(otrng_client_s *client,
return ret;
}

static char *receive_no_prekey_in_storage(otrng_client_s *client,
const uint8_t *decoded,
const size_t decoded_len) {
/*@null@*/ static char *receive_no_prekey_in_storage(otrng_client_s *client,
const uint8_t *decoded,
const size_t decoded_len) {
uint32_t instance_tag = 0;
size_t read = 0;
uint8_t *identity_ser = NULL;
Expand Down Expand Up @@ -841,9 +844,8 @@ static otrng_result process_received_prekey_ensemble_retrieval(
return OTRNG_SUCCESS;
}

static char *receive_prekey_ensemble_retrieval(otrng_client_s *client,
const uint8_t *decoded,
const size_t decoded_len) {
/*@null@*/ static char *receive_prekey_ensemble_retrieval(
otrng_client_s *client, const uint8_t *decoded, const size_t decoded_len) {
otrng_prekey_ensemble_retrieval_message_s msg;

if (!otrng_prekey_ensemble_retrieval_message_deserialize(&msg, decoded,
Expand All @@ -863,7 +865,7 @@ static char *receive_prekey_ensemble_retrieval(otrng_client_s *client,
return NULL;
}

static otrng_prekey_request_s *
/*@null@*/ static otrng_prekey_request_s *
check_current_dake_request(const otrng_client_s *client, const char *from) {
otrng_prekey_request_s *rfa;

Expand All @@ -882,10 +884,10 @@ check_current_dake_request(const otrng_client_s *client, const char *from) {
return NULL;
}

static char *receive_decoded_message(otrng_client_s *client,
const uint8_t *decoded,
const size_t decoded_len,
/*@notnull@*/ const char *from) {
/*@null@*/ static char *
receive_decoded_message(otrng_client_s *client, const uint8_t *decoded,
const size_t decoded_len,
/*@notnull@*/ const char *from) {
uint8_t msg_type = 0;
otrng_prekey_request_s *request = NULL;
char *res;
Expand Down Expand Up @@ -938,13 +940,14 @@ static char *receive_decoded_message(otrng_client_s *client,
case OTRNG_PREKEY_ENSEMBLE_RETRIEVAL_MSG:
return receive_prekey_ensemble_retrieval(client, decoded, decoded_len);
default:
notify_error(client, OTRNG_PREKEY_CLIENT_MALFORMED_MSG, request->ctx);
notify_error(client, OTRNG_PREKEY_CLIENT_MALFORMED_MSG,
request != NULL ? request->ctx : NULL);
}

return NULL;
}

tstatic otrng_prekey_server_s *
/*@null@*/ tstatic otrng_prekey_server_s *
find_server_for_identity(/*@notnull@*/ otrng_prekey_manager_s *manager,
const char *identity) {
otrng_prekey_server_s *server = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/prekey_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ tstatic otrng_result otrng_prekey_profile_sign(
return OTRNG_SUCCESS;
}

INTERNAL otrng_prekey_profile_s *
/*@null@*/ INTERNAL otrng_prekey_profile_s *
otrng_prekey_profile_build(uint32_t instance_tag,
const otrng_keypair_s *longterm_pair) {
otrng_prekey_profile_s *prekey_profile;
Expand Down
2 changes: 1 addition & 1 deletion src/prekey_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ INTERNAL void otrng_prekey_profile_free(otrng_prekey_profile_s *dst);
INTERNAL void otrng_prekey_profile_copy(otrng_prekey_profile_s *dst,
const otrng_prekey_profile_s *src);

INTERNAL otrng_prekey_profile_s *
/*@null@*/ INTERNAL otrng_prekey_profile_s *
otrng_prekey_profile_build(uint32_t instance_tag,
const otrng_keypair_s *longterm_pair);

Expand Down
2 changes: 1 addition & 1 deletion src/prekey_proofs.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ INTERNAL otrng_bool otrng_ecdh_proof_verify(ecdh_proof_s *px,
return otrng_false;
}

tstatic void *gen_random_data(size_t n, random_generator gen) {
/*@null@*/ tstatic void *gen_random_data(size_t n, random_generator gen) {
if (gen == NULL) {
void *rhash, *rbuf;
rbuf = gcry_random_bytes_secure(n, GCRY_STRONG_RANDOM);
Expand Down
4 changes: 2 additions & 2 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ tstatic otrng_result encrypt_data_message(data_message_s *data_msg,
return OTRNG_SUCCESS;
}

tstatic data_message_s *generate_data_message(const otrng_s *otr,
const uint32_t ratchet_id) {
/*@null@*/ tstatic data_message_s *
generate_data_message(const otrng_s *otr, const uint32_t ratchet_id) {
data_message_s *data_msg = otrng_data_message_new();
if (!data_msg) {
return NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ INTERNAL size_t otrng_serialize_ring_sig(uint8_t *dst,
return cursor - dst;
}

INTERNAL uint8_t *otrng_serialize_old_mac_keys(list_element_s *old_mac_keys) {
/*@null@*/ INTERNAL uint8_t *
otrng_serialize_old_mac_keys(list_element_s *old_mac_keys) {
size_t num_mac_keys = otrng_list_len(old_mac_keys);
size_t serlen = num_mac_keys * MAC_KEY_BYTES;
uint8_t *ser_mac_keys;
Expand Down
3 changes: 2 additions & 1 deletion src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ INTERNAL size_t otrng_serialize_shared_prekey(
*
* @param [old_mac_keys] The list of old mac keys.
*/
INTERNAL uint8_t *otrng_serialize_old_mac_keys(list_element_s *old_mac_keys);
/*@null@*/ INTERNAL uint8_t *
otrng_serialize_old_mac_keys(list_element_s *old_mac_keys);

INTERNAL size_t otrng_serialize_phi(uint8_t *dst,
const char *shared_session_state,
Expand Down
8 changes: 4 additions & 4 deletions src/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ tstatic void handle_smp_event_cb_v4(const otrng_smp_event event,
}
}

tstatic tlv_s *otrng_process_smp(otrng_smp_event *ret, smp_protocol_s *smp,
const tlv_s *tlv) {
/*@null@*/ tstatic tlv_s *
otrng_process_smp(otrng_smp_event *ret, smp_protocol_s *smp, const tlv_s *tlv) {
otrng_smp_event event = *ret;
tlv_s *to_send = NULL;

Expand Down Expand Up @@ -164,7 +164,7 @@ INTERNAL tlv_s *otrng_process_smp_tlv(const tlv_s *tlv, otrng_s *otr) {
return out;
}

tstatic tlv_s *
/*@null@*/ tstatic tlv_s *
otrng_smp_initiate(const otrng_client_profile_s *initiator_profile,
const otrng_client_profile_s *responder_profile,
const uint8_t *question, const size_t q_len,
Expand Down Expand Up @@ -279,7 +279,7 @@ INTERNAL otrng_result otrng_smp_start(string_p *to_send,
return OTRNG_ERROR;
}

tstatic tlv_s *
/*@null@*/ tstatic tlv_s *
otrng_smp_provide_secret(otrng_smp_event *event, smp_protocol_s *smp,
const otrng_client_profile_s *our_profile,
const otrng_client_profile_s *their_client_profile,
Expand Down
7 changes: 4 additions & 3 deletions src/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#include "shared.h"
#include "tlv.h"

INTERNAL tlv_s *otrng_process_smp_tlv(const tlv_s *tlv, otrng_s *otr);
/*@null@*/ INTERNAL tlv_s *otrng_process_smp_tlv(const tlv_s *tlv,
otrng_s *otr);

INTERNAL otrng_result otrng_smp_start(string_p *to_send,
const uint8_t *question,
Expand All @@ -47,14 +48,14 @@ API otrng_result otrng_smp_abort(string_p *to_send, otrng_s *otr);

#ifdef OTRNG_SMP_PRIVATE

tstatic tlv_s *
/*@null@*/ tstatic tlv_s *
otrng_smp_initiate(const otrng_client_profile_s *initiator_profile,
const otrng_client_profile_s *responder_profile,
const uint8_t *question, const size_t q_len,
const uint8_t *secret, const size_t secretlen, uint8_t *ssid,
smp_protocol_s *smp, otrng_s *conversation);

tstatic tlv_s *
/*@null@*/ tstatic tlv_s *
otrng_smp_provide_secret(otrng_smp_event *event, smp_protocol_s *smp,
const otrng_client_profile_s *our_profile,
const otrng_client_profile_s *their_profile,
Expand Down
Loading

0 comments on commit 1944361

Please sign in to comment.