linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Subject: [PATCH 3/4] btrfs-progs: utils: Fix NULL pointer derefernces in string_is_numerical
Date: Mon, 24 Oct 2016 10:43:34 +0800	[thread overview]
Message-ID: <20161024024335.6770-3-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20161024024335.6770-1-quwenruo@cn.fujitsu.com>

In get_running_kernel_version() function, we directly pass return
pointer from strtok_r() to string_is_numberical().

Return pointer from strok_r() can be NULL, but string_is_numberical()
can't handle it and will cause NULL pointer derefernces.

Fix it by check if it's a NULL pointer first.

Reported-by: David Sterba <dsterba@suse.cz>
Resolves-Coverity-CID: 1374097
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 utils.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/utils.c b/utils.c
index 3f54245..c135ac9 100644
--- a/utils.c
+++ b/utils.c
@@ -4015,6 +4015,8 @@ unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode)
 
 int string_is_numerical(const char *str)
 {
+	if (!str)
+		return 0;
 	if (!(*str >= '0' && *str <= '9'))
 		return 0;
 	while (*str >= '0' && *str <= '9')
-- 
2.10.1




  parent reply	other threads:[~2016-10-24  2:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24  2:43 [PATCH 1/4] btrfs-progs: Fix memory leak in write_raid56_with_parity Qu Wenruo
2016-10-24  2:43 ` [PATCH 2/4] btrfs-progs: fsck: Fix patch allocation check and leak in check_fs_first_inode Qu Wenruo
2016-10-24  2:43 ` Qu Wenruo [this message]
2016-10-24  2:43 ` [PATCH 4/4] btrfs-progs: fsck: Fix NULL pointer dereference for possible memory allocation failure Qu Wenruo
2016-10-24  3:04 ` [PATCH 1/4] btrfs-progs: Fix memory leak in write_raid56_with_parity Qu Wenruo
2016-10-25 14:35 ` David Sterba

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=20161024024335.6770-3-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).