Skip to contentSkip to conversation

xl: fix adding configuration parameters over command line

PATCH New Andre Przywara 1 participant 1 message Sep 10, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xl: fix adding configuration parameters over command line

Hi,

since we read the configuration 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.
This is needed to make the command line appending actually work, otherwise I get a parser error due to memory trash.

Regards,
Andre.

Signature · 3 lines
Andre Przywara
AMD-Operating System Research Center (OSRC), Dresden, Germany
Tel: +49 351 448-3567-12

commit 1b3e5056e47769b3a58f624ae933a227ab6b8b24

Author: Andre Przywara <[email protected]>
Date:   Fri Sep 10 14:26:40 2010 +0200

fix adding configuration parameters over 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.

tools/libxl/xl_cmdimpl.c +6 -8
index e7b9d74..f40de2b 100644
@@ -1397,22 +1397,20 @@ static int create_domain(struct domain_create *dom_info)
                                        &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-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel