Fix: tests: base notification client: unchecked sscanf return value
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 22 Apr 2021 18:43:02 +0000 (14:43 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 22 Apr 2021 18:43:02 +0000 (14:43 -0400)
CID 1407934 (#2 of 2): Unchecked return value (CHECKED_RETURN)
8. check_return: Calling sscanf without checking return value (as is
done elsewhere 17 out of 19 times).

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ifcef490aa15aea8ae4846553fbc63c596583d274

tests/regression/tools/notification/base_client.c

index eecdb47885a5520d8a502241ab0a21979af652ca..9b6d30b86731cb638d21f37c77d9932ce18a0b7d 100644 (file)
@@ -92,12 +92,24 @@ int parse_arguments(char **argv)
        /* Ratio or bytes ? */
        if (!strcasecmp("bytes", buffer_usage_threshold_type)) {
                is_threshold_ratio = false;
-               sscanf(buffer_usage_threshold_value, "%" SCNu64, &threshold_bytes);
+               sscanf_ret = sscanf(buffer_usage_threshold_value, "%" SCNu64,
+                               &threshold_bytes);
+               if (sscanf_ret != 1) {
+                       printf("error: Invalid buffer usage threshold value bytes (integer), sscanf returned %d\n",
+                                       sscanf_ret);
+                       goto error;
+               }
        }
 
        if (!strcasecmp("ratio", buffer_usage_threshold_type)) {
                is_threshold_ratio = true;
-               sscanf(buffer_usage_threshold_value, "%lf", &threshold_ratio);
+               sscanf_ret = sscanf(buffer_usage_threshold_value, "%lf",
+                               &threshold_ratio);
+               if (sscanf_ret != 1) {
+                       printf("error: Invalid buffer usage threshold value ratio (float), sscanf returned %d\n",
+                                       sscanf_ret);
+                       goto error;
+               }
        }
 
        /* Number of notification to expect */
This page took 0.025856 seconds and 4 git commands to generate.