Strange behaviour of 'exit' command

Sascha Hauer s.hauer at pengutronix.de
Thu Jun 13 00:18:45 PDT 2019


Hi Ian,

On Wed, Jun 12, 2019 at 11:42:24AM +0100, Ian Abbott wrote:
> I noticed some strange behaviour in the 'hush' shell when the 'sh' and
> 'exit' commands are used:
> 
> ---------------------------------
> barebox:/ sh
> barebox:/ exit
> t: No such file or directory
> barebox:/ echo $?
> 127
> barebox:/
> ---------------------------------

After some digging:

in common/hush.c get_user_input() we have:

	static char the_command[CONFIG_CBSIZE];

This string is used for user input and is unfortunately shared between
different shell instances. The 't' that is executed is the 't' from
'exit'. Try ' exit' instead and you'll see the shell trying to execute
'it' ;)

the_command should be dynamically allocated, but since in_str is
currently statically allocated there is no place in the code to free
the_command again after usage.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list