Skip to contentSkip to conversation

correct xl cpupool-create with extra parameters

PATCH In review Juergen Gross 2 participants 2 messages Feb 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 correct xl cpupool-create with extra parameters

xl cpupool-create won't take always extra parameters specified on the command line, as a 0-byte is missing at the end of the configuration file contents.

Signed-off-by [email protected]
1 file changed, 6 insertions(+), 7 deletions(-)

tools/libxl/xl_cmdimpl.c | 13 ++++++-------

# HG changeset patch
# User Juergen Gross <[email protected]> # Date 1297675603 -3600
# Node ID 78995dd5b66b193954124bf3ed49931617680cef # Parent 67f2fed570346155d615327f4c1bd1099f155fbd correct xl cpupool-create with extra parameters

xl cpupool-create won't take always extra parameters specified on the command line, as a 0-byte is missing at the end of the configuration file contents.

Signed-off-by [email protected]
tools/libxl/xl_cmdimpl.c +6 -7
diff -r 67f2fed57034 -r 78995dd5b66b tools/libxl/xl_cmdimpl.c
@@ -5204,7 +5204,7 @@ int main_cpupoolcreate(int argc, char **
         {0, 0, 0, 0}
     };
     int ret;
-    void *config_data = 0;
+    char *config_data = 0;
     int config_len = 0;
     XLU_Config *config;
     const char *buf;
@@ -5244,9 +5244,8 @@ int main_cpupoolcreate(int argc, char **
     memset(extra_config, 0, sizeof(extra_config));
     while (optind < argc) {
         if ((p = strchr(argv[optind], '='))) {
-            if (strlen(extra_config) + 1 < sizeof(extra_config)) {
-                if (strlen(extra_config))
-                    strcat(extra_config, "\n");
+            if (strlen(extra_config) + 1 + strlen(argv[optind]) < sizeof(extra_config)) {
+                strcat(extra_config, "\n");
                 strcat(extra_config, argv[optind]);
             }
         } else if (!filename) {
@@ -5263,7 +5262,7 @@ int main_cpupoolcreate(int argc, char **
         return -ERROR_FAIL;
     }
 
-    if (libxl_read_file_contents(&ctx, filename, &config_data, &config_len)) {
+    if (libxl_read_file_contents(&ctx, filename, (void **)&config_data, &config_len)) {
         fprintf(stderr, "Failed to read config file: %s: %s\n",
                 filename, strerror(errno));
         return -ERROR_FAIL;
@@ -5279,10 +5278,10 @@ int main_cpupoolcreate(int argc, char **
             fprintf(stderr, "Failed to realloc config_data\n");
             return -ERROR_FAIL;
         }
-        strcat(config_data, "\n");
+        config_data[config_len] = 0;
         strcat(config_data, extra_config);
         strcat(config_data, "\n");
-        config_len += (strlen(extra_config) + 2);
+        config_len += strlen(extra_config) + 1;
     }
 
     config = xlu_cfg_init(stderr, filename);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Acked-by on v1 1/1
#1 lore raw

Juergen Gross writes ("[Xen-devel] [PATCH] correct xl cpupool-create with extra parameters"):

Quoted 2 lines

xl cpupool-create won't take always extra parameters specified on the command line, as a 0-byte is missing at the end of the configuration file contents.

Thanks, this looks right to me; I have applied it.

Having said that, I think this approach (reallocing the config data buffer and tacking the args on the end) is pretty nasty really. The right thing would be probably call xlu_cfg_read* more than once. Let's not do that now, though.

Ian.