]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
hmac: return error if init fails
authorDaniel Stenberg <daniel@haxx.se>
Wed, 23 Jul 2025 14:50:22 +0000 (16:50 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 23 Jul 2025 21:11:25 +0000 (23:11 +0200)
They can actually happen in OOM situtations.

Reported-by: Philippe Antoine
Closes #18008

lib/hmac.c

index 3af1f292dac22d1d30a19d0cc9d1fe4f9bcab162..5e7dd0df0c2d50a0b14297c1592e17415a23bdcc 100644 (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);