]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
include/internal/hashtable.h: avoid OOB read in ossl_ht_strcase()
authorEugene Syromiatnikov <esyr@openssl.org>
Tue, 23 Jun 2026 08:06:04 +0000 (10:06 +0200)
committerTomas Mraz <tomas@openssl.foundation>
Wed, 24 Jun 2026 13:09:20 +0000 (15:09 +0200)
Avoid accessing src[len] by swapping the check order and bound check
the iterator variable before the access.

Found by cppcheck.

Fixes: cc4ea5e00028 "Introduce new internal hashtable implementation"
Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
MergeDate: Wed Jun 24 13:09:25 2026
(Merged from https://github.com/openssl/openssl/pull/31663)

include/internal/hashtable.h

index 7c4150ba28890bf6a2de905cbf1b3bdc30ead4a5..9aad6530974f3da19dc8eb65092b3871cf030793 100644 (file)
@@ -357,7 +357,7 @@ static ossl_inline ossl_unused void ossl_ht_strcase(HT_KEY *key, char *tgt, cons
     if (key != NULL && key->keysize + len > key->bufsize)
         len = (size_t)(key->bufsize - key->keysize);
 
-    for (i = 0; src[i] != '\0' && i < len; i++)
+    for (i = 0; i < len && src[i] != '\0'; i++)
         tgt[i] = case_adjust & src[i];
 }