diff mbox series

autoboot: Add check for result of malloc_cache_aligned()

Message ID 20240229223211.22489-1-maks.mishinFZ@gmail.com
State Accepted
Commit 606867c849b48bf10c16877507480269497e8afd
Delegated to: Tom Rini
Headers show
Series autoboot: Add check for result of malloc_cache_aligned() | expand

Commit Message

Maks Mishin Feb. 29, 2024, 10:32 p.m. UTC
Return value of a function 'malloc_cache_aligned'
is dereferenced at autoboot.c:207 without checking for NULL,
but it is usually checked for this function.

Found by RASU JSC.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 common/autoboot.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Tom Rini March 7, 2024, 5:12 p.m. UTC | #1
On Fri, Mar 01, 2024 at 01:32:11AM +0300, Maks Mishin wrote:

> Return value of a function 'malloc_cache_aligned'
> is dereferenced at autoboot.c:207 without checking for NULL,
> but it is usually checked for this function.
> 
> Found by RASU JSC.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/common/autoboot.c b/common/autoboot.c
index 5d331991c1..6f0aeae6bf 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -167,6 +167,9 @@  static int passwd_abort_sha256(uint64_t etime)
 		sha_env_str = AUTOBOOT_STOP_STR_SHA256;
 
 	presskey = malloc_cache_aligned(DELAY_STOP_STR_MAX_LENGTH);
+	if (!presskey)
+		return -ENOMEM;
+
 	c = strstr(sha_env_str, ":");
 	if (c && (c - sha_env_str < DELAY_STOP_STR_MAX_LENGTH)) {
 		/* preload presskey with salt */