[libfko] bug fix to check strdup() return value
Using the 'fiu-run' fault injection binary, a couple of cases were turned up with libfko does not properly check the strdup() return value. This commit fixes these issues, and here is an illustration of the stack trace for one such issue: Core was generated by `../client/.libs/fwknop -A tcp/22 -a 127.0.0.2 -D 127.0.0.1 --get-key local_spa.'. Program terminated with signal 11, Segmentation fault. #0 __strnlen_sse2 () at ../sysdeps/x86_64/multiarch/../strnlen.S:34 34 ../sysdeps/x86_64/multiarch/../strnlen.S: No such file or directory. (gdb) where #0 __strnlen_sse2 () at ../sysdeps/x86_64/multiarch/../strnlen.S:34 #1 0x00007effa38189bc in _rijndael_encrypt (enc_key_len=<optimized out>, enc_key=<optimized out>, ctx=0x7effa5945750) at fko_encryption.c:141 #2 fko_encrypt_spa_data (ctx=0x7effa5945750, enc_key=<optimized out>, enc_key_len=<optimized out>) at fko_encryption.c:605 #3 0x00007effa381a2d6 in fko_spa_data_final (ctx=0x7effa5945750, enc_key=enc_key@entry=0x7fff3ff4aa10 "fwknoptest", enc_key_len=<optimized out>, hmac_key=hmac_key@entry=0x7fff3ff4aaa0 "", hmac_key_len=0) at fko_funcs.c:489 #4 0x00007effa405f2fb in main (argc=<optimized out>, argv=<optimized out>) at fwknop.c:449
This commit is contained in:
parent
989d48b7e9
commit
ffde9c3f1a
@ -131,8 +131,7 @@ _rijndael_encrypt(fko_ctx_t ctx, const char *enc_key, const int enc_key_len)
|
||||
zero_free_rv = zero_free(ctx->encrypted_msg,
|
||||
strnlen(ctx->encrypted_msg, MAX_SPA_ENCODED_MSG_SIZE));
|
||||
|
||||
ctx->encrypted_msg = strdup(b64ciphertext);
|
||||
ctx->encrypted_msg_len = strnlen(ctx->encrypted_msg, MAX_SPA_ENCODED_MSG_SIZE);
|
||||
ctx->encrypted_msg = strdup(b64ciphertext);
|
||||
|
||||
/* Clean-up
|
||||
*/
|
||||
@ -149,6 +148,8 @@ _rijndael_encrypt(fko_ctx_t ctx, const char *enc_key, const int enc_key_len)
|
||||
if(ctx->encrypted_msg == NULL)
|
||||
return(FKO_ERROR_MEMORY_ALLOCATION);
|
||||
|
||||
ctx->encrypted_msg_len = strnlen(ctx->encrypted_msg, MAX_SPA_ENCODED_MSG_SIZE);
|
||||
|
||||
if(! is_valid_encoded_msg_len(ctx->encrypted_msg_len))
|
||||
return(FKO_ERROR_INVALID_DATA_ENCRYPT_RESULT_MSGLEN_VALIDFAIL);
|
||||
|
||||
@ -377,8 +378,7 @@ gpg_encrypt(fko_ctx_t ctx, const char *enc_key)
|
||||
zero_free_rv = zero_free(ctx->encrypted_msg,
|
||||
strnlen(ctx->encrypted_msg, MAX_SPA_ENCODED_MSG_SIZE));
|
||||
|
||||
ctx->encrypted_msg = strdup(b64cipher);
|
||||
ctx->encrypted_msg_len = strnlen(ctx->encrypted_msg, MAX_SPA_ENCODED_MSG_SIZE);
|
||||
ctx->encrypted_msg = strdup(b64cipher);
|
||||
|
||||
/* Clean-up
|
||||
*/
|
||||
@ -395,6 +395,8 @@ gpg_encrypt(fko_ctx_t ctx, const char *enc_key)
|
||||
if(ctx->encrypted_msg == NULL)
|
||||
return(FKO_ERROR_MEMORY_ALLOCATION);
|
||||
|
||||
ctx->encrypted_msg_len = strnlen(ctx->encrypted_msg, MAX_SPA_ENCODED_MSG_SIZE);
|
||||
|
||||
if(! is_valid_encoded_msg_len(ctx->encrypted_msg_len))
|
||||
return(FKO_ERROR_INVALID_DATA_ENCRYPT_GPG_RESULT_MSGLEN_VALIDFAIL);
|
||||
|
||||
|
||||
@ -290,11 +290,15 @@ int fko_set_spa_hmac(fko_ctx_t ctx,
|
||||
if(ctx->msg_hmac != NULL)
|
||||
free(ctx->msg_hmac);
|
||||
|
||||
ctx->msg_hmac = strdup(hmac_base64);
|
||||
ctx->msg_hmac_len = strnlen(ctx->msg_hmac, hmac_digest_str_len);
|
||||
ctx->msg_hmac = strdup(hmac_base64);
|
||||
|
||||
free(hmac_base64);
|
||||
|
||||
if(ctx->msg_hmac == NULL)
|
||||
return(FKO_ERROR_MEMORY_ALLOCATION);
|
||||
|
||||
ctx->msg_hmac_len = strnlen(ctx->msg_hmac, hmac_digest_str_len);
|
||||
|
||||
switch(ctx->msg_hmac_len)
|
||||
{
|
||||
case MD5_B64_LEN:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user