All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gianni Tedesco <gianni.tedesco@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Xen Devel <xen-devel@lists.xensource.com>,
	Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Subject: Re: [PATCH]: xl: don't free string literals
Date: Wed, 8 Sep 2010 13:13:10 +0100	[thread overview]
Message-ID: <1283947990.20276.168.camel@qabil.uk.xensource.com> (raw)
In-Reply-To: <19590.32288.472147.509673@mariner.uk.xensource.com>

On Tue, 2010-09-07 at 19:02 +0100, Ian Jackson wrote:
> Gianni Tedesco writes ("[PATCH]: xl: don't free string literals"):
> > The function init_dm_info() is initialising some strings from literals.
> > This is bad juju because when the destructor is called we cannot know if
> > the string literal was overridden with a strdup()'d value. Therefore
> > strdup the initialisers in init_dm_info() and unconditionally free them
> > before assigning non-default values to prevent their leakage.
> 
> Can't we replace the dozen copies of this
> 
> > -        if (!xlu_cfg_get_string (config, "device_model", &buf))
> > +        if (!xlu_cfg_get_string (config, "device_model", &buf)) {
> > +            free(dm_info->device_model);
> >              dm_info->device_model = strdup(buf);
> > +        }
> 
> with something like
> 
> > -        if (!xlu_cfg_get_string (config, "device_model", &buf))
> > +        if (!xlu_cfg_get_string_mallocd (config, "device_model", &buf)) {
> 
> or whatever you want to call the function ?  Or just change the
> definition of xlu_cfg_get_string and declare that it always frees its
> argument if it's not 0 to start with.
> 
> Ian.

Absolutely, I think I'll just change xlu_cfg_get_string() everywhere.
Don't see a need to have two versions of a function and a non-obvious
rule about which to use where. Will hack that up and re-send later.

Gianni

      reply	other threads:[~2010-09-08 12:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-06 12:17 [PATCH]: xl: don't free string literals Gianni Tedesco
2010-09-07 18:02 ` Ian Jackson
2010-09-08 12:13   ` Gianni Tedesco [this message]

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=1283947990.20276.168.camel@qabil.uk.xensource.com \
    --to=gianni.tedesco@citrix.com \
    --cc=Ian.Jackson@eu.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.