From 214060ef20499332b0369030b664a8e239518661 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 10 May 2013 20:30:47 +0200 Subject: [PATCH] Fix warnings for functions marked __attribute((warn_unused_result)). --- src/net_packet.c | 6 +++++- src/openssl/prf.c | 10 ++++++++-- src/protocol_auth.c | 10 ++++++---- src/protocol_key.c | 12 ++++++++---- src/sptps.c | 7 +++++-- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/net_packet.c b/src/net_packet.c index c2552619..9024f262 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -669,7 +669,11 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { /* Add the message authentication code */ if(digest_active(n->outdigest)) { - digest_create(n->outdigest, &inpkt->seqno, inpkt->len, (char *)&inpkt->seqno + inpkt->len); + if(!digest_create(n->outdigest, &inpkt->seqno, inpkt->len, (char *)&inpkt->seqno + inpkt->len)) { + logger(DEBUG_TRAFFIC, LOG_ERR, "Error while encrypting packet to %s (%s)", n->name, n->hostname); + goto end; + } + inpkt->len += digest_length(n->outdigest); } diff --git a/src/openssl/prf.c b/src/openssl/prf.c index 943bd620..4f5a52be 100644 --- a/src/openssl/prf.c +++ b/src/openssl/prf.c @@ -54,10 +54,16 @@ static bool prf_xor(int nid, const char *secret, size_t secretlen, char *seed, s while(outlen > 0) { /* Inner HMAC */ - digest_create(digest, data, len + seedlen, data); + if(!digest_create(digest, data, len + seedlen, data)) { + digest_close(digest); + return false; + } /* Outer HMAC */ - digest_create(digest, data, len + seedlen, hash); + if(!digest_create(digest, data, len + seedlen, hash)) { + digest_close(digest); + return false; + } /* XOR the results of the outer HMAC into the out buffer */ for(int i = 0; i < len && i < outlen; i++) diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 7940ab80..a4e3b24f 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -273,7 +273,8 @@ bool send_metakey(connection_t *c) { key[0] &= 0x7F; - cipher_set_key_from_rsa(c->outcipher, key, len, true); + if(!cipher_set_key_from_rsa(c->outcipher, key, len, true)) + return false; if(debug_level >= DEBUG_SCARY_THINGS) { bin2hex(key, hexkey, len); @@ -403,11 +404,10 @@ bool challenge_h(connection_t *c, const char *request) { return false; } - c->allow_request = CHAL_REPLY; - /* Calculate the hash from the challenge we received */ - digest_create(c->indigest, buffer, len, digest); + if(!digest_create(c->indigest, buffer, len, digest)) + return false; /* Convert the hash to a hexadecimal formatted string */ @@ -415,6 +415,8 @@ bool challenge_h(connection_t *c, const char *request) { /* Send the reply */ + c->allow_request = CHAL_REPLY; + return send_request(c, "%d %s", CHAL_REPLY, buffer); } diff --git a/src/protocol_key.c b/src/protocol_key.c index 7f6e1653..af103c62 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -273,8 +273,10 @@ bool send_ans_key(node_t *to) { abort(); randomize(key, keylen); - cipher_set_key(to->incipher, key, false); - digest_set_key(to->indigest, key, keylen); + if(!cipher_set_key(to->incipher, key, false)) + abort(); + if(!digest_set_key(to->indigest, key, keylen)) + abort(); bin2hex(key, key, keylen); @@ -418,8 +420,10 @@ bool ans_key_h(connection_t *c, const char *request) { /* Update our copy of the origin's packet key */ - cipher_set_key(from->outcipher, key, true); - digest_set_key(from->outdigest, key, keylen); + if(!cipher_set_key(from->outcipher, key, true)) + return false; + if(!digest_set_key(from->outdigest, key, keylen)) + return false; from->status.validkey = true; from->sent_seqno = 0; diff --git a/src/sptps.c b/src/sptps.c index 1699b97f..5d0d4562 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -98,7 +98,9 @@ static bool send_record_priv_datagram(sptps_t *s, uint8_t type, const char *data if(s->outstate) { // If first handshake has finished, encrypt and HMAC - cipher_set_counter(s->outcipher, &seqno, sizeof seqno); + if(!cipher_set_counter(s->outcipher, &seqno, sizeof seqno)) + return false; + if(!cipher_counter_xor(s->outcipher, buffer + 6, len + 1UL, buffer + 6)) return false; @@ -490,7 +492,8 @@ static bool sptps_receive_data_datagram(sptps_t *s, const char *data, size_t len // Decrypt. memcpy(&seqno, buffer + 2, 4); - cipher_set_counter(s->incipher, &seqno, sizeof seqno); + if(!cipher_set_counter(s->incipher, &seqno, sizeof seqno)) + return false; if(!cipher_counter_xor(s->incipher, buffer + 6, len - 4, buffer + 6)) return false; -- 2.39.2