[LTP] [PATCH] syscalls/execve06: Add test for argv[0] = NULL
Cyril Hrubis
chrubis@suse.cz
Tue Jun 14 15:04:20 CEST 2022
Hi!
> I wonder why this does not work:
> .needs_cmds = (const char *[]) {
> "execve06_child",
> NULL
> },
>
> tst_test.c:1526: TINFO: Timeout per run is 0h 00m 30s
> execve06.c:33: TFAIL: Failed to execute execl01_child: ENOENT (2)
> tst_test.c:395: TBROK: Invalid child (23451) exit value 1
The difference is because the test library adds current directory and
test start directory into $PATH before a test is executed, see
add_paths() in the tst_test.c.
The .needs_cmds is for binaries installed on the system in /usr/bin/
etc. so it does not make much sense to call the add_paths() before we
process the array.
> > +
> > + pid = SAFE_FORK();
> > + if (pid == 0) {
> > + execve(path, argv, envp);
> > + tst_brk(TFAIL | TERRNO, "Failed to execute execl01_child");
> > + }
> > +}
> > +
> > +static struct tst_test test = {
> > + .forks_child = 1,
> > + .child_needs_reinit = 1,
> > + .test_all = verify_execve,
> > + .tags = (const struct tst_tag[]) {
> > + {"linux-git", "dcd46d897adb"},
> > + {"CVE", "2021-4034"},
> > + {}
> > + }
> > +};
> > diff --git a/testcases/kernel/syscalls/execve/execve06_child.c b/testcases/kernel/syscalls/execve/execve06_child.c
> > new file mode 100644
> > index 000000000..17280d58a
> > --- /dev/null
> > +++ b/testcases/kernel/syscalls/execve/execve06_child.c
> > @@ -0,0 +1,27 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * Copyright (C) 2022 Cyril Hrubis chrubis@suse.cz
> very nit: <chrubis@suse.cz> (missing < >)
Will fix.
> > + */
> > +
> > +#define TST_NO_DEFAULT_MAIN
> > +#include <stdlib.h>
> > +#include "tst_test.h"
> > +
> > +int main(int argc, char *argv[])
> > +{
> > + tst_reinit();
> > +
> > + if (argc != 1) {
> > + tst_res(TFAIL, "argc is %d, expected 1", argc);
> > + return 0;
> > + }
> > +
> > + if (!argv[0]) {
> > + tst_res(TFAIL, "argv[0] == NULL");
> > + return 0;
> > + }
> > +
> > + tst_res(TPASS, "argv[0] was filled in by kernel");
>
> Testing matches the description from kernel commit.
> Maybe also test for argv[0] being empty string (to make sure behavior does not
> change, although unlikely it'd change)?
It should be safe either way but I decided to be less specific and only
check that something have been added there.
> I tested it on various kernels, works as expected.
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Tested-by: Petr Vorel <pvorel@suse.cz>
I will push it with the added runtest entries and fixed copyright then.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list