Skip to contentSkip to conversation

lib: rsa: add NULL check for 'algo' in

PATCH In review Anton Moryakov 2 participants 2 messages Feb 25, 2025 – Mar 13, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: rsa: add NULL check for 'algo' in

- 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.

---
 lib/rsa/rsa-verify.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/rsa/rsa-verify.c +5 -0
index d3b4f71d6b..43166b1f24 100644
@@ -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);
Signature · 1 line
2.30.2
#1 lore raw
Quoted 8 lines · Anton Moryakov

- 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.

[...]

Applied to u-boot/next, thanks!

[1/1] lib: rsa: add NULL check for 'algo' in

      commit: babc6eef2f48970f394816c955a4a7481ce8df80
Signature · 1 line
Tom