From: Jérémie Galarneau Date: Thu, 22 Apr 2021 18:43:02 +0000 (-0400) Subject: Fix: tests: base notification client: unchecked sscanf return value X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=9d596320136eb060354a686a455ad93639e3861c Fix: tests: base notification client: unchecked sscanf return value 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 Change-Id: Ifcef490aa15aea8ae4846553fbc63c596583d274 --- diff --git a/tests/regression/tools/notification/base_client.c b/tests/regression/tools/notification/base_client.c index eecdb4788..9b6d30b86 100644 --- a/tests/regression/tools/notification/base_client.c +++ b/tests/regression/tools/notification/base_client.c @@ -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 */