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>
Tue, 11 May 2021 15:22:05 +0000 (11:22 -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: I26e4d324c97833acedab4ebd030d412848dcbfe4

tests/regression/tools/notification/base_client.c

index 70ad763abe51aa1645bfd9c6b2678a75dd6e8b51..851f42ab37541ee39add45614a0f9febf10406c1 100644 (file)
@@ -45,6 +45,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;
@@ -96,7 +97,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;
+       }
 
        return 0;
 error:
This page took 0.026483 seconds and 4 git commands to generate.