mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 2/5] hush: export source_script()
Date: Thu, 12 Nov 2026 09:47:53 +0100	[thread overview]
Message-ID: <e344c1ba-1555-4e90-8df2-47937d5f3554@pengutronix.de> (raw)
In-Reply-To: <20261030-devboot-v1-2-ab9dd3a92c66@pengutronix.de>

On 10/30/26 15:13, Sascha Hauer wrote:
> C code that wants to source a shell script has to go through
> run_command("source ..."), which parses the command line and looks the
> script up in the PATH.
> 
> Export source_script() instead. As the simple parser can't source
> scripts, it gets a stub returning -ENOSYS. Unlike its callers in hush,
> source_script() can now be called directly, so check the security policy
> in it, like run_command() and execute_script() do.
> 
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  common/hush.c   | 17 +++++++++++++++--
>  include/shell.h |  8 ++++++++
>  2 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/common/hush.c b/common/hush.c
> index ac885fbfe7..c5809b32cd 100644
> --- a/common/hush.c
> +++ b/common/hush.c
> @@ -329,7 +329,6 @@ static char **make_list_in(char **inp, char *name);
>  static char *insert_var_value(char *inp);
>  static int set_local_var(const char *s, int flg_export);
>  static int execute_script(const char *path, int argc, char *argv[]);
> -static int source_script(const char *path, int argc, char *argv[]);
>  
>  static int b_check_space(o_string *o, int len)
>  {
> @@ -1975,12 +1974,26 @@ static int execute_script(const char *path, int argc, char *argv[])
>  	return ret;
>  }
>  
> -static int source_script(const char *path, int argc, char *argv[])
> +/**
> + * source_script - execute a shell script in the current environment
> + * @path: path of the script
> + * @argc: number of positional parameters, including $0
> + * @argv: positional parameters, starting with $0
> + *
> + * Unlike executing a script, variables set by it remain set in the current
> + * environment context after it returns.
> + *
> + * Return: exit status of the last command executed, or a negative error code
> + */
> +int source_script(const char *path, int argc, char *argv[])
>  {
>  	struct p_context ctx = {};
>  	char *script;
>  	int ret;
>  
> +	if (!IS_ALLOWED(SCONFIG_SHELL))
> +		return -EPERM;
> +
>  	initialize_context(&ctx, true);
>  
>  	ctx.global_argc = argc;
> diff --git a/include/shell.h b/include/shell.h
> index b399564ff3..a0c3414fa6 100644
> --- a/include/shell.h
> +++ b/include/shell.h
> @@ -6,17 +6,25 @@
>  #ifndef __SHELL_H__
>  #define __SHELL_H__
>  
> +#include <linux/errno.h>
> +
>  int shell_get_last_return_code(void);
>  
>  int run_shell(void);
>  
>  #ifdef CONFIG_SHELL_HUSH
>  char *shell_expand(char *str);
> +int source_script(const char *path, int argc, char *argv[]);
>  #else
>  static inline char *shell_expand(char *str)
>  {
>  	return strdup(str);
>  }
> +
> +static inline int source_script(const char *path, int argc, char *argv[])
> +{
> +	return -ENOSYS;
> +}
>  #endif
>  
>  #ifdef CONFIG_BAREBOX_CMDLINE
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2026-11-12  8:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 14:13 [PATCH 0/5] boot: implement devboot in C Sascha Hauer
2026-10-30 14:13 ` [PATCH 1/5] boot: report the exit status of failing boot scripts Sascha Hauer
2026-11-12  8:50   ` Ahmad Fatoum
2026-10-30 14:13 ` [PATCH 2/5] hush: export source_script() Sascha Hauer
2026-11-12  8:47   ` Ahmad Fatoum [this message]
2026-10-30 14:13 ` [PATCH 3/5] boot: hand overrides on to nested boots and the bootm command Sascha Hauer
2026-11-13  8:52   ` Ahmad Fatoum
2026-10-30 14:13 ` [PATCH 4/5] boot: implement devboot in C Sascha Hauer
2026-11-13  7:51   ` Ahmad Fatoum
2026-11-13  9:48     ` Sascha Hauer
2026-10-30 14:13 ` [PATCH 5/5] sandbox: defconfig: enable boot overrides and devboot Sascha Hauer
2026-11-12  8:48   ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e344c1ba-1555-4e90-8df2-47937d5f3554@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox