[libfko] free dynamically allocated resources for multiple libfko fcn calls
This commit is contained in:
+24
-1
@@ -98,6 +98,9 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
if (ctx->encoded_msg_len - t_size < 0)
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
|
||||
if(ctx->digest != NULL)
|
||||
free(ctx->digest);
|
||||
|
||||
/* Copy the digest into the context and terminate the encoded data
|
||||
* at that point so the original digest is not part of the
|
||||
* encoded string.
|
||||
@@ -142,7 +145,6 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
case FKO_DIGEST_SHA512:
|
||||
sha512_base64(tbuf, (unsigned char*)ctx->encoded_msg, ctx->encoded_msg_len);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
/* We give up here if the computed digest does not match the
|
||||
@@ -166,6 +168,9 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
}
|
||||
|
||||
if(ctx->rand_val != NULL)
|
||||
free(ctx->rand_val);
|
||||
|
||||
ctx->rand_val = calloc(1, FKO_RAND_VAL_SIZE+1);
|
||||
if(ctx->rand_val == NULL)
|
||||
{
|
||||
@@ -192,6 +197,9 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
|
||||
strlcpy(tbuf, ndx, t_size+1);
|
||||
|
||||
if(ctx->username != NULL)
|
||||
free(ctx->username);
|
||||
|
||||
ctx->username = malloc(t_size+1); /* Yes, more than we need */
|
||||
if(ctx->username == NULL)
|
||||
{
|
||||
@@ -250,6 +258,9 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
}
|
||||
|
||||
if(ctx->version != NULL)
|
||||
free(ctx->version);
|
||||
|
||||
ctx->version = malloc(t_size+1);
|
||||
if(ctx->version == NULL)
|
||||
{
|
||||
@@ -301,6 +312,9 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
|
||||
strlcpy(tbuf, ndx, t_size+1);
|
||||
|
||||
if(ctx->message != NULL)
|
||||
free(ctx->message);
|
||||
|
||||
ctx->message = malloc(t_size+1); /* Yes, more than we need */
|
||||
if(ctx->message == NULL)
|
||||
{
|
||||
@@ -357,6 +371,9 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
|
||||
strlcpy(tbuf, ndx, t_size+1);
|
||||
|
||||
if(ctx->nat_access != NULL)
|
||||
free(ctx->nat_access);
|
||||
|
||||
ctx->nat_access = malloc(t_size+1); /* Yes, more than we need */
|
||||
if(ctx->nat_access == NULL)
|
||||
{
|
||||
@@ -398,6 +415,9 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
{
|
||||
strlcpy(tbuf, ndx, t_size+1);
|
||||
|
||||
if(ctx->server_auth != NULL)
|
||||
free(ctx->server_auth);
|
||||
|
||||
ctx->server_auth = malloc(t_size+1); /* Yes, more than we need */
|
||||
if(ctx->server_auth == NULL)
|
||||
{
|
||||
@@ -442,6 +462,9 @@ fko_decode_spa_data(fko_ctx_t ctx)
|
||||
*/
|
||||
strlcpy(tbuf, ndx, t_size+1);
|
||||
|
||||
if(ctx->server_auth != NULL)
|
||||
free(ctx->server_auth);
|
||||
|
||||
ctx->server_auth = malloc(t_size+1); /* Yes, more than we need */
|
||||
if(ctx->server_auth == NULL)
|
||||
{
|
||||
|
||||
@@ -149,6 +149,9 @@ _rijndael_decrypt(fko_ctx_t ctx,
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
}
|
||||
|
||||
if(ctx->encoded_msg != NULL)
|
||||
free(ctx->encoded_msg);
|
||||
|
||||
/* Create a bucket for the plaintext data and decrypt the message
|
||||
* data into it.
|
||||
*/
|
||||
|
||||
+6
-3
@@ -160,9 +160,6 @@ fko_new(fko_ctx_t *r_ctx)
|
||||
|
||||
FKO_SET_CTX_INITIALIZED(ctx);
|
||||
|
||||
if(r_ctx != NULL)
|
||||
fko_destroy(*r_ctx);
|
||||
|
||||
*r_ctx = ctx;
|
||||
|
||||
return(FKO_SUCCESS);
|
||||
@@ -194,6 +191,9 @@ fko_new_with_data(fko_ctx_t *r_ctx, const char * const enc_msg,
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
}
|
||||
|
||||
if(ctx->encrypted_msg != NULL)
|
||||
free(ctx->encrypted_msg);
|
||||
|
||||
/* First, add the data to the context.
|
||||
*/
|
||||
ctx->encrypted_msg = strdup(enc_msg);
|
||||
@@ -492,6 +492,9 @@ fko_set_spa_data(fko_ctx_t ctx, const char * const enc_msg)
|
||||
if(! is_valid_encoded_msg_len(enc_msg_len))
|
||||
return(FKO_ERROR_INVALID_DATA);
|
||||
|
||||
if(ctx->encrypted_msg != NULL)
|
||||
free(ctx->encrypted_msg);
|
||||
|
||||
/* First, add the data to the context.
|
||||
*/
|
||||
ctx->encrypted_msg = strdup(enc_msg);
|
||||
|
||||
@@ -166,6 +166,9 @@ int fko_calculate_hmac(fko_ctx_t ctx,
|
||||
b64_encode(hmac, hmac_base64, SHA256_DIGEST_LEN);
|
||||
strip_b64_eq(hmac_base64);
|
||||
|
||||
if(ctx->msg_hmac != NULL)
|
||||
free(ctx->msg_hmac);
|
||||
|
||||
ctx->msg_hmac = strdup(hmac_base64);
|
||||
ctx->msg_hmac_len = strnlen(ctx->msg_hmac, SHA512_DIGEST_STR_LEN);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user