All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@amd.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Ian Campbell <Ian.Campbell@citrix.com>
Cc: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH 1/2] xl: fix adding configuration parameters over command line
Date: Fri, 10 Sep 2010 16:15:27 +0200	[thread overview]
Message-ID: <4C8A3D7F.8060804@amd.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

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.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>

Regards,
Andre.

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

[-- Attachment #2: xl_fix_cmdline_appending.patch --]
[-- Type: text/x-patch, Size: 2108 bytes --]

commit 1b3e5056e47769b3a58f624ae933a227ab6b8b24
Author: Andre Przywara <andre.przywara@amd.com>
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.
    
    Signed-off-by: Andre Przywara <andre.przywara@amd.com>

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index e7b9d74..f40de2b 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -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) {

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

                 reply	other threads:[~2010-09-10 14:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C8A3D7F.8060804@amd.com \
    --to=andre.przywara@amd.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.