2 * This file is part of execveat 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.
34 #include <sys/syscall.h>
38 # define FILENAME "test.execveat\nfilename"
39 # define Q_FILENAME "test.execveat\\nfilename"
41 static const char * const argv[] = {
42 FILENAME, "first", "second", (const char *) -1L,
43 (const char *) -2L, (const char *) -3L
45 static const char * const q_argv[] = {
46 Q_FILENAME, "first", "second"
49 static const char * const envp[] = {
50 "foobar=1", "foo\nbar=2", (const char *) -1L,
51 (const char *) -2L, (const char *) -3L
53 static const char * const q_envp[] = {
54 "foobar=1", "foo\\nbar=2"
60 const char ** const tail_argv = tail_memdup(argv, sizeof(argv));
61 const char ** const tail_envp = tail_memdup(envp, sizeof(envp));
63 syscall(__NR_execveat, -100, FILENAME, tail_argv, tail_envp, 0x1100);
64 printf("execveat(AT_FDCWD, \"%s\""
65 ", [\"%s\", \"%s\", \"%s\", %p, %p, %p, ???]"
66 #ifdef VERBOSE_EXECVEAT
67 ", [\"%s\", \"%s\", %p, %p, %p, ???]"
69 ", [/* 5 vars, unterminated */]"
71 ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
72 Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
73 argv[3], argv[4], argv[5],
74 #ifdef VERBOSE_EXECVEAT
75 q_envp[0], q_envp[1], envp[2], envp[3], envp[4],
77 errno == ENOSYS ? "ENOSYS" : "ENOENT");
79 tail_argv[ARRAY_SIZE(q_argv)] = NULL;
80 tail_envp[ARRAY_SIZE(q_envp)] = NULL;
82 syscall(__NR_execveat, -100, FILENAME, tail_argv, tail_envp, 0x1100);
83 printf("execveat(AT_FDCWD, \"%s\", [\"%s\", \"%s\", \"%s\"]"
84 #ifdef VERBOSE_EXECVEAT
89 ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
90 Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
91 #ifdef VERBOSE_EXECVEAT
94 errno == ENOSYS ? "ENOSYS" : "ENOENT");
96 syscall(__NR_execveat, -100, FILENAME, tail_argv + 2, tail_envp + 1, 0x1100);
97 printf("execveat(AT_FDCWD, \"%s\", [\"%s\"]"
98 #ifdef VERBOSE_EXECVEAT
103 ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
104 Q_FILENAME, q_argv[2],
105 #ifdef VERBOSE_EXECVEAT
108 errno == ENOSYS ? "ENOSYS" : "ENOENT");
110 const char **const empty = tail_alloc(sizeof(*empty));
113 syscall(__NR_execveat, -100, FILENAME, empty, empty, 0x1100);
114 printf("execveat(AT_FDCWD, \"%s\", []"
115 #ifdef VERBOSE_EXECVEAT
120 ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
121 Q_FILENAME, errno == ENOSYS ? "ENOSYS" : "ENOENT");
123 char str_a[] = "012345678901234567890123456789012";
124 char str_b[] = "_abcdefghijklmnopqrstuvwxyz()[]{}";
125 #define DEFAULT_STRLEN ((unsigned int) sizeof(str_a) - 2)
126 char **const a = tail_alloc(sizeof(*a) * (DEFAULT_STRLEN + 2));
127 char **const b = tail_alloc(sizeof(*b) * (DEFAULT_STRLEN + 2));
129 for (i = 0; i <= DEFAULT_STRLEN; ++i) {
135 syscall(__NR_execveat, -100, FILENAME, a, b, 0x1100);
136 printf("execveat(AT_FDCWD, \"%s\", [\"%.*s\"...", Q_FILENAME, DEFAULT_STRLEN, a[0]);
137 for (i = 1; i < DEFAULT_STRLEN; ++i)
138 printf(", \"%s\"", a[i]);
139 #ifdef VERBOSE_EXECVEAT
140 printf(", \"%s\"", a[i]);
144 #ifdef VERBOSE_EXECVEAT
145 printf("], [\"%.*s\"...", DEFAULT_STRLEN, b[0]);
146 for (i = 1; i <= DEFAULT_STRLEN; ++i)
147 printf(", \"%s\"", b[i]);
149 printf("], [/* %u vars */", DEFAULT_STRLEN + 1);
151 printf("], AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
152 errno == ENOSYS ? "ENOSYS" : "ENOENT");
154 syscall(__NR_execveat, -100, FILENAME, a + 1, b + 1, 0x1100);
155 printf("execveat(AT_FDCWD, \"%s\", [\"%s\"", Q_FILENAME, a[1]);
156 for (i = 2; i <= DEFAULT_STRLEN; ++i)
157 printf(", \"%s\"", a[i]);
158 #ifdef VERBOSE_EXECVEAT
159 printf("], [\"%s\"", b[1]);
160 for (i = 2; i <= DEFAULT_STRLEN; ++i)
161 printf(", \"%s\"", b[i]);
163 printf("], [/* %d vars */", DEFAULT_STRLEN);
165 printf("], AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
166 errno == ENOSYS ? "ENOSYS" : "ENOENT");
168 const void * const efault = tail_alloc(0);
170 syscall(__NR_execveat, -100, FILENAME, NULL, efault, 0x1100);
171 printf("execveat(AT_FDCWD, \"%s\", NULL, %p"
172 ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
173 Q_FILENAME, efault, errno == ENOSYS ? "ENOSYS" : "ENOENT");
175 syscall(__NR_execveat, -100, FILENAME, efault, NULL, 0x1100);
176 printf("execveat(AT_FDCWD, \"%s\", %p, NULL"
177 ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
178 Q_FILENAME, efault, errno == ENOSYS ? "ENOSYS" : "ENOENT");
180 puts("+++ exited with 0 +++");
186 SKIP_MAIN_UNDEFINED("__NR_execveat")