From: Jérémie Galarneau Date: Wed, 7 Apr 2021 15:49:39 +0000 (-0400) Subject: Tests: fix: unchecked sscanf return value X-Git-Tag: v2.13.0-rc1~161 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e062fb0271603bcd8e4fa7f806cad95d69df606f;p=lttng-tools.git Tests: fix: unchecked sscanf return value 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 Change-Id: I7733e88ea6af6313379bd8d4ca131cd243cda401 --- diff --git a/tests/regression/tools/notification/base_client.c b/tests/regression/tools/notification/base_client.c index 9ba1340cb..f74657a2a 100644 --- a/tests/regression/tools/notification/base_client.c +++ b/tests/regression/tools/notification/base_client.c @@ -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)) {