Skip to content

Commit

Permalink
jwt-openssl: Check error on EVP_DigestSign()
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Collins <[email protected]>
  • Loading branch information
benmcollins committed Dec 3, 2024
1 parent 0e83b08 commit e0cae65
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions libjwt/jwt-openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,17 @@ int jwt_sign_sha_pem(jwt_t *jwt, char **out, unsigned int *len,
}

/* Get the size of sig first */
EVP_DigestSign(mdctx, NULL, &slen, (const unsigned char *)str, str_len);
if (EVP_DigestSign(mdctx, NULL, &slen, (const unsigned char *)str, str_len) != 1)
SIGN_ERROR(EINVAL);

/* Allocate memory for signature based on returned size */
sig = alloca(slen);
sig = alloca(slen);
if (sig == NULL)
SIGN_ERROR(ENOMEM);

/* Actual signing */
EVP_DigestSign(mdctx, sig, &slen, (const unsigned char *)str, str_len);
if (EVP_DigestSign(mdctx, sig, &slen, (const unsigned char *)str, str_len) != 1)
SIGN_ERROR(EINVAL);

if (type != EVP_PKEY_EC) {
*out = jwt_malloc(slen);
Expand Down

0 comments on commit e0cae65

Please sign in to comment.