Skip to contentSkip to conversation

qga: fix leak of base64 decoded data on command error

PATCH In review Daniel P. Berrangé 2 participants 2 messages Aug 9, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qga: fix leak of base64 decoded data on command error

If the guest command fails to be spawned, then we would leak the decoded base64 input used for the command's stdin feed.

---
 qga/commands.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qga/commands.c +2 -2
index a6491d2cf8..80501e4a73 100644
@@ -402,7 +402,7 @@ GuestExec *qmp_guest_exec(const char *path,
     GIOChannel *in_ch, *out_ch, *err_ch;
     GSpawnFlags flags;
     bool has_output = (has_capture_output && capture_output);
-    uint8_t *input = NULL;
+    g_autofree uint8_t *input = NULL;
     size_t ninput = 0;
 
     arglist.value = (char *)path;
@@ -441,7 +441,7 @@ GuestExec *qmp_guest_exec(const char *path,
     g_child_watch_add(pid, guest_exec_child_watch, gei);
 
     if (has_input_data) {
-        gei->in.data = input;
+        gei->in.data = g_steal_pointer(&input);
         gei->in.size = ninput;
 #ifdef G_OS_WIN32
         in_ch = g_io_channel_win32_new_fd(in_fd);
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Daniel P. Berrangé

If the guest command fails to be spawned, then we would leak the decoded base64 input used for the command's stdin feed.

---

Quoted 30 lines
 qga/commands.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qga/commands.c +2 -3
index a6491d2cf8..80501e4a73 100644
@@ -402,7 +402,7 @@ GuestExec *qmp_guest_exec(const char *path,
     GIOChannel *in_ch, *out_ch, *err_ch;
     GSpawnFlags flags;
     bool has_output = (has_capture_output && capture_output);
-    uint8_t *input = NULL;
+    g_autofree uint8_t *input = NULL;
     size_t ninput = 0;
 
     arglist.value = (char *)path;
@@ -441,7 +441,7 @@ GuestExec *qmp_guest_exec(const char *path,
     g_child_watch_add(pid, guest_exec_child_watch, gei);
 
     if (has_input_data) {
-        gei->in.data = input;
+        gei->in.data = g_steal_pointer(&input);
         gei->in.size = ninput;
 #ifdef G_OS_WIN32
         in_ch = g_io_channel_win32_new_fd(in_fd);
--

2.31.1

Signature · 1 line
Marc-André Lureau