diff mbox

[U-Boot,4/4] cmd/fat: Do not crash on write when <bytes> is not specified

Message ID 8cf29a932c9445f686a97d99dd9b9122@rwthex-w2-b.rwth-ad.de
State Accepted
Commit 454e3d90302d52b619e6df7ebbe716964cee016e
Delegated to: Tom Rini
Headers show

Commit Message

Stefan Brüns Sept. 11, 2016, 8:51 p.m. UTC
argc is checked, but is off by one. In case <bytes> is not specified,
create an empty file, which is identical to the ext4write behaviour.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
---
 cmd/fat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Simon Glass Sept. 19, 2016, 12:57 a.m. UTC | #1
On 11 September 2016 at 14:51, Stefan Brüns
<stefan.bruens@rwth-aachen.de> wrote:
> argc is checked, but is off by one. In case <bytes> is not specified,
> create an empty file, which is identical to the ext4write behaviour.
>
> Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
> ---
>  cmd/fat.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Sept. 23, 2016, 7:55 p.m. UTC | #2
On Sun, Sep 11, 2016 at 10:51:42PM +0200, Stefan Brüns wrote:

> argc is checked, but is off by one. In case <bytes> is not specified,
> create an empty file, which is identical to the ext4write behaviour.
> 
> Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/cmd/fat.c b/cmd/fat.c
index 4e20746..ad1dc2a 100644
--- a/cmd/fat.c
+++ b/cmd/fat.c
@@ -126,7 +126,7 @@  static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
 		return 1;
 	}
 	addr = simple_strtoul(argv[3], NULL, 16);
-	count = simple_strtoul(argv[5], NULL, 16);
+	count = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16);
 
 	buf = map_sysmem(addr, count);
 	ret = file_fat_write(argv[4], buf, 0, count, &size);
@@ -145,7 +145,7 @@  static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
 U_BOOT_CMD(
 	fatwrite,	6,	0,	do_fat_fswrite,
 	"write file into a dos filesystem",
-	"<interface> <dev[:part]> <addr> <filename> <bytes>\n"
+	"<interface> <dev[:part]> <addr> <filename> [<bytes>]\n"
 	"    - write file 'filename' from the address 'addr' in RAM\n"
 	"      to 'dev' on 'interface'"
 );