From 9046acaf22650b2c3f71185d8a1201647c431a7b Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Thu, 9 May 2013 21:56:13 -0400 Subject: [PATCH] [libfko] memory leak fixes found by Coverity --- lib/fko_encryption.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/fko_encryption.c b/lib/fko_encryption.c index 51b16adb..0c19e7fb 100644 --- a/lib/fko_encryption.c +++ b/lib/fko_encryption.c @@ -84,10 +84,14 @@ _rijndael_encrypt(fko_ctx_t ctx, const char *enc_key, const int enc_key_len) if(plaintext == NULL) return(FKO_ERROR_MEMORY_ALLOCATION); + pt_len = snprintf(plaintext, pt_len, "%s:%s", ctx->encoded_msg, ctx->digest); if(! is_valid_pt_msg_len(pt_len)) + { + free(plaintext); return(FKO_ERROR_INVALID_DATA); + } /* Make a bucket for the encrypted version and populate it. */ @@ -371,7 +375,10 @@ gpg_decrypt(fko_ctx_t ctx, const char *dec_key) return(FKO_ERROR_MEMORY_ALLOCATION); if((b64_decode_len = b64_decode(ctx->encrypted_msg, cipher)) < 0) + { + free(cipher); return(FKO_ERROR_INVALID_DATA); + } cipher_len = b64_decode_len;