qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/5] linux-uesr: make exec_path realpath


From: Alex Bennée
Subject: Re: [PATCH 2/5] linux-uesr: make exec_path realpath
Date: Mon, 24 May 2021 11:55:41 +0100
User-agent: mu4e 1.5.13; emacs 28.0.50

YAMAMOTO Takashi <yamamoto@midokura.com> writes:

> Otherwise, it can be easily fooled by the user app using chdir().
>
> Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
> ---
>  linux-user/main.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 4dfc47ad3b..1f9f4e3820 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -55,6 +55,7 @@
>  #endif
>  
>  char *exec_path;
> +char exec_path_store[PATH_MAX];

Is there any point in keeping this as a static path rather than just
allocating it off the heap?

>  
>  int singlestep;
>  static const char *argv0;
> @@ -610,7 +611,10 @@ static int parse_args(int argc, char **argv)
>          exit(EXIT_FAILURE);
>      }
>  
> -    exec_path = argv[optind];
> +    exec_path = realpath(argv[optind], exec_path_store);
> +    if (exec_path == NULL) {
> +        exec_path = argv[optind];
> +    }

  exec_path = realpath(argv[optind], NULL)
  exec_path = exec_path ? exec_path : argv[optind];

what situations would we expect realpath to fail and in those cases is
sticking to argv[optind] safe?

>  
>      return optind;
>  }


-- 
Alex Bennée



reply via email to

[Prev in Thread] Current Thread [Next in Thread]