2 * This file is part of execve strace test.
4 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #define FILENAME "test.execve\nfilename"
36 #define Q_FILENAME "test.execve\\nfilename"
38 static const char * const argv[] = {
39 FILENAME, "first", "second", (const char *) -1L,
40 (const char *) -2L, (const char *) -3L
42 static const char * const q_argv[] = {
43 Q_FILENAME, "first", "second"
46 static const char * const envp[] = {
47 "foobar=1", "foo\nbar=2", (const char *) -1L,
48 (const char *) -2L, (const char *) -3L
50 static const char * const q_envp[] = {
51 "foobar=1", "foo\\nbar=2"
57 char ** const tail_argv = tail_memdup(argv, sizeof(argv));
58 char ** const tail_envp = tail_memdup(envp, sizeof(envp));
60 execve(FILENAME, tail_argv, tail_envp);
61 printf("execve(\"%s\""
62 ", [\"%s\", \"%s\", \"%s\", %p, %p, %p, ???]"
64 ", [\"%s\", \"%s\", %p, %p, %p, ???]"
66 ", [/* 5 vars, unterminated */]"
69 Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
70 argv[3], argv[4], argv[5],
72 q_envp[0], q_envp[1], envp[2], envp[3], envp[4],
74 errno == ENOSYS ? "ENOSYS" : "ENOENT");
76 tail_argv[ARRAY_SIZE(q_argv)] = NULL;
77 tail_envp[ARRAY_SIZE(q_envp)] = NULL;
79 execve(FILENAME, tail_argv, tail_envp);
80 printf("execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
87 Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
91 errno == ENOSYS ? "ENOSYS" : "ENOENT");
93 execve(FILENAME, tail_argv + 2, tail_envp + 1);
94 printf("execve(\"%s\", [\"%s\"]"
101 Q_FILENAME, q_argv[2],
102 #ifdef VERBOSE_EXECVE
105 errno == ENOSYS ? "ENOSYS" : "ENOENT");
107 char **const empty = tail_alloc(sizeof(*empty));
110 execve(FILENAME, empty, empty);
111 printf("execve(\"%s\", []"
112 #ifdef VERBOSE_EXECVE
118 Q_FILENAME, errno == ENOSYS ? "ENOSYS" : "ENOENT");
120 char str_a[] = "012345678901234567890123456789012";
121 char str_b[] = "_abcdefghijklmnopqrstuvwxyz()[]{}";
122 #define DEFAULT_STRLEN ((unsigned int) sizeof(str_a) - 2)
123 char **const a = tail_alloc(sizeof(*a) * (DEFAULT_STRLEN + 2));
124 char **const b = tail_alloc(sizeof(*b) * (DEFAULT_STRLEN + 2));
126 for (i = 0; i <= DEFAULT_STRLEN; ++i) {
132 execve(FILENAME, a, b);
133 printf("execve(\"%s\", [\"%.*s\"...", Q_FILENAME, DEFAULT_STRLEN, a[0]);
134 for (i = 1; i < DEFAULT_STRLEN; ++i)
135 printf(", \"%s\"", a[i]);
136 #ifdef VERBOSE_EXECVE
137 printf(", \"%s\"", a[i]);
141 #ifdef VERBOSE_EXECVE
142 printf("], [\"%.*s\"...", DEFAULT_STRLEN, b[0]);
143 for (i = 1; i <= DEFAULT_STRLEN; ++i)
144 printf(", \"%s\"", b[i]);
146 printf("], [/* %u vars */", DEFAULT_STRLEN + 1);
148 printf("]) = -1 %s (%m)\n", errno == ENOSYS ? "ENOSYS" : "ENOENT");
150 execve(FILENAME, a + 1, b + 1);
151 printf("execve(\"%s\", [\"%s\"", Q_FILENAME, a[1]);
152 for (i = 2; i <= DEFAULT_STRLEN; ++i)
153 printf(", \"%s\"", a[i]);
154 #ifdef VERBOSE_EXECVE
155 printf("], [\"%s\"", b[1]);
156 for (i = 2; i <= DEFAULT_STRLEN; ++i)
157 printf(", \"%s\"", b[i]);
159 printf("], [/* %d vars */", DEFAULT_STRLEN);
161 printf("]) = -1 %s (%m)\n", errno == ENOSYS ? "ENOSYS" : "ENOENT");
163 const void * const efault = tail_alloc(0);
165 execve(FILENAME, (char **) tail_argv[ARRAY_SIZE(q_argv)], efault);
166 printf("execve(\"%s\", NULL, %p"
168 Q_FILENAME, efault, errno == ENOSYS ? "ENOSYS" : "ENOENT");
170 execve(FILENAME, efault, NULL);
171 printf("execve(\"%s\", %p, NULL"
173 Q_FILENAME, efault, errno == ENOSYS ? "ENOSYS" : "ENOENT");