Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Jan 28, 2022 15:47 UTC (Fri) by larkey (guest, #104463)Parent article: Handling argc==0 in the kernel
> If the argv array passed to execve() is empty (or the argv pointer is simply NULL), the first pointer in the new program's argv array will be NULL, and the envp array will start immediately thereafter.
POSIX says that argv == NULL isn't allowed:
> The argument argv is an array of character pointers to null-terminated strings. The application shall ensure that the last member of this array is a null pointer.
(https://pubs.opengroup.org/onlinepubs/9699919799.2018edit...)
That's also what the kernel bug (https://bugzilla.kernel.org/show_bug.cgi?id=8408) from years back is about. It is *not* about enforcing argc >= 1 (i.e., argv[0] != NULL).
The patch by Ariadne Conill does *not* address what was reported in the bug, despite claiming so. It enforces that case b) never happens which is a stricter requirement and indeed not required by POSIX, as correctly pointed out by Heikki Kallasjoki and Rich Felker. This is just a recommendation:
> The value in argv[0] should point to a filename string that is
associated with the process [...]
I agree that Linux should not allow argv == NULL, that's definitely against the spec. argv[0] == NULL is a different matter although I think it is a reasonable demand, from a security stand point.
-------
Appendix:
POSIX on shall and should:
> shall
>
> For an implementation that conforms to POSIX.1-2017, describes a feature or behavior that is mandatory. An application can rely on the existence of the feature or behavior.
> should
>
> For an implementation that conforms to POSIX.1-2017, describes a feature or behavior that is recommended but not mandatory. An application should not rely on the existence of the feature or behavior. An application that relies on such a feature or behavior cannot be assured to be portable across conforming implementations.
(https://pubs.opengroup.org/onlinepubs/9699919799.2018edit...)
