Skip to content

Commit

Permalink
Check o_realloc return value
Browse files Browse the repository at this point in the history
  • Loading branch information
babelouest committed Apr 24, 2022
1 parent 8c77bbb commit 0972794
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/jwe.c
Original file line number Diff line number Diff line change
Expand Up @@ -3394,14 +3394,18 @@ int r_jwe_decrypt_payload(jwe_t * jwe) {
o_free(jwe->iv);
if ((jwe->iv = o_malloc(o_strlen((const char *)jwe->iv_b64url))) != NULL) {
if (o_base64url_decode(jwe->iv_b64url, o_strlen((const char *)jwe->iv_b64url), jwe->iv, &jwe->iv_len)) {
jwe->iv = o_realloc(jwe->iv, jwe->iv_len);
if ((payload_enc = o_malloc(o_strlen((const char *)jwe->ciphertext_b64url))) != NULL && (ciphertext = o_malloc(o_strlen((const char *)jwe->ciphertext_b64url))) != NULL) {
if (!o_base64url_decode(jwe->ciphertext_b64url, o_strlen((const char *)jwe->ciphertext_b64url), ciphertext, &ciphertext_len)) {
y_log_message(Y_LOG_LEVEL_ERROR, "r_jwe_decrypt_payload - Error o_base64url_decode ciphertext");
ret = RHN_ERROR;
if ((jwe->iv = o_realloc(jwe->iv, jwe->iv_len)) != NULL) {
if ((payload_enc = o_malloc(o_strlen((const char *)jwe->ciphertext_b64url))) != NULL && (ciphertext = o_malloc(o_strlen((const char *)jwe->ciphertext_b64url))) != NULL) {
if (!o_base64url_decode(jwe->ciphertext_b64url, o_strlen((const char *)jwe->ciphertext_b64url), ciphertext, &ciphertext_len)) {
y_log_message(Y_LOG_LEVEL_ERROR, "r_jwe_decrypt_payload - Error o_base64url_decode ciphertext");
ret = RHN_ERROR;
}
} else {
y_log_message(Y_LOG_LEVEL_ERROR, "r_jwe_decrypt_payload - Error allocating resources for payload_enc or ciphertext");
ret = RHN_ERROR_MEMORY;
}
} else {
y_log_message(Y_LOG_LEVEL_ERROR, "r_jwe_decrypt_payload - Error allocating resources for payload_enc or ciphertext");
y_log_message(Y_LOG_LEVEL_ERROR, "r_jwe_decrypt_payload - Error reallocating resources for iv");
ret = RHN_ERROR_MEMORY;
}
} else {
Expand Down

0 comments on commit 0972794

Please sign in to comment.