Blame SOURCES/0010-covscan-initialize-argv-s-copy.patch

0985ad
From c1a2ef0efed557a3c7808e491a6b2638666ecd9e Mon Sep 17 00:00:00 2001
0985ad
From: Victor Toso <me@victortoso.com>
0985ad
Date: Mon, 26 Aug 2019 17:03:22 +0200
0985ad
Subject: [PATCH 10/11] covscan: initialize argv's copy
0985ad
0985ad
Otherwise we get a CLANG_WARNING due accessing garbage.
0985ad
0985ad
Covscan report:
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:471:9: warning: 1st function call argument is an uninitialized value
0985ad
 > #        execvp(orig_argv[0], orig_argv);
0985ad
 > #        ^      ~~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:421:24: note: Storing uninitialized value
0985ad
 > #    char **orig_argv = g_memdup(argv, sizeof(char*) * (argc+1));
0985ad
 > #                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:434:9: note: Assuming 'error' is equal to NULL
0985ad
 > #    if (error != NULL) {
0985ad
 > #        ^~~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:434:5: note: Taking false branch
0985ad
 > #    if (error != NULL) {
0985ad
 > #    ^
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:442:9: note: Assuming 'portdev' is not equal to NULL
0985ad
 > #    if (portdev == NULL)
0985ad
 > #        ^~~~~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:442:5: note: Taking false branch
0985ad
 > #    if (portdev == NULL)
0985ad
 > #    ^
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:445:9: note: Assuming 'vdagentd_socket' is not equal to NULL
0985ad
 > #    if (vdagentd_socket == NULL)
0985ad
 > #        ^~~~~~~~~~~~~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:445:5: note: Taking false branch
0985ad
 > #    if (vdagentd_socket == NULL)
0985ad
 > #    ^
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:448:30: note: Assuming 'do_daemonize' is 0
0985ad
 > #    openlog("spice-vdagent", do_daemonize ? LOG_PID : (LOG_PID | LOG_PERROR),
0985ad
 > #                             ^~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:448:30: note: '?' condition is false
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:451:9: note: Assuming the condition is false
0985ad
 > #    if (!g_file_test(portdev, G_FILE_TEST_EXISTS)) {
0985ad
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:451:5: note: Taking false branch
0985ad
 > #    if (!g_file_test(portdev, G_FILE_TEST_EXISTS)) {
0985ad
 > #    ^
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:457:9: note: Assuming 'do_daemonize' is 0
0985ad
 > #    if (do_daemonize)
0985ad
 > #        ^~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:457:5: note: Taking false branch
0985ad
 > #    if (do_daemonize)
0985ad
 > #    ^
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:468:9: note: Assuming 'version_mismatch' is not equal to 0
0985ad
 > #    if (version_mismatch) {
0985ad
 > #        ^~~~~~~~~~~~~~~~
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:468:5: note: Taking true branch
0985ad
 > #    if (version_mismatch) {
0985ad
 > #    ^
0985ad
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:471:9: note: 1st function call argument is an uninitialized value
0985ad
 > #        execvp(orig_argv[0], orig_argv);
0985ad
 > #        ^      ~~~~~~~~~~~~
0985ad
 > #  469|           syslog(LOG_INFO, "Version mismatch, restarting");
0985ad
 > #  470|           sleep(1);
0985ad
 > #  471|->         execvp(orig_argv[0], orig_argv);
0985ad
 > #  472|       }
0985ad
 > #  473|
0985ad
0985ad
Signed-off-by: Victor Toso <victortoso@redhat.com>
0985ad
---
0985ad
 src/vdagent/vdagent.c | 5 ++++-
0985ad
 1 file changed, 4 insertions(+), 1 deletion(-)
0985ad
0985ad
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
0985ad
index 0e2e73e..5b146db 100644
0985ad
--- a/src/vdagent/vdagent.c
0985ad
+++ b/src/vdagent/vdagent.c
0985ad
@@ -418,7 +418,10 @@ int main(int argc, char *argv[])
0985ad
     GOptionContext *context;
0985ad
     GError *error = NULL;
0985ad
     VDAgent *agent;
0985ad
-    char **orig_argv = g_memdup(argv, sizeof(char*) * (argc+1));
0985ad
+    char **orig_argv;
0985ad
+
0985ad
+    orig_argv = g_memdup(argv, sizeof(char*) * (argc+1));
0985ad
+    orig_argv[argc] = NULL;
0985ad
 
0985ad
     context = g_option_context_new(NULL);
0985ad
     g_option_context_add_main_entries(context, entries, NULL);
0985ad
-- 
0985ad
2.21.0
0985ad