U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>,
	Joao Marcos Costa <jmcosta944@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Andrea della Porta <andrea.porta@suse.com>,
	u-boot@lists.denx.de
Subject: Re: [PATCH v2 1/1] fs/squashfs: avoid illegal free() in sqfs_opendir()
Date: Mon, 14 Apr 2025 15:35:30 +0200	[thread overview]
Message-ID: <e86091c7-3dd2-4cf8-af97-673609dbc79a@bootlin.com> (raw)
In-Reply-To: <20250414131924.86672-1-heinrich.schuchardt@canonical.com>

Hello,

On 4/14/25 15:19, Heinrich Schuchardt wrote:
> * Use calloc() to allocate token_list. This avoids an illegal free if
>    sqfs_tokenize() fails.
> * Do not iterate over token_list if it has not been allocated.
> 
> Addresses-Coverity-ID: 510453:  Null pointer dereferences  (FORWARD_NULL)
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
> v2:
> 	Fix typo in subject line
> ---
>   fs/squashfs/sqfs.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
> index 7c364686f14..2dcdd60f683 100644
> --- a/fs/squashfs/sqfs.c
> +++ b/fs/squashfs/sqfs.c
> @@ -949,7 +949,7 @@ static int sqfs_opendir_nest(const char *filename, struct fs_dir_stream **dirsp)
>   		goto out;
>   	}
>   
> -	token_list = malloc(token_count * sizeof(char *));
> +	token_list = calloc(token_count, sizeof(char *));
>   	if (!token_list) {
>   		ret = -EINVAL;
>   		goto out;
> @@ -987,9 +987,11 @@ static int sqfs_opendir_nest(const char *filename, struct fs_dir_stream **dirsp)
>   	*dirsp = (struct fs_dir_stream *)dirs;
>   
>   out:
> -	for (j = 0; j < token_count; j++)
> -		free(token_list[j]);
> -	free(token_list);
> +	if (token_list) {
> +		for (j = 0; j < token_count; j++)
> +			free(token_list[j]);
> +		free(token_list);
> +	}
>   	free(pos_list);
>   	free(path);
>   	if (ret) {

Reviewed-by: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
-- 
Best regards,
João Marcos Costa

  reply	other threads:[~2025-04-14 21:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14 13:19 [PATCH v2 1/1] fs/squashfs: avoid illegal free() in sqfs_opendir() Heinrich Schuchardt
2025-04-14 13:35 ` Joao Marcos Costa [this message]
2025-04-22 13:58 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e86091c7-3dd2-4cf8-af97-673609dbc79a@bootlin.com \
    --to=joaomarcos.costa@bootlin.com \
    --cc=andrea.porta@suse.com \
    --cc=heinrich.schuchardt@canonical.com \
    --cc=jmcosta944@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox