]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
tools/xl: Fix trim() following c/s e316316 "xl: Rewrite trim()"
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 16 Jul 2015 19:18:31 +0000 (20:18 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 17 Jul 2015 09:57:20 +0000 (10:57 +0100)
c/s e316316 "xl: Rewrite trim()" uses the wrong indirection of
'output', causing memory corruption for all callers.

Introduce a new local variable, making the code more obviously
correct.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/xl_cmdimpl.c

index 37d4af680d02489c1055dddd3743854caf640083..0cc9f8bee51eeb8c3ce189b297b674129fa41024 100644 (file)
@@ -663,10 +663,12 @@ static void trim(char_predicate_t predicate, const char *input, char **output)
         ;
 
     size_t len_nonnull = after - first;
+    char *result = xmalloc(len_nonnull + 1);
 
-    *output = xmalloc(len_nonnull + 1);
-    memcpy(output, first, len_nonnull);
-    output[len_nonnull] = 0;
+    memcpy(result, first, len_nonnull);
+    result[len_nonnull] = 0;
+
+    *output = result;
 }
 
 static int split_string_into_pair(const char *str,