mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Stefan Christ <s.christ@phytec.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 2/7] imd: string returned from imd_string_data should be const
Date: Fri, 1 Apr 2016 10:43:52 +0200	[thread overview]
Message-ID: <20160401084352.GB9102@pengutronix.de> (raw)
In-Reply-To: <20160329093406.GA5532@lws-christ>

On Tue, Mar 29, 2016 at 11:34:06AM +0200, Stefan Christ wrote:
> Hi Sascha,
> 
> On Tue, Mar 29, 2016 at 10:50:49AM +0200, Sascha Hauer wrote:
> > imd_string_data() returns the original data, so the string should be
> > const.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> >  common/imd.c | 13 +++++++++----
> >  1 file changed, 9 insertions(+), 4 deletions(-)
> > 
> > diff --git a/common/imd.c b/common/imd.c
> > index acaa23f..9bd1563 100644
> > --- a/common/imd.c
> > +++ b/common/imd.c
> > @@ -193,7 +193,7 @@ static uint32_t imd_name_to_type(const char *name)
> >  	return IMD_TYPE_INVALID;
> >  }
> >  
> > -static char *imd_string_data(struct imd_header *imd, int index)
> > +static const char *imd_string_data(struct imd_header *imd, int index)
> >  {
> >  	int i, total = 0, l = 0;
> >  	int len = imd_read_length(imd);
> > @@ -306,10 +306,15 @@ int imd_command(int argc, char *argv[])
> >  		}
> >  
> >  		if (imd_is_string(type)) {
> > -			if (strno >= 0)
> > -				str = imd_string_data(imd, strno);
> > -			else
> > +			if (strno >= 0) {
> > +				const char *s = imd_string_data(imd, strno);
> > +				if (s)
> > +					str = strdup(s);
> 
> The following code in the function doesn't free the string 'str' correctly. The
> code is
> 
>                         if (strno < 0)
>                                 free(str);

Ok, if I see it correctly str should be freed unconditionally.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2016-04-01  8:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-29  8:50 [PATCH 1/7] imd: use struct imd_header * as argument Sascha Hauer
2016-03-29  8:50 ` [PATCH 2/7] imd: string returned from imd_string_data should be const Sascha Hauer
2016-03-29  9:34   ` Stefan Christ
2016-04-01  8:43     ` Sascha Hauer [this message]
2016-03-29  8:50 ` [PATCH 3/7] scripts: Add scripts/include/ to include path for target programs Sascha Hauer
2016-03-29  8:50 ` [PATCH 4/7] imd: rename imd_search_validate to imd_get Sascha Hauer
2016-03-29  8:50 ` [PATCH 5/7] imd: export functions Sascha Hauer
2016-03-29  8:50 ` [PATCH 6/7] imd: Add function to read parameters Sascha Hauer
2016-03-29  8:50 ` [PATCH 7/7] bbu: print and evaluate image Metadata Sascha Hauer
2016-03-29  9:29   ` Stefan Christ
2016-04-01  8:41     ` Sascha Hauer

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=20160401084352.GB9102@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.christ@phytec.de \
    /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