All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mkimage: clarify error message for empty input files
@ 2021-08-01 22:23 Thomas Hebb
  2021-08-01 22:25 ` Tom Hebb
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thomas Hebb @ 2021-08-01 22:23 UTC (permalink / raw)
  To: u-boot
  Cc: Thomas Hebb, Alexandru Gagniuc, Joel Stanley, Naoki Hayama,
	Simon Glass, Yann Dirson

Currently, an empty imput file causes `mmap()` to fail, and you get an
error like "mkimage: Can't read file.img: Invalid argument", which is
extremely unintuitive and hard to diagnose if you don't know what to
look for. Add an explicit check for an empty file and provide a clear
error message instead.

We already bounds check the image size when listing and re-signing
existing images, so we only need this check here, when opening data
files going into a image.

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>

---

 tools/mkimage.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/mkimage.c b/tools/mkimage.c
index 302bfcf971..fbe883ce36 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -732,6 +732,12 @@ copy_file (int ifd, const char *datafile, int pad)
 		exit (EXIT_FAILURE);
 	}
 
+	if (sbuf.st_size == 0) {
+		fprintf (stderr, "%s: Input file %s is empty, bailing out\n",
+			params.cmdname, datafile);
+		exit (EXIT_FAILURE);
+	}
+
 	ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0);
 	if (ptr == MAP_FAILED) {
 		fprintf (stderr, "%s: Can't read %s: %s\n",
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mkimage: clarify error message for empty input files
  2021-08-01 22:23 [PATCH] mkimage: clarify error message for empty input files Thomas Hebb
@ 2021-08-01 22:25 ` Tom Hebb
  2021-08-02 19:21 ` Simon Glass
  2021-09-02 13:28 ` Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Hebb @ 2021-08-01 22:25 UTC (permalink / raw)
  To: u-boot; +Cc: Alexandru Gagniuc, Joel Stanley, Naoki Hayama, Simon Glass

On Sun, Aug 1, 2021 at 3:23 PM Thomas Hebb <tommyhebb@gmail.com> wrote:
>
> Currently, an empty imput file causes `mmap()` to fail, and you get an
Whoops, s/imput/input/. Didn't catch this before sending it out.

> error like "mkimage: Can't read file.img: Invalid argument", which is
> extremely unintuitive and hard to diagnose if you don't know what to
> look for. Add an explicit check for an empty file and provide a clear
> error message instead.
>
> We already bounds check the image size when listing and re-signing
> existing images, so we only need this check here, when opening data
> files going into a image.
>
> Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
>
> ---
>
>  tools/mkimage.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/tools/mkimage.c b/tools/mkimage.c
> index 302bfcf971..fbe883ce36 100644
> --- a/tools/mkimage.c
> +++ b/tools/mkimage.c
> @@ -732,6 +732,12 @@ copy_file (int ifd, const char *datafile, int pad)
>                 exit (EXIT_FAILURE);
>         }
>
> +       if (sbuf.st_size == 0) {
> +               fprintf (stderr, "%s: Input file %s is empty, bailing out\n",
> +                       params.cmdname, datafile);
> +               exit (EXIT_FAILURE);
> +       }
> +
>         ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0);
>         if (ptr == MAP_FAILED) {
>                 fprintf (stderr, "%s: Can't read %s: %s\n",
> --
> 2.32.0
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mkimage: clarify error message for empty input files
  2021-08-01 22:23 [PATCH] mkimage: clarify error message for empty input files Thomas Hebb
  2021-08-01 22:25 ` Tom Hebb
@ 2021-08-02 19:21 ` Simon Glass
  2021-09-02 13:28 ` Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Glass @ 2021-08-02 19:21 UTC (permalink / raw)
  To: Thomas Hebb
  Cc: U-Boot Mailing List, Alexandru Gagniuc, Joel Stanley,
	Naoki Hayama, Yann Dirson

On Sun, 1 Aug 2021 at 16:23, Thomas Hebb <tommyhebb@gmail.com> wrote:
>
> Currently, an empty imput file causes `mmap()` to fail, and you get an
> error like "mkimage: Can't read file.img: Invalid argument", which is
> extremely unintuitive and hard to diagnose if you don't know what to
> look for. Add an explicit check for an empty file and provide a clear
> error message instead.
>
> We already bounds check the image size when listing and re-signing
> existing images, so we only need this check here, when opening data
> files going into a image.
>
> Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
>
> ---
>
>  tools/mkimage.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

(s/imput/input/ as you note)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mkimage: clarify error message for empty input files
  2021-08-01 22:23 [PATCH] mkimage: clarify error message for empty input files Thomas Hebb
  2021-08-01 22:25 ` Tom Hebb
  2021-08-02 19:21 ` Simon Glass
@ 2021-09-02 13:28 ` Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2021-09-02 13:28 UTC (permalink / raw)
  To: Thomas Hebb
  Cc: u-boot, Alexandru Gagniuc, Joel Stanley, Naoki Hayama,
	Simon Glass, Yann Dirson

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

On Sun, Aug 01, 2021 at 03:23:13PM -0700, Thomas Hebb wrote:

> Currently, an empty imput file causes `mmap()` to fail, and you get an
> error like "mkimage: Can't read file.img: Invalid argument", which is
> extremely unintuitive and hard to diagnose if you don't know what to
> look for. Add an explicit check for an empty file and provide a clear
> error message instead.
> 
> We already bounds check the image size when listing and re-signing
> existing images, so we only need this check here, when opening data
> files going into a image.
> 
> Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/next, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-02 13:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-01 22:23 [PATCH] mkimage: clarify error message for empty input files Thomas Hebb
2021-08-01 22:25 ` Tom Hebb
2021-08-02 19:21 ` Simon Glass
2021-09-02 13:28 ` Tom Rini

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.