Tests: fix: unchecked sscanf return value
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 7 Apr 2021 15:49:39 +0000 (11:49 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 7 Apr 2021 15:49:39 +0000 (11:49 -0400)
1407934 Unchecked return value

If the function returns an error value, the error value may be mistaken for a normal value.

In parse_arguments: Value returned from a function is not checked for errors before being used (CWE-252)

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

tests/regression/tools/notification/base_client.c

index 9ba1340cb4d320876f59d53610451fdfe92fffc0..f74657a2aefb2c878d054b23f9d404eac8112b68 100644 (file)
@@ -47,6 +47,7 @@ int handle_condition(
 static
 int parse_arguments(char **argv)
 {
+       int sscanf_ret;
        const char *domain_type_string = NULL;
        const char *buffer_usage_type_string = NULL;
        const char *buffer_usage_threshold_type = NULL;
@@ -100,7 +101,13 @@ int parse_arguments(char **argv)
        }
 
        /* Number of notification to expect */
-       sscanf(nr_expected_notifications_string, "%d", &nr_expected_notifications);
+       sscanf_ret = sscanf(nr_expected_notifications_string, "%d",
+                       &nr_expected_notifications);
+       if (sscanf_ret != 1) {
+               printf("error: Invalid nr_expected_notifications, sscanf returned %d\n",
+                               sscanf_ret);
+               goto error;
+       }
 
        /* Put notify action in a group. */
        if (!strcasecmp("1", use_action_group_value)) {
This page took 0.025269 seconds and 4 git commands to generate.