From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] UBIFS: Change ubifsload to not read beyond the requested size
Date: Fri, 29 Oct 2010 22:54:04 +0200 [thread overview]
Message-ID: <20101029205404.71F62BB0AD@gemini.denx.de> (raw)
In-Reply-To: <1288343093-31276-1-git-send-email-sr@denx.de>
Dear Stefan Roese,
In message <1288343093-31276-1-git-send-email-sr@denx.de> you wrote:
> Until now ubifsload pads the destination with 0 up to a multiple of
> UBIFS_BLOCK_SIZE (4KiB) while reading a file to memory. This patch
> changes this behaviour to only read to the requested length. This
> is either the file length or the length/size provided as parameter
> to the ubifsload command.
>
> Signed-off-by: Stefan Roese <sr@denx.de>
> ---
> This patch makes the patch [UBIFS: Add padded size to ubifsload output]
> posted yesterday obsolete since we're not padding any more now.
...
> + /*
> + * We need to buffer the data locally for the
> + * last block. This is to not pad the destination
> + * area to a multiple of UBIFS_BLOCK_SIZE.
> + */
> + buff = malloc(UBIFS_BLOCK_SIZE);
> +
> + /* Read block-siez into temp buffer */
> + ret = read_block(inode, buff, block, dn);
> + if (last_block_size)
> + dlen = last_block_size;
> + else
> + dlen = le32_to_cpu(dn->size);
How about some error handling?
malloc() can fail, and read_block() can fail as well.
> + /* Now copy required size back to dest */
> + memcpy(addr, buff, dlen);
> +
> + free(buff);
> + } else {
> + ret = read_block(inode, addr, block, dn);
> + if (ret) {
> + err = ret;
> + if (err != -ENOENT)
> + break;
or simpler:
ret = read_block(inode, addr, block, dn);
if (ret != -ENOENT) {
err = ret;
break;
}
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"I used to think that the brain was the most wonderful organ in my
body. Then I realized who was telling me this." - Emo Phillips
next prev parent reply other threads:[~2010-10-29 20:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-29 9:04 [U-Boot] [PATCH] UBIFS: Change ubifsload to not read beyond the requested size Stefan Roese
2010-10-29 14:01 ` Ben Gardiner
2010-11-01 15:47 ` Stefan Roese
2010-10-29 20:54 ` Wolfgang Denk [this message]
2010-11-01 13:06 ` Stefan Roese
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=20101029205404.71F62BB0AD@gemini.denx.de \
--to=wd@denx.de \
--cc=u-boot@lists.denx.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 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.