[libvirt] [PATCH] vshReadlineOptionsPrune: Fix possible leak

Michal Privoznik mprivozn at redhat.com
Fri Jan 12 16:08:42 UTC 2018


The function should prune list of --options so that options
already specified are not offered to user for completion again.
However, if the list of offered options contains a string that
doesn't start with double dash the function returns leaking
partially constructed list. There's not much benefit from trying
to roll back. Just free everything up - our only caller would do
that anyway.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tools/vsh.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 4426c08d6..7db0a16f1 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2798,8 +2798,17 @@ vshReadlineOptionsPrune(char ***list,
         vshCmdOpt *opt =  last->opts;
 
         /* Should never happen (TM) */
-        if (!list_opt)
+        if (!list_opt) {
+            /* But in case it does, we're in a tough situation
+             * because @list[0..i-1] is possibly sparse. That
+             * means if caller were to call virStringListFree
+             * over it some memory is definitely going to be
+             * leaked. The best we can do is to free from list[i]
+             * as our only caller is just fine with it. */
+            virStringListFree(list[i]);
+            virStringListFree(newList);
             return -1;
+        }
 
         while (opt) {
             if (STREQ(opt->def->name, list_opt)) {
-- 
2.13.6




More information about the libvir-list mailing list