This commit commit fixes a memory leak in the HMAC verification code found with
the test suite running in valgrind mode. Here is the './test-fwknop.pl --diff'
output showing fko_verify_hmac() removed from the flagged functions list:
[+] fwknop functions (unique view):
- 8 : ???
- 3 : main
- 3 : pcap_capture
- 1 : incoming_spa
+ 7 : ???
+ 2 : pcap_capture
+ 2 : main
1 : pcap_compile
- 1 : fko_new_with_data
- 1 : strndup
- 1 : fko_verify_hmac
[+] fwknop functions (with call line numbers):
- 8 : ??? (in /usr/lib/x86_64-linux-gnu/libpcap.so.1.1.1)
- 3 : main (fwknopd.c:299)
- 1 : fko_new_with_data (fko_funcs.c:220)
- 1 : pcap_capture (pcap_capture.c:105)
- 1 : incoming_spa (incoming_spa.c:376)
- 1 : strndup (strndup.c:46)
+ 7 : ??? (in /usr/lib/x86_64-linux-gnu/libpcap.so.1.1.1)
+ 2 : main (fwknopd.c:299)
1 : pcap_compile (in /usr/lib/x86_64-linux-gnu/libpcap.so.1.1.1)
- 1 : pcap_capture (pcap_capture.c:226)
1 : pcap_capture (pcap_capture.c:97)
- 1 : fko_verify_hmac (fko_hmac.c:54)
+ 1 : pcap_capture (pcap_capture.c:105)
*/
tbuf = strndup(ctx->encrypted_msg, ctx->encrypted_msg_len - SHA256_B64_LEN);
if(tbuf == NULL)
+ {
+ free(hmac_digest_from_data);
return(FKO_ERROR_MEMORY_ALLOCATION);
+ }
free(ctx->encrypted_msg);
res = add_salted_str(ctx);
if (res != FKO_SUCCESS)
+ {
+ free(hmac_digest_from_data);
return(res);
+ }
/* Calculate the HMAC from the encrypted data and then
* compare
}
}
+ free(hmac_digest_from_data);
return(res);
}