[LTP] Access02 and use of system() library function

Laurent GONZALEZ ltp@gezedo.com
Mon Mar 20 13:22:33 CET 2017


On 20/03/2017 12:11, Cyril Hrubis wrote:
> Hi!
>> in order to check the actual executable mode of a file, access02 calls system() library function.
>>
>> The test fails when the return value of system() is not 0. Shouldn't the return value being tested only for its sign instead (and even versus -1 only) ?
>>
>> The system() function returns -1 in case of error, and the return value of the command otherwise. Even in the case the command returns non-zero value, its execution is positively checked, but access02 fails because the return value is not 0.
>>
>> This corner case happens when the shell is busybox's hush. Hush uses execvp to execute the test_file3, this leads the kernel to return ENOEXEC (bad exec format). Then execvp tries to execute the shell "/bin/sh" with the name of the file "./test_file3" as argv[0]. Then busybox returns that no such an applet does exist, and terminates with error code 127.
> What LTP version is this? The access02 test was rewritten some time ago and
> there is no test_file3 since commit:
>
> commit adb3e23d9de5f8ff54d2395112f79f25c36cf598
> Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
> Date:   Wed Jul 20 18:44:39 2016 +0800
>
>     syscalls/access02: reconstruct and convert to new API
>
> Which is included in last to stable releases....
>
You're right, i am using an old version of LTP (20160126).

It does not change my remark anyway, newer test does X_OK test using system() library function. The return value is checked against 0 for success, whereas I suggest that it should check against any positive value, or even against any value but -1.





More information about the ltp mailing list