btrfs-progs: utils: Fix NULL pointer derefernces in string_is_numerical
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Mon, 24 Oct 2016 02:43:34 +0000 (10:43 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 23 Nov 2016 09:48:13 +0000 (10:48 +0100)
In get_running_kernel_version() function, we directly pass return
pointer from strtok_r() to string_is_numerical().

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

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

Resolves-Coverity-CID: 1374097
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
utils.c

diff --git a/utils.c b/utils.c
index 9a6ccf7..c883f38 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -4056,6 +4056,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')