anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

Blame SOURCES/9dc0d66-ndctl-fix-static-analysis-report-unchecked-sscanf.patch

bcf6bc
ndctl: fix static analysis report, unchecked sscanf
bcf6bc
bcf6bc
BZ: 
bcf6bc
bcf6bc
commit 9dc0d660414d6da0f1cd89c80c94128b90603aa7
bcf6bc
Author: Dan Williams <dan.j.williams@intel.com>
bcf6bc
Date:   Mon Oct 2 08:59:56 2017 -0700
bcf6bc
bcf6bc
    ndctl: fix static analysis report, unchecked sscanf
bcf6bc
    
bcf6bc
    Static analysis flags some occasions of unchecked sscanf return value.
bcf6bc
    
bcf6bc
    Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
bcf6bc
    Signed-off-by: Dan Williams <dan.j.williams@intel.com>
bcf6bc
bcf6bc
diff --git a/util/json.c b/util/json.c
bcf6bc
index d1ee351..0c92c3b 100644
bcf6bc
--- a/util/json.c
bcf6bc
+++ b/util/json.c
bcf6bc
@@ -374,11 +374,12 @@ static int compare_dimm_number(const void *p1, const void *p2)
bcf6bc
 	const char *dimm2_name = ndctl_dimm_get_devname(dimm2);
bcf6bc
 	int num1, num2;
bcf6bc
 
bcf6bc
-	sscanf(dimm1_name, "nmem%d", &num1;;
bcf6bc
-	sscanf(dimm2_name, "nmem%d", &num2;;
bcf6bc
+	if (sscanf(dimm1_name, "nmem%d", &num1) != 1)
bcf6bc
+		num1 = 0;
bcf6bc
+	if (sscanf(dimm2_name, "nmem%d", &num2) != 1)
bcf6bc
+		num2 = 0;
bcf6bc
 
bcf6bc
 	return num1 - num2;
bcf6bc
-
bcf6bc
 }
bcf6bc
 
bcf6bc
 static struct json_object *badblocks_to_jdimms(struct ndctl_region *region,