[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: BUG: /proc/self/exe reports relative paths, should always return abs
From: |
Samuel Thibault |
Subject: |
Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths? |
Date: |
Fri, 22 Sep 2017 20:27:17 +0200 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
Hello,
Svante Signell, on ven. 22 sept. 2017 16:24:11 +0200, wrote:
> Final version?
Almost there :)
> -/* Replace the current process, executing FILE_NAME with arguments ARGV and
> - environment ENVP. ARGV and ENVP are terminated by NULL pointers. */
> +/* Replace the current process, executing ABS_NAME, a canonicalized
> + absolute path name of FILE_NAME, with arguments ARGV and
> + environment ENVP. ARGV and ENVP are terminated by NULL
> + pointers. */
> int
> __execve (const char *file_name, char *const argv[], char *const envp[])
> {
> error_t err;
> - file_t file = __file_name_lookup (file_name, O_EXEC, 0);
> + char *cwd = NULL, *concat_name = NULL;
> + const char *abs_name;
>
> + file_t file = __file_name_lookup (file_name, O_EXEC, 0);
This creates a file_t, so return paths have to deallocate it (just like
it is done at the end of the function).
> if (file == MACH_PORT_NULL)
> return -1;
>
> + /* Absolute path */
> + if (file_name[0] == '/')
> + {
> + abs_name = file_name;
> + }
> + /* Relative path */
> + else
> + {
> + cwd = getcwd (NULL, 0);
> + if (cwd == NULL)
Here
> + return -1;
> + int res = asprintf (&concat_name, "%s/%s", cwd, file_name);
> + if (res == -1)
> + {
and there
> + free (cwd);
> + return -1;
> + }
> + abs_name = concat_name;
> + free (cwd);
> + }
Along the way, you could move the declaration f the char *cwd variable
on the cwd = getcwd() line, it'll be just a little bit better :)
Samuel
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, (continued)
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/17
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/18
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/18
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/18
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/20
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/20
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/21
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/21
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/21
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/22
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?,
Samuel Thibault <=
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/24
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/24
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/24
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/25
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/25
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/26
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/26
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/26
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Samuel Thibault, 2017/09/26
- Re: BUG: /proc/self/exe reports relative paths, should always return absolute paths?, Svante Signell, 2017/09/27