* [musl] execve with null envp
@ 2023-06-09 15:05 Tali Auster
2023-06-09 17:04 ` Rich Felker
0 siblings, 1 reply; 3+ messages in thread
From: Tali Auster @ 2023-06-09 15:05 UTC (permalink / raw)
To: musl
Hello,
Is there any specific behavior specified when NULL is passed for envp in
any of the exec* methods that accept it? I took a quick look at the
source tree, and process/execve.c has a comment suggesting that the
correct behavior may be to use environ for envp before passing the NULL
to the syscall unchanged. My intuition - and, in practice, Linux with
glibc seems to agree - is that a NULL envp means an empty environment. I
imagine the answer to this question may just be a vague shrug, but does
POSIX mandate anything specific here? Or, perhaps a question with a more
clear answer, can my userspace code call execve(pathname, argv, NULL)
and reliably expect the child to have an empty environment?
Hopefully this is on-topic for this list; regardless, thanks for any
help or direction y'all can provide!
Tali Auster
They/Them
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [musl] execve with null envp
2023-06-09 15:05 [musl] execve with null envp Tali Auster
@ 2023-06-09 17:04 ` Rich Felker
2023-06-09 17:40 ` Bobby Bingham
0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2023-06-09 17:04 UTC (permalink / raw)
To: Tali Auster; +Cc: musl
On Fri, Jun 09, 2023 at 09:05:15AM -0600, Tali Auster wrote:
> Hello,
>
> Is there any specific behavior specified when NULL is passed for
> envp in any of the exec* methods that accept it? I took a quick look
> at the source tree, and process/execve.c has a comment suggesting
> that the correct behavior may be to use environ for envp before
> passing the NULL to the syscall unchanged. My intuition - and, in
> practice, Linux with glibc seems to agree - is that a NULL envp
> means an empty environment. I imagine the answer to this question
> may just be a vague shrug, but does POSIX mandate anything specific
> here? Or, perhaps a question with a more clear answer, can my
> userspace code call execve(pathname, argv, NULL) and reliably expect
> the child to have an empty environment?
>
> Hopefully this is on-topic for this list; regardless, thanks for any
> help or direction y'all can provide!
The only specification I'm aware of is:
"The argument envp is an array of character pointers to
null-terminated strings. These strings shall constitute the
environment for the new process image. The envp array is
terminated by a null pointer."
So, if the caller fails to satisfy that part of the interface
contract, the behavior is undefined.
I'm not sure if there's any historical consistency on what happens
here or if any implementations have the behavior the comment suggested
might be "right", but short of research to establish that there's a
reliable behavior and effort to standardize it, I think the clear
solution here is "don't do that". It's easy to just pass (char*[]){0}
instead of a null pointer.
Rich
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [musl] execve with null envp
2023-06-09 17:04 ` Rich Felker
@ 2023-06-09 17:40 ` Bobby Bingham
0 siblings, 0 replies; 3+ messages in thread
From: Bobby Bingham @ 2023-06-09 17:40 UTC (permalink / raw)
To: musl, Rich Felker, Tali Auster
[-- Attachment #1: Type: text/plain, Size: 1976 bytes --]
The Linux manpage explicitly says to not rely on this and that other systems are known to return EFAULT in this case.
https://www.man7.org/linux/man-pages/man2/execve.2.html#NOTES
On June 9, 2023 12:04:04 PM CDT, Rich Felker <dalias@libc.org> wrote:
>On Fri, Jun 09, 2023 at 09:05:15AM -0600, Tali Auster wrote:
>> Hello,
>>
>> Is there any specific behavior specified when NULL is passed for
>> envp in any of the exec* methods that accept it? I took a quick look
>> at the source tree, and process/execve.c has a comment suggesting
>> that the correct behavior may be to use environ for envp before
>> passing the NULL to the syscall unchanged. My intuition - and, in
>> practice, Linux with glibc seems to agree - is that a NULL envp
>> means an empty environment. I imagine the answer to this question
>> may just be a vague shrug, but does POSIX mandate anything specific
>> here? Or, perhaps a question with a more clear answer, can my
>> userspace code call execve(pathname, argv, NULL) and reliably expect
>> the child to have an empty environment?
>>
>> Hopefully this is on-topic for this list; regardless, thanks for any
>> help or direction y'all can provide!
>
>The only specification I'm aware of is:
>
> "The argument envp is an array of character pointers to
> null-terminated strings. These strings shall constitute the
> environment for the new process image. The envp array is
> terminated by a null pointer."
>
>So, if the caller fails to satisfy that part of the interface
>contract, the behavior is undefined.
>
>I'm not sure if there's any historical consistency on what happens
>here or if any implementations have the behavior the comment suggested
>might be "right", but short of research to establish that there's a
>reliable behavior and effort to standardize it, I think the clear
>solution here is "don't do that". It's easy to just pass (char*[]){0}
>instead of a null pointer.
>
>Rich
[-- Attachment #2: Type: text/html, Size: 2551 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-09 17:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09 15:05 [musl] execve with null envp Tali Auster
2023-06-09 17:04 ` Rich Felker
2023-06-09 17:40 ` Bobby Bingham
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).