Hi!
> > Not all systems have /bin/true. It would be better to do:
> >
> > /bin/sh -c ':'
> >
> > etc, as we have code that depends on this type of shell-required POSIX
> > behavior.
> >
> I'm sorry for I cannot figure out how to do this way. I tried, but
> cannot crash unpatched kernel anymore. So I think the simple workaround
> is checking if /bin/true installed in the program:
It should as simple as execve("/bin/sh -c ':'", c, c), or that didn't work?
What about "/bin/sh -c ''" ?
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <sys/resource.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +
> +int main(int argc, char **argv) {
The curly bracked should be on new line here.
> + int i, lc, st;
> + pid_t pid;
> + char *msg;
> + char *c[257];
> + char cc[32*4096];
> + struct rlimit rl = {
> + .rlim_cur = RLIM_INFINITY,
> + .rlim_max = RLIM_INFINITY,
> + };
> +
> + if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
> + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> + for (lc = 0; TEST_LOOPING(lc); lc++) {
> + switch (pid = fork()) {
> + case -1:
> + tst_brkm(TBROK|TERRNO, NULL, "fork");
> + case 0:
> + memset(cc, 'c', 32*4096-1);
Hmm should not the cc actually be C string and so terminated with '\0'?
> + for (i=0;i<256;i++)
> + c[i] = cc;
> + if (setrlimit(RLIMIT_STACK, &rl) == -1)
> + tst_brkm(TBROK|TERRNO, NULL,
> "setrlimit");
> + if (execve("/bin/true", c, c) == -1)
> + tst_brkm(TBROK|TERRNO, NULL, "execve");
> + default:
> + if (waitpid(pid, &st, 0) == -1)
> + tst_brkm(TBROK|TERRNO, NULL, "waitpid");
> +
> + if (! WIFEXITED(st))
> + tst_brkm(TBROK, NULL, "child exits
> abnormally");
Please don't add space after ! here.
> + if (WEXITSTATUS(st) == 2)
> + tst_brkm(TBROK, NULL, "Do you have
> /bin/true installed?");
> +
> + if (WEXITSTATUS(st) != 0)
> + tst_brkm(TBROK, NULL, "chaild exits
> with non-zero value");
> +
> + tst_resm(TPASS, "thp01 pass");
> + }
> + }
> +
> + tst_exit();
> +}
--
Cyril Hrubis
[email protected]
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list