From: Ian Campbell <Ian.Campbell@eu.citrix.com>
To: Marek Marczykowski <marmarek@mimuw.edu.pl>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: [PATCH 07 of 10] xl: Fix 'script' param parsing in network-attach
Date: Sat, 4 Jun 2011 09:25:52 +0100 [thread overview]
Message-ID: <1307175952.20673.17.camel@dagon.hellion.org.uk> (raw)
In-Reply-To: <4DE9731B.9090709@mimuw.edu.pl>
On Sat, 2011-06-04 at 00:49 +0100, Marek Marczykowski wrote:
> On 03.06.2011 10:16, Ian Campbell wrote:
> > On Thu, 2011-06-02 at 23:35 +0100, Marek Marczykowski wrote:
> >> # HG changeset patch
> >> # User Marek Marczykowski <marmarek@mimuw.edu.pl>
> >> # Date 1306963105 -7200
> >> # Node ID 6811aa543e69379557ff7391ea3db8a5e7f7dde0
> >> # Parent eb7216a75b7d7a5de93c717401b447545022b582
> >> xl: Fix 'script' param parsing in network-attach
> >>
> >> Fix 'script=' string length
> >>
> >> Signed-off-by: Marek Marczykowski <marmarek@mimuw.edu.pl>
> >>
> >> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> >> --- a/tools/libxl/xl_cmdimpl.c
> >> +++ b/tools/libxl/xl_cmdimpl.c
> >> @@ -4285,9 +4285,9 @@
> >> } else if (!strncmp("ip=", *argv, 3)) {
> >> free(nic.ip);
> >> nic.ip = strdup((*argv) + 3);
> >> - } else if (!strncmp("script=", *argv, 6)) {
> >> + } else if (!strncmp("script=", *argv, 7)) {
> >> free(nic.script);
> >> - nic.script = strdup((*argv) + 6);
> >> + nic.script = strdup((*argv) + 7);
> >
> > Good catch.
> >
> > The pre-existing use of all those
> > strncmp(A, *argv, open-coded-sizeof(A))
> > must be a source of many such errors. A helper function (or macro) is
> > probably the way to go. Do you fancy coding that up?
>
> And the same size must be used in strdup offset...
> Maybe something like this (solving also problem in 06 patch):
> -----------
> #define COMPARE_AND_REPLACE(pattern, dest) \
> } else if (!strncmp(pattern, *argv, sizeof(pattern))) { \
> free(dest); \
> dest = strdup((*argv) + sizeof(pattern));
>
> (...)
> COMPARE_AND_REPLACE("script=", nic.script)
> COMPARE_AND_REPLACE("ip=", nic.ip)
> ---------
> Looks weird because of no semicolon at the end of lines, but should
> works.
Generally you can fix the semi-colon thing by omitting the last one from
the macro itself.
> Unfortunately cannot be used in all places (like one below)...
> What do you think?
How about (untested), requires a local "char *oparg":
static int match_option_size(const char *prefix, size_t len,
char *arg, char **argopt)
{
int rc = strncmp(prefix, argv, len);
if (!rc) *argopt = argv+len;
return !rc
}
#define match_option(_prefix, _arg, _oparg) \
match_option_size((_prefix), (_arg), sizeof((_prefix)), &(_oparg));
static void replace_string(char **str, const char *val)
{
free(*str);\
*str = strdup(val);
}
then you have:
else if (match_option("script=", *argv, oparg))
replace_string(&nic.script, oparg);
else if (match_option("backend=", *argv, oparg)) {
if(libxl_name_to_domid(&ctx, oparg, &val)) {
fprintf(stderr, "Specified backend domain does not exist, defaulting to Dom0\n");
...
}
}
with a bit of macro pasting in match_option you can probably push the
"=" down into the macro so each callsite doesn't need it.
Ian.
>
> >
> > Ian.
> >
> >> } else if (!strncmp("backend=", *argv, 8)) {
> >> if(libxl_name_to_domid(&ctx, ((*argv) + 8), &val)) {
> >> fprintf(stderr, "Specified backend domain does not exist, defaulting to Dom0\n");
>
>
>
next prev parent reply other threads:[~2011-06-04 8:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-02 22:35 [PATCH 00 of 10] A bunch of fixes (and one feature) for libxl Marek Marczykowski
2011-06-02 22:35 ` [PATCH 01 of 10] libxl: Remove frontend and backend devices from xenstore after destroy Marek Marczykowski
2011-06-03 8:03 ` Ian Campbell
2011-06-03 23:30 ` Marek Marczykowski
2011-06-04 6:46 ` Ian Campbell
2011-06-02 22:35 ` [PATCH 02 of 10] libxl: Do not start stubdom when not needed Marek Marczykowski
2011-06-03 8:03 ` Ian Campbell
2011-06-02 22:35 ` [PATCH 03 of 10] libxl: Accept disk name in libxl_devid_to_device_disk Marek Marczykowski
2011-06-03 8:08 ` Ian Campbell
2011-06-02 22:35 ` [PATCH 04 of 10] libxl: Allocate memory for strings in libxl_device_disk Marek Marczykowski
2011-06-03 8:10 ` Ian Campbell
2011-06-02 22:35 ` [PATCH 05 of 10] libxl: Set libxl_device_nic->domid when looking up by devid Marek Marczykowski
2011-06-03 8:11 ` Ian Campbell
2011-06-03 23:24 ` Marek Marczykowski
2011-06-04 6:47 ` Ian Campbell
2011-06-02 22:35 ` [PATCH 06 of 10] xl: Allocate memory for libxl_device_nic string members Marek Marczykowski
2011-06-03 8:13 ` Ian Campbell
2011-06-02 22:35 ` [PATCH 07 of 10] xl: Fix 'script' param parsing in network-attach Marek Marczykowski
2011-06-03 8:16 ` Ian Campbell
2011-06-03 23:49 ` Marek Marczykowski
2011-06-04 8:25 ` Ian Campbell [this message]
2011-06-02 22:35 ` [PATCH 08 of 10] xen.lowlevel.xl: Return None on empty domain name Marek Marczykowski
2011-06-03 8:22 ` Ian Campbell
2011-06-02 22:35 ` [PATCH 09 of 10] libxl: Do not SEGV when no 'removable' disk parameter in xenstore Marek Marczykowski
2011-06-02 22:35 ` [PATCH 10 of 10] libxl: "script:" prefix in block device description to setup vbd by hotplug scripts Marek Marczykowski
2011-06-03 8:24 ` Ian Campbell
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=1307175952.20673.17.camel@dagon.hellion.org.uk \
--to=ian.campbell@eu.citrix.com \
--cc=marmarek@mimuw.edu.pl \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).