[U-Boot] [PATCH 1/2] pxe: Fix crash if 'sysboot' is run without args

Previously, a NULL pointer dereference would occur if the 'sysboot' command is executed without any arguments.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi --- common/cmd_pxe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git common/cmd_pxe.c common/cmd_pxe.c index 4cbb2b1..abf0941 100644 --- common/cmd_pxe.c +++ common/cmd_pxe.c @@ -1648,7 +1648,7 @@ static int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
is_pxe = false;
- if (strstr(argv[1], "-p")) { + if (argc > 1 && strstr(argv[1], "-p")) { prompt = 1; argc--; argv++;

Previously, if the menu activated by the 'sysboot' command gets interrupted by a Ctrl-C, the behaviour is as if the menu timeout was reached - i.e. boot the default menu entry. This patch fixes that so a Ctrl-C now terminates the command as the user would expect.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi --- common/menu.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git common/menu.c common/menu.c index e81c074..eda96d6 100644 --- common/menu.c +++ common/menu.c @@ -202,6 +202,9 @@ static inline int menu_interactive_choice(struct menu *m, void **choice) choice_item = menu_item_by_key(m, cbuf); if (!choice_item) printf("%s not found\n", cbuf); + } else if (readret == -1) { + printf("<INTERRUPT>\n"); + return -EINTR; } else { return menu_default_choice(m, choice); }

Hi Tuomas,
On 7 May 2015 at 12:29, Tuomas Tynkkynen tuomas.tynkkynen@iki.fi wrote:
Previously, if the menu activated by the 'sysboot' command gets interrupted by a Ctrl-C, the behaviour is as if the menu timeout was reached - i.e. boot the default menu entry. This patch fixes that so a Ctrl-C now terminates the command as the user would expect.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi
common/menu.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git common/menu.c common/menu.c index e81c074..eda96d6 100644 --- common/menu.c +++ common/menu.c @@ -202,6 +202,9 @@ static inline int menu_interactive_choice(struct menu *m, void **choice) choice_item = menu_item_by_key(m, cbuf); if (!choice_item) printf("%s not found\n", cbuf);
} else if (readret == -1) {
printf("<INTERRUPT>\n");
return -EINTR; } else { return menu_default_choice(m, choice); }
-- 2.4.0
Reviewed-by: Simon Glass sjg@chromium.org
If you feel like doing another patch, you could update the cli_readline_into_buffer() and cread_line() to describe the meaning of the return values (-1 and -2). Even better if you can use -EINTR and -ETIMEDOUT.
Regards, Simon

On Thu, May 07, 2015 at 09:29:19PM +0300, Tuomas Tynkkynen wrote:
Previously, if the menu activated by the 'sysboot' command gets interrupted by a Ctrl-C, the behaviour is as if the menu timeout was reached - i.e. boot the default menu entry. This patch fixes that so a Ctrl-C now terminates the command as the user would expect.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

On 7 May 2015 at 12:29, Tuomas Tynkkynen tuomas.tynkkynen@iki.fi wrote:
Previously, a NULL pointer dereference would occur if the 'sysboot' command is executed without any arguments.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi
common/cmd_pxe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Thu, May 07, 2015 at 09:29:18PM +0300, Tuomas Tynkkynen wrote:
Previously, a NULL pointer dereference would occur if the 'sysboot' command is executed without any arguments.
Signed-off-by: Tuomas Tynkkynen tuomas.tynkkynen@iki.fi Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!
participants (3)
-
Simon Glass
-
Tom Rini
-
Tuomas Tynkkynen