[PATCH 2/2] linux: posix_spawn: return EINVAL on argc < 1
Adhemerval Zanella
adhemerval.zanella@linaro.org
Fri Jan 28 17:07:40 GMT 2022
On 28/01/2022 12:26, Cristian Rodríguez wrote:
> This apparently does not do what I wanted..
>
> if (argv[0] == NULL || !strlen(argv[0]))
> {
> errno = EINVAL;
> return errno;
> }
>
> is a better check I think.
>
> On Fri, Jan 28, 2022 at 10:48 AM Cristian Rodríguez
> <crrodriguez@opensuse.org> wrote:
>>
>> posix_spawn allows argc < 1 but the specification says that
>> "The value in argv[0] should point to a filename string.."
>> So there must be at least one non-null argument.
>>
>> Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
>> ---
>> sysdeps/unix/sysv/linux/spawni.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c
>> index 93359c708b..23617c9165 100644
>> --- a/sysdeps/unix/sysv/linux/spawni.c
>> +++ b/sysdeps/unix/sysv/linux/spawni.c
>> @@ -334,6 +334,11 @@ __spawnix (pid_t * pid, const char *file,
>> errno = E2BIG;
>> return errno;
>> }
>> + if (argc < 1)
>> + {
>> + errno = EINVAL;
>> + return errno;
>> + }
>>
>> int prot = (PROT_READ | PROT_WRITE
>> | ((GL (dl_stack_flags) & PF_X) ? PROT_EXEC : 0));
>> --
>> 2.34.1
Since Linux is discussing changing on execve syscall [1], I think it would be
better to the same not only for posix_spawn, but rather to all execve
functions.
And since all ends up calling execve, even posix_spawn, I think it would be
better to:
1. Make posix/execve.c call __execveat.
1.1. It would also allow remove the Hurd implementation 'sysdeps/mach/hurd/execve.c'
2. Add the proper check on generic, Linux, and Hurd implementation execveat.
2.1. Maybe even add __execveat_internal that just issue the syscall and let the
generic wrapper handle the argument parsing.
3. Add a regression test.
I also think returning EINVAL is better than the kernel EFAULT one (it seems that
the last message on thread does settle for that).
[1] https://lore.kernel.org/all/20220126114447.25776-1-ariadne@dereferenced.org/
More information about the Libc-alpha
mailing list