From: Alexander Aring <alex.aring@gmail.com>
To: Jan Weitzel <j.weitzel@phytec.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] ubiformat: get buffer from malloc
Date: Mon, 25 Mar 2013 16:34:08 +0100 [thread overview]
Message-ID: <20130325153406.GB6967@x61s.campuswlan.hs-rm.de> (raw)
In-Reply-To: <20130325153215.GA6967@x61s.campuswlan.hs-rm.de>
On Mon, Mar 25, 2013 at 04:32:15PM +0100, Alexander Aring wrote:
> Hi,
>
> On Mon, Mar 25, 2013 at 04:15:57PM +0100, Jan Weitzel wrote:
> > There was a erase block sized (here 131072) char buf array on the stack.
> > Changed this to get the space from malloc preventing stack overflows.
> > Also fix a wrong return without clean up.
> >
> > Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>
> > ---
> > commands/ubiformat.c | 22 +++++++++++++++-------
> > 1 files changed, 15 insertions(+), 7 deletions(-)
> >
> > diff --git a/commands/ubiformat.c b/commands/ubiformat.c
> > index 47941be..121816f 100644
> > --- a/commands/ubiformat.c
> > +++ b/commands/ubiformat.c
> > @@ -296,13 +296,20 @@ static int mark_bad(const struct mtd_dev_info *mtd, struct ubi_scan_info *si, in
> > static int flash_image(const struct mtd_dev_info *mtd,
> > const struct ubigen_info *ui, struct ubi_scan_info *si)
> > {
> > - int fd, img_ebs, eb, written_ebs = 0, divisor;
> > + int fd, img_ebs, eb, written_ebs = 0, divisor, ret = -1;
> > off_t st_size;
> > + char *buf = NULL;
> >
> > fd = open_file(&st_size);
> > if (fd < 0)
> > return fd;
> >
> > + buf = malloc(mtd->eb_size);
> > + if (!buf) {
> > + sys_errmsg("cannot allocate %d bytes of memory", mtd->eb_size);
> > + goto out_close;
>
> meep, out_close will call free(buf). You need to add a new label above
> free(buf);
>
ah, free is null proofed sry.
Alex
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-03-25 15:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-25 15:15 Jan Weitzel
2013-03-25 15:25 ` Jan Weitzel
2013-03-25 15:32 ` Alexander Aring
2013-03-25 15:34 ` Alexander Aring [this message]
2013-03-27 8:04 ` 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=20130325153406.GB6967@x61s.campuswlan.hs-rm.de \
--to=alex.aring@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=j.weitzel@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