lib: accept larger input to md5/hmac/sha256/sha512 functions

Avoid unchecked data conversions from size_t to unsigned int.

Reported-by: James Fuller
Closes #21174
This commit is contained in:
Daniel Stenberg 2026-03-31 11:22:34 +02:00
parent 1570091f10
commit dd7fcd581f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
7 changed files with 41 additions and 20 deletions

View file

@ -478,14 +478,19 @@ static void my_sha256_final(unsigned char *out, void *ctx)
* Returns CURLE_OK on success.
*/
CURLcode Curl_sha256it(unsigned char *output, const unsigned char *input,
const size_t len)
size_t len)
{
CURLcode result;
my_sha256_ctx ctx;
result = my_sha256_init(&ctx);
if(!result) {
my_sha256_update(&ctx, input, curlx_uztoui(len));
do {
unsigned int ilen = (unsigned int) CURLMIN(len, UINT_MAX);
my_sha256_update(&ctx, input, ilen);
len -= ilen;
input += ilen;
} while(len);
my_sha256_final(output, &ctx);
}
return result;