[PATCH] dm: Add check for NULL dev_part_str
Sean Anderson
seanga2 at gmail.com
Sat May 15 18:38:34 CEST 2021
> Re: [PATCH] dm: Add check for NULL dev_part_str
This should probably be "part: ..."
On 5/15/21 12:36 PM, Sean Anderson wrote:
> Some callers (e.g. cmd/fs.c) of fs_set_blk_dev may use a NULL dev_part_str.
> While blk_get_device_part_str handles this fine,
> part_get_info_by_dev_and_name does not. This fixes commands crashing when
> implicitly using bootdevice.
>
> Fixes: 7194527b6a ("cmd: fs: Use part_get_info_by_dev_and_name_or_num to parse partitions")
> Reported-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> Signed-off-by: Sean Anderson <seanga2 at gmail.com>
>
> ---
>
> disk/part.c | 6 +++++-
> test/dm/part.c | 2 ++
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/disk/part.c b/disk/part.c
> index 5e7e59cf25..086da84b7f 100644
> --- a/disk/part.c
> +++ b/disk/part.c
> @@ -714,7 +714,11 @@ static int part_get_info_by_dev_and_name(const char *dev_iface,
> int ret;
>
> /* Separate device and partition name specification */
> - part_str = strchr(dev_part_str, '#');
> + if (dev_part_str)
> + part_str = strchr(dev_part_str, '#');
> + else
> + part_str = NULL;
> +
> if (part_str) {
> dup_str = strdup(dev_part_str);
> dup_str[part_str - dev_part_str] = 0;
> diff --git a/test/dm/part.c b/test/dm/part.c
> index 051e9010b6..aff7cfe55f 100644
> --- a/test/dm/part.c
> +++ b/test/dm/part.c
> @@ -46,8 +46,10 @@ static int dm_test_part(struct unit_test_state *uts)
>
> test(-ENODEV, "", true);
> env_set("bootdevice", "0");
> + test(0, NULL, true);
> test(0, "", true);
> env_set("bootdevice", "1");
> + test(1, NULL, false);
> test(1, "", false);
> test(1, "-", false);
> env_set("bootdevice", "");
>
More information about the U-Boot
mailing list