diff mbox series

[v2,10/28] fs/squashfs: sqfs_concat_tokens: check if malloc succeeds

Message ID 20201103111126.23600-11-richard.genoud@posteo.net
State Accepted
Commit dc3312c43c82ff9335b2bf4ee4f72365e824adfd
Delegated to: Tom Rini
Headers show
Series fs/squashfs: fix memory leaks and introduce exists() function | expand

Commit Message

Richard Genoud Nov. 3, 2020, 11:11 a.m. UTC
memory allocation should always be checked

Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
---
 fs/squashfs/sqfs.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

João Marcos Costa Nov. 3, 2020, 12:40 p.m. UTC | #1
Reviewed-by Joao Marcos Costa <jmcosta944@gmail.com>

Em ter., 3 de nov. de 2020 às 08:12, Richard Genoud <
richard.genoud@posteo.net> escreveu:

> memory allocation should always be checked
>
> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>
> ---
>  fs/squashfs/sqfs.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
> index 72181f38332..7da2e09cc36 100644
> --- a/fs/squashfs/sqfs.c
> +++ b/fs/squashfs/sqfs.c
> @@ -242,6 +242,9 @@ static char *sqfs_concat_tokens(char **token_list, int
> token_count)
>         length = sqfs_get_tokens_length(token_list, token_count);
>
>         result = malloc(length + 1);
> +       if (!result)
> +               return NULL;
> +
>         result[length] = '\0';
>
>         for (i = 0; i < token_count; i++) {
>
Tom Rini Nov. 20, 2020, 1:37 a.m. UTC | #2
On Tue, Nov 03, 2020 at 12:11:08PM +0100, Richard Genoud wrote:

> memory allocation should always be checked
> 
> Reviewed-by: Joao Marcos Costa <jmcosta944@gmail.com>
> Signed-off-by: Richard Genoud <richard.genoud@posteo.net>

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

Patch

diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index 72181f38332..7da2e09cc36 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -242,6 +242,9 @@  static char *sqfs_concat_tokens(char **token_list, int token_count)
 	length = sqfs_get_tokens_length(token_list, token_count);
 
 	result = malloc(length + 1);
+	if (!result)
+		return NULL;
+
 	result[length] = '\0';
 
 	for (i = 0; i < token_count; i++) {