[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xl: fix adding configuration parameters on command line



# HG changeset patch
# User Andre Przywara <andre.przywara@xxxxxxx>
# Date 1284141448 -3600
# Node ID a9f272d4ab4f121e223b9533b5c9d3489f733597
# Parent  5ad5ba05e3aff5ed78bb225755850d760866b178
xl: fix adding configuration parameters on command line

Since we read the text file as is from the disk, there is no
trailing \0 at the end terminating the C string. Therefore we
must not use strcat to this buffer. Also we need to allocate
space for the trailing zero byte.

Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/xl_cmdimpl.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff -r 5ad5ba05e3af -r a9f272d4ab4f tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Fri Sep 10 18:49:49 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Fri Sep 10 18:57:28 2010 +0100
@@ -1315,22 +1315,20 @@ static int create_domain(struct domain_c
                                        &config_data, &config_len);
         if (ret) { fprintf(stderr, "Failed to read config file: %s: %s\n",
                            config_file, strerror(errno)); return ERROR_FAIL; }
-        if (!restore_file && extra_config
-            && strlen(extra_config)) {
-            if (config_len > INT_MAX - (strlen(extra_config) + 2)) {
+        if (!restore_file && extra_config && strlen(extra_config)) {
+            if (config_len > INT_MAX - (strlen(extra_config) + 2 + 1)) {
                 fprintf(stderr, "Failed to attach extra configration\n");
                 return ERROR_FAIL;
             }
+            /* allocate space for the extra config plus two EOLs plus \0 */
             config_data = realloc(config_data, config_len
-                + strlen(extra_config) + 2);
+                + strlen(extra_config) + 2 + 1);
             if (!config_data) {
                 fprintf(stderr, "Failed to realloc config_data\n");
                 return ERROR_FAIL;
             }
-            strcat(config_data, "\n");
-            strcat(config_data, extra_config);
-            strcat(config_data, "\n");
-            config_len += (strlen(extra_config) + 2);
+            config_len += sprintf(config_data + config_len, "\n%s\n",
+                extra_config);
         }
     } else {
         if (!config_data) {

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.