public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/1] ubifs: avoid possible NULL dereference
Date: Tue, 21 Nov 2017 22:16:40 +0100	[thread overview]
Message-ID: <20171121211640.CE469120302@gemini.denx.de> (raw)
In-Reply-To: <20171121184503.3193-1-xypron.glpk@gmx.de>

Dear Heinrich,

In message <20171121184503.3193-1-xypron.glpk@gmx.de> you wrote:
> If 'file' cannot be allocated due to an out of memory
> situation, do not dereference it.
> 
> When debugging this patch also avoids a misleading message
> "cannot find next direntry, error %d" in case of an out of
> memory situation. It is sufficent to write
> "%s: Error, no memory for malloc!\n" in this case.
> 
> Reported-by: Alex Sadovsky <nable.maininbox@googlemail.com>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  fs/ubifs/ubifs.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
> index 4465523d5f..313dee0579 100644
> --- a/fs/ubifs/ubifs.c
> +++ b/fs/ubifs/ubifs.c
> @@ -403,8 +403,7 @@ static int ubifs_finddir(struct super_block *sb, char *dirname,
>  	dir = kzalloc(sizeof(struct inode), 0);
>  	if (!file || !dentry || !dir) {
>  		printf("%s: Error, no memory for malloc!\n", __func__);
> -		err = -ENOMEM;
> -		goto out;
> +		goto out_nomem;
>  	}
>  
>  	dir->i_sb = sb;
> @@ -424,7 +423,6 @@ static int ubifs_finddir(struct super_block *sb, char *dirname,
>  		err = PTR_ERR(dent);
>  		goto out;
>  	}
> -
>  	file->f_pos = key_hash_flash(c, &dent->key);
>  	file->private_data = dent;
>  
> @@ -463,6 +461,7 @@ out:
>  
>  out_free:
>  	kfree(file->private_data);
> +out_nomem:
>  	free(file);
>  	free(dentry);
>  	free(dir);

Should you not keep the "err = -ENOMEM;" setting?  Otherwise there
is no indivcation that an error happened.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
There are no data that cannot be plotted on a straight  line  if  the
axis are chosen correctly.

  parent reply	other threads:[~2017-11-21 21:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-21 18:45 [U-Boot] [PATCH 1/1] ubifs: avoid possible NULL dereference Heinrich Schuchardt
2017-11-21 20:23 ` Ladislav Michl
2017-11-21 21:29   ` Heinrich Schuchardt
2017-11-21 21:55     ` Ladislav Michl
2017-11-21 21:16 ` Wolfgang Denk [this message]
2017-11-21 21:22   ` Ladislav Michl
2017-11-22  8:09     ` Wolfgang Denk
2017-11-22  8:25       ` Ladislav Michl
2017-11-24  5:59         ` Heiko Schocher
2017-11-21 21:28   ` Heinrich Schuchardt

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=20171121211640.CE469120302@gemini.denx.de \
    --to=wd@denx.de \
    --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