|
|
Subscribe / Log in / New account

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

At least FreeBSD runs this fine. They do return -EFAULT though when you do:

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.


to post comments

Handling argc==0 in the kernel

Posted Jan 28, 2022 16:22 UTC (Fri) by larkey (guest, #104463) [Link]

However, FreeBSD has applied a similar patch as proposed by Ariadne 2 days ago:

https://github.com/freebsd/freebsd-src/commit/773fa8cd136...

Copied from OpenBSD, says the commit message.

Handling argc==0 in the kernel

Posted Jan 28, 2022 17:33 UTC (Fri) by ariadne (subscriber, #138312) [Link] (1 responses)

It's about both, Linux turns NULL into {NULL} which is then rejected by the patch.

Handling argc==0 in the kernel

Posted Jan 28, 2022 17:44 UTC (Fri) by larkey (guest, #104463) [Link]

Fair enough :D

But, at least to me, it was kind of confusing at first to see these two mangled.

Handling argc==0 in the kernel

Posted Jan 30, 2022 18:44 UTC (Sun) by anton (subscriber, #25547) [Link] (2 responses)

Linux isn't POSIX conforming, allowing argv == NULL
Can you support this claim with actual POSIX wording?

Handling argc==0 in the kernel

Posted Jan 31, 2022 9:58 UTC (Mon) by larkey (guest, #104463) [Link] (1 responses)

The POSIX standard says:

> 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.

Handling argc==0 in the kernel

Posted Jan 31, 2022 12:35 UTC (Mon) by anton (subscriber, #25547) [Link]

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.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds