[PATCH] posix: Fix return value of system if shell can not be executed [BZ #27053]
Adhemerval Zanella
adhemerval.zanella@linaro.org
Mon Jan 11 14:58:54 GMT 2021
On 11/01/2021 10:50, Florian Weimer wrote:
> * Adhemerval Zanella:
>
>> On 11/01/2021 07:01, Florian Weimer wrote:
>>> * Adhemerval Zanella via Libc-alpha:
>>>
>>>> POSIX states that system returned code for failure to execute the shell
>>>> shall be as if the shell had terminated using _exit(127). This
>>>> behaviour was removed with 5fb7fc96350575.
>>>>
>>>> This issue should not be possible for pclose because if the shell can
>>>> not be executed, popen would not return a valid FILE object. Other
>>>> process execution failures (such as killed by a signal) would be
>>>> returned through waitpid from pclose call.
>>>
>>> Note that execve is not atomic and a late resource allocation failure
>>> will be reported as a termination by a signal (because the previous
>>> process image is gone at that point).
>>
>> But afaiu the failure in shell execution by the posix_spawn will be
>> readily reported since execve would fail. I think any late resource
>> failure allocation would be reported as pipe close (_IO_fileno (fp)).
>>
>> Are you saying that spawn_process in libio/iopopen.c maybe return
>> true even if "sh" can not be executed?
>
> It can report process termination by a signal, whatever that means in
> the context of system.
>
> Because of the non-atomic nature of execve, there is a point where the
> kernel cannot return ENOMEM anymore, and has to send a signal to the
> process to terminate it. Then the system function will have a PID for
> that failed process, yet execve has not succeeded in any meaningful
> sense of the word.
But in this case the issue will be independently whether we use
posix_spawn or fork, right?
More information about the Libc-alpha
mailing list