hmac: return error if init fails

They can actually happen in OOM situtations.

Reported-by: Philippe Antoine
Closes #18008
This commit is contained in:
Daniel Stenberg 2025-07-23 16:50:22 +02:00
parent 24f8442e6a
commit 2714486d89
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -73,7 +73,8 @@ Curl_HMAC_init(const struct HMAC_params *hashparams,
/* If the key is too long, replace it by its hash digest. */
if(keylen > hashparams->maxkeylen) {
hashparams->hinit(ctxt->hashctxt1);
if(hashparams->hinit(ctxt->hashctxt1))
return NULL;
hashparams->hupdate(ctxt->hashctxt1, key, keylen);
hkey = (unsigned char *) ctxt->hashctxt2 + hashparams->ctxtsize;
hashparams->hfinal(hkey, ctxt->hashctxt1);
@ -82,8 +83,9 @@ Curl_HMAC_init(const struct HMAC_params *hashparams,
}
/* Prime the two hash contexts with the modified key. */
hashparams->hinit(ctxt->hashctxt1);
hashparams->hinit(ctxt->hashctxt2);
if(hashparams->hinit(ctxt->hashctxt1) ||
hashparams->hinit(ctxt->hashctxt2))
return NULL;
for(i = 0; i < keylen; i++) {
b = (unsigned char)(*key ^ hmac_ipad);