Re: [hackers] [farbfeld] Minor style change in arg.h || Laslo Hunhold

From: Laslo Hunhold <>
Date: Wed, 2 Aug 2017 13:28:48 +0200

On Wed, 2 Aug 2017 12:09:42 +0200
isabella parakiss <> wrote:

Hey Isabella,

> execve("/my/fine/program", NULL, NULL);
> char *empty[] = { NULL };
> execve("/my/fine/program", empty, empty);

very nice catch! This problem is also present in the old arg.h and
I'll push a commit to fix it.

Here is an excerpt from the manpage for some further analysis of your

        On Linux, argv and envp can be specified as NULL. In both
        cases, this has the same effect as specifying the
        argument as a pointer to a list containing a single null
        pointer. Do not take advantage of this nonstandard and
        nonportable misfeature! On many other UNIX systems,
        specifying argv as NULL will result in an error (EFAULT). Some
        other UNIX systems treat the envp==NULL case the same as Linux.

So we can safely just look at the case

        char *empty[] = { NULL };
        execve("/my/fine/program", empty, empty);

as the other one is equivalent (on Linux).

I wrote a small test program which corresponds to "/my/fine/program"
and it reports the following as executed with execve like above:

        pre-argc: 0
        argv0: (null)
        argc: -1
        argv[0]: (null)

The problem is obvious here. It's that we decrement argc even if it is
already 0, which could look up loops which just iterate over argc like

        while (argc--)

Thanks for reporting this!

With best regards


Laslo Hunhold <>
Received on Wed Aug 02 2017 - 13:28:48 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 02 2017 - 13:37:20 CEST