Handling argc==0 in the kernel
Handling argc==0 in the kernel
Posted Jan 28, 2022 16:18 UTC (Fri) by larkey (guest, #104463)In reply to: Handling argc==0 in the kernel by judas_iscariote
Parent article: Handling argc==0 in the kernel
execve("/bin/date", NULL, NULL);
as mentioned in the year-old bug report. But this patch is about
execve("/bin/date", &(char*){NULL}, NULL);
which neither FreeBSD thinks is faulty, nor POSIX requires (i.e., FreeBSD is exactly in line with POSIX here). POSIX however recommends that argv[0] != NULL.
There are two issues here, a) that Linux isn't POSIX conforming, allowing argv == NULL, and b) pkexec relying on argv[0] != NULL which is only a POSIX recommendation. I do think the patch from Ariadne Conill should be applied, but then Linux is decidedly stricter than FreeBSD.
Posted Jan 28, 2022 16:22 UTC (Fri)
by larkey (guest, #104463)
[Link]
https://github.com/freebsd/freebsd-src/commit/773fa8cd136...
Copied from OpenBSD, says the commit message.
Posted Jan 28, 2022 17:33 UTC (Fri)
by ariadne (subscriber, #138312)
[Link] (1 responses)
Posted Jan 28, 2022 17:44 UTC (Fri)
by larkey (guest, #104463)
[Link]
But, at least to me, it was kind of confusing at first to see these two mangled.
Posted Jan 30, 2022 18:44 UTC (Sun)
by anton (subscriber, #25547)
[Link] (2 responses)
Posted Jan 31, 2022 9:58 UTC (Mon)
by larkey (guest, #104463)
[Link] (1 responses)
> 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.
There is nothing in POSIX saying "it may be an array, but it also may be NULL". If a pointer may be NULL in any C function, this is explicitly noted. Compare the standard on strtol(3):
> A pointer to the final string shall be stored in the object pointed to by endptr, provided that endptr is not a null pointer.
(https://pubs.opengroup.org/onlinepubs/9699919799/function...).
This is making it explicit that endptr may be NULL. The nptr argument, however, may not be NULL i.e.,
strtol(NULL, NULL, 10);
is *not* allowed. In the same vain, you can't just make argv be NULL.
Posted Jan 31, 2022 12:35 UTC (Mon)
by anton (subscriber, #25547)
[Link]
Handling argc==0 in the kernel
Handling argc==0 in the kernel
Handling argc==0 in the kernel
Handling argc==0 in the kernel
Linux isn't POSIX conforming, allowing argv == NULL
Can you support this claim with actual POSIX wording?
Handling argc==0 in the kernel
In all of this text I see only requirements on the application, not on the OS. An application must not pass argv=NULL, and POSIX does not define define what the OS shall do if the application is non-conforming in this respect. Linux has a certain behaviour, BSD a different one, both conforming AFAICT.
Handling argc==0 in the kernel