lib: rsa: add NULL check for 'algo' in
authorAnton Moryakov <ant.v.moryakov@gmail.com>
Tue, 25 Feb 2025 13:53:27 +0000 (16:53 +0300)
committerTom Rini <trini@konsulko.com>
Thu, 13 Mar 2025 20:23:09 +0000 (14:23 -0600)
- Check return value of fdt_getprop for NULL.
- Return -EFAULT if 'algo' property is missing.
- Prevent NULL pointer dereference in strcmp."

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
lib/rsa/rsa-verify.c

index b74aaf8..4a0418a 100644 (file)
@@ -449,6 +449,11 @@ static int rsa_verify_with_keynode(struct image_sign_info *info,
        }
 
        algo = fdt_getprop(blob, node, "algo", NULL);
+       if (!algo) {
+               debug("%s: Missing 'algo' property\n", __func__);
+               return -EFAULT;
+       }
+
        if (strcmp(info->name, algo)) {
                debug("%s: Wrong algo: have %s, expected %s\n", __func__,
                      info->name, algo);