common: Add NULL checks for malloc_cache_aligned in autoboot.c
authorAnton Moryakov <ant.v.moryakov@gmail.com>
Thu, 6 Feb 2025 21:55:21 +0000 (00:55 +0300)
committerTom Rini <trini@konsulko.com>
Tue, 11 Feb 2025 14:17:23 +0000 (08:17 -0600)
- Check return value of malloc_cache_aligned for presskey and sha.
- Return -ENOMEM if memory allocation fails.
- Free allocated memory in error paths."

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
common/autoboot.c

index 898a57b..0a25449 100644 (file)
@@ -186,10 +186,15 @@ static int passwd_abort_sha256(uint64_t etime)
        ret = hash_parse_string(algo_name, sha_env_str, sha_env);
        if (ret) {
                printf("Hash %s not supported!\n", algo_name);
+               free(presskey);
                return 0;
        }
 
        sha = malloc_cache_aligned(SHA256_SUM_LEN);
+       if (!sha) {
+               free(presskey);
+               return -ENOMEM;
+       }
        size = SHA256_SUM_LEN;
        /*
         * We don't know how long the stop-string is, so we need to