On Oct 28, 2022, at 11:56 PM, Paul Eggert via tz <tz@iana.org> wrote:
Don’t dump core if argv[0] is NULL, which is allowed on GNU/Linux if the invoker is sufficiently perverse.
Is argc == 0 in that case? On macOS Monterey, at least, this program: #include <unistd.h> #include <stdio.h> #include <string.h> #include <errno.h> int main(void) { char *args[1] = { NULL }; if (execv("./me", args) == -1) { fprintf(stderr, "Exec of ./me failed: %s\n", strerror(errno)); return 2; } // This cannot possibly happen return 0; } can then exec this program: #include <stdio.h> int main(int argc, char **argv) { printf("argc = %d\n", argc); printf("argv[0] = %p\n", argv[0]); return 0; } and the latter will print argc = 0 argv[0] = 0x0 I suspect at least some other UN*Xes behave in the same fashion. Is the first program a sufficiently perverse invoker, in which case I'd expect that argc == 0 will be true of argv[0] == NULL is true, or are you thinking of something even *more* perverse, that gives you a non-zero argc and a null argv[0]?