Commit e9b0f99e8243e3146f3b5f4ef91f4b6c8f4452c0
Committed by
Tom Rini
1 parent
51bdad67cb
Exists in
master
and in
54 other branches
fs: fix do_fsload() handling of optional arguments
Most arguments to the shell command do_fsload() implements are optional. Fix the minimum argc check to respect that. Cater for the situation where argv[2] is not provided. Enhance both do_fsload() and do_ls() to check the maximum number of arguments too. While this check would typically be implemented via U_BOOT_CMD()'s max_args parameter, if these functions are called directly, then that check won't exist. Finally, alter do_ls() to check (argc >= 4) rather than (argc == 4) so that if the function is enhanced to allow extra arguments in the future, this test won't need to be changed at that time. Signed-off-by: Stephen Warren <swarren@nvidia.com> Reviewed-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Showing 1 changed file with 7 additions and 3 deletions Side-by-side Diff
fs/fs.c
... | ... | @@ -258,10 +258,12 @@ |
258 | 258 | int len_read; |
259 | 259 | char buf[12]; |
260 | 260 | |
261 | - if (argc < 5) | |
261 | + if (argc < 2) | |
262 | 262 | return CMD_RET_USAGE; |
263 | + if (argc > 7) | |
264 | + return CMD_RET_USAGE; | |
263 | 265 | |
264 | - if (fs_set_blk_dev(argv[1], argv[2], fstype)) | |
266 | + if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype)) | |
265 | 267 | return 1; |
266 | 268 | |
267 | 269 | if (argc >= 4) { |
268 | 270 | |
... | ... | @@ -308,11 +310,13 @@ |
308 | 310 | { |
309 | 311 | if (argc < 2) |
310 | 312 | return CMD_RET_USAGE; |
313 | + if (argc > 4) | |
314 | + return CMD_RET_USAGE; | |
311 | 315 | |
312 | 316 | if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype)) |
313 | 317 | return 1; |
314 | 318 | |
315 | - if (fs_ls(argc == 4 ? argv[3] : "/")) | |
319 | + if (fs_ls(argc >= 4 ? argv[3] : "/")) | |
316 | 320 | return 1; |
317 | 321 | |
318 | 322 | return 0; |