diff mbox

[3/4] btrfs-progs: utils: Fix NULL pointer derefernces in string_is_numerical

Message ID 20161024024335.6770-3-quwenruo@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Qu Wenruo Oct. 24, 2016, 2:43 a.m. UTC
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 mbox

Patch

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')