Skip to content

nshlib: guard nsh_getfullpath against NULL argv[1] in boot command - #3705

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Junbo-Zheng:boot
Aug 7, 2026
Merged

nshlib: guard nsh_getfullpath against NULL argv[1] in boot command#3705
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Junbo-Zheng:boot

Conversation

@Junbo-Zheng

Copy link
Copy Markdown
Contributor

Summary

A bare boot (no argument, argc == 1) passes argv[1] == NULL. nsh_getfullpath(NULL) returns strdup(g_home) == "/"

FAR char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl,
FAR const char *relpath)
{
FAR const char *wd;
/* Handle some special cases */
if (!relpath || relpath[0] == '\0')
{
/* No relative path provided */
return strdup(g_home);
}
instead of NULL, which turned the default-boot path (NULL -> board default image) into "/". board_boot_image("/") then failed with -EINVAL (-22), preventing the board from booting.

Guard the nsh_getfullpath() call so NULL passes through unchanged, restoring the original default-boot behavior while still resolving relative paths when an argument is given.

This fixes the regression introduced by the relative-path support

commit fabafbc3615b3d22636bbf33f932578f491bef23 (origin/master, origin/HEAD)
Author: Junbo Zheng <zhengjunbo1@xiaomi.com>
Date:   Fri Jul 24 23:47:44 2026 +0800

    nshlib: add relative image path support in boot command

    cmd_boot passed the image path straight to boardctl(), which resolves
    it in a context that does not inherit the NSH shell cwd, so relative
    paths failed and only absolute paths worked. Use nsh_getfullpath() to
    resolve relative paths against the cwd before calling boardctl().

    Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>

Impact

  • Users: Fixes a regression where bare boot (no image argument) stopped working after the relative-path support boot now works again
  • Build: None -- one-line source change, no con change.
  • Hardware: None -- no board-specific logic touched; affects all boards using NSH boot.
  • Documentation: None.
  • Security & Compatibility: None

Testing

Passed internal CT tests by running boot with no argument

  • before, it returned -EINVAL and no boot occurred
  • after, the default boot path proceeds

Signed-off-by: Junbo Zheng zhengjunbo1@xiaomi.com

A bare `boot` (no argument, argc == 1) passes argv[1] == NULL.
nsh_getfullpath(NULL) returns strdup(g_home) == "/" instead of NULL,
which turned the default-boot path (NULL -> board default image)
into "/".  board_boot_image("/") then failed with -EINVAL (-22),
preventing the board from booting.

Guard the nsh_getfullpath() call so NULL passes through unchanged,
restoring the original default-boot behavior while still resolving
relative paths when an argument is given.

This fixes the regression introduced by the relative-path support
```
commit fabafbc (origin/master, origin/HEAD)
Author: Junbo Zheng <zhengjunbo1@xiaomi.com>
Date:   Fri Jul 24 23:47:44 2026 +0800

    nshlib: add relative image path support in boot command

    cmd_boot passed the image path straight to boardctl(), which resolves
    it in a context that does not inherit the NSH shell cwd, so relative
    paths failed and only absolute paths worked. Use nsh_getfullpath() to
    resolve relative paths against the cwd before calling boardctl().

    Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
```

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
@xiaoxiang781216
xiaoxiang781216 merged commit 145e64a into apache:master Aug 7, 2026
42 checks passed
@Junbo-Zheng
Junbo-Zheng deleted the boot branch August 7, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants