From f16bb960c998af2df4da7d4135c3e63517f5ea77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Mon, 15 Dec 2014 12:33:43 +0100 Subject: tests: fix NEGATIVE_RETURNS (CWE-394) in tests Error: NEGATIVE_RETURNS (CWE-394): [#def8] NetworkManager-1.1.0/src/tests/test-general-with-expect.c:139: negative_return_fn: Function "fork()" returns a negative number. NetworkManager-1.1.0/src/tests/test-general-with-expect.c:139: var_assign: Assigning: signed variable "pgid" = "fork". NetworkManager-1.1.0/src/tests/test-general-with-expect.c:163: negative_returns: "pgid" is passed to a parameter that cannot be negative. Error: NEGATIVE_RETURNS (CWE-394): [#def9] NetworkManager-1.1.0/src/tests/test-general-with-expect.c:302: negative_returns: A negative constant "-1" is passed as an argument to a parameter that cannot be negative. NetworkManager-1.1.0/src/tests/test-general-with-expect.c:81:2: neg_sink_parm_call: Passing "sig" to "nm_utils_kill_child_async", which cannot accept a negative number. NetworkManager-1.1.0/src/NetworkManagerUtils.c:448:2: neg_sink_parm_call: Passing "sig" to "kill", which cannot accept a negative number. (cherry picked from commit 5252287209f77cd43b5158d4657aea81414069c4) --- src/tests/test-general-with-expect.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index bee266f343..f5010dae4a 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -137,7 +137,10 @@ test_nm_utils_kill_child_create_and_join_pgroup (void) g_assert (err == 0); pgid = fork(); - g_assert (pgid >= 0); + if (pgid < 0) { + g_assert_not_reached (); + return pgid; + } if (pgid == 0) { /* child process... */ @@ -299,6 +302,7 @@ test_nm_utils_kill_child (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*kill child process 'test-a-3-0' (*): unexpected error sending Unexpected signal: Invalid argument (22)"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-3-0' (*): invoke callback: killing child failed"); + /* coverity[negative_returns] */ test_nm_utils_kill_child_async_do ("test-a-3-0", pid3a, -1, 1000 / 2, FALSE, NULL); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-a-3-1' (*): wait for process to terminate after sending SIGTERM (15) (send SIGKILL in 500 milliseconds)..."); -- cgit v1.2.1