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.12.4~26 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7e295ba7ed0cb70a88278683ed359981054a5e5c;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: I26e4d324c97833acedab4ebd030d412848dcbfe4 --- diff --git a/tests/regression/tools/notification/base_client.c b/tests/regression/tools/notification/base_client.c index 70ad763ab..851f42ab3 100644 --- a/tests/regression/tools/notification/base_client.c +++ b/tests/regression/tools/notification/base_client.c @@ -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: