1 /* Tests various combinations of dfd and pathname for *at syscalls.
2    In particular, dfd should not be checked when pathname is absolute.
3    See https://bugs.kde.org/show_bug.cgi?id=307103 for more information.
4  */
5 
6 #include "config.h"
7 
8 #include <fcntl.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <sys/stat.h>
12 #include <sys/syscall.h>
13 
14 #define DIRECTORY "/tmp/"
15 #define FILENAME "abc123"
16 
17 int main(void)
18 {
19    char buf[1];
20    struct stat stats;
21 
22    int dfd = open(DIRECTORY, O_RDONLY);
23 
24    /* linkat */
25    linkat(dfd, FILENAME, dfd, FILENAME, 0);
26    linkat(0x9879151, DIRECTORY FILENAME, 0x9879152, DIRECTORY FILENAME, 0);
27    linkat(AT_FDCWD, FILENAME, AT_FDCWD, FILENAME, 0);
28    linkat(0x9879153, FILENAME, 0x9879154, FILENAME, 0); /* warning for this one */
29 
30    /* symlinkat */
31    symlinkat(FILENAME, dfd, FILENAME);
32    symlinkat(DIRECTORY FILENAME, 0x26868151, DIRECTORY FILENAME);
33    symlinkat(FILENAME, AT_FDCWD, FILENAME);
34    symlinkat(FILENAME, 0x26868152, FILENAME); /* warning for this one */
35 
36    /* readlinkat */
37    readlinkat(dfd, FILENAME, buf, 1);
38    readlinkat(0x4368151, DIRECTORY FILENAME, buf, 1);
39    readlinkat(AT_FDCWD, FILENAME, buf, 1);
40    readlinkat(0x4368152, FILENAME, buf, 1); /* warning for this one */
41 
42 #if defined(SOLARIS_FREALPATHAT_SYSCALL)
43    /* frealpathat - not available directly */
44    syscall(SYS_frealpathat, dfd, FILENAME, buf, 1);
45    syscall(SYS_frealpathat, 0x443115, DIRECTORY FILENAME, buf, 1);
46    syscall(SYS_frealpathat, AT_FDCWD, FILENAME, buf, 1);
47 #endif /* SOLARIS_FREALPATHAT_SYSCALL */
48 
49    /* faccessat */
50    faccessat(dfd, FILENAME, F_OK, 0);
51    faccessat(0x4132151, DIRECTORY FILENAME, F_OK, 0);
52    faccessat(AT_FDCWD, FILENAME, F_OK, 0);
53    faccessat(0x4132152, FILENAME, F_OK, 0); /* warning for this one */
54 
55    /* fchownat */
56    fchownat(dfd, FILENAME, -1, -1, 0);
57    fchownat(0x4369251, DIRECTORY FILENAME, -1, -1, 0);
58    fchownat(AT_FDCWD, FILENAME, -1, -1, 0);
59    fchownat(0x4369252, FILENAME, -1, -1, 0); /* warning for this one */
60 
61    /* renameat */
62    renameat(dfd, FILENAME, dfd, FILENAME);
63    renameat(0x4371151, DIRECTORY FILENAME, 0x4371152, DIRECTORY FILENAME);
64    renameat(AT_FDCWD, FILENAME, AT_FDCWD, FILENAME);
65    renameat(0x4371153, FILENAME, 0x4371154, FILENAME); /* warning for this one */
66 
67    /* unlinkat */
68    unlinkat(dfd, FILENAME, 0);
69    unlinkat(0x7608151, DIRECTORY FILENAME, 0);
70    unlinkat(AT_FDCWD, FILENAME, 0);
71    unlinkat(0x7608152, FILENAME, 0); /* warning for this one */
72 
73    /* fstatat */
74    fstatat(dfd, FILENAME, &stats, 0);
75    fstatat(0x42515151, DIRECTORY FILENAME, &stats, 0);
76    fstatat(AT_FDCWD, FILENAME, &stats, 0);
77    fstatat(0x42515152, FILENAME, &stats, 0); /* warning for this one */
78 
79    /* openat */
80    openat(dfd, FILENAME, O_RDONLY);
81    openat(0x9038151, DIRECTORY FILENAME, O_RDONLY);
82    openat(AT_FDCWD, FILENAME, O_RDONLY);
83    openat(0x9038152, FILENAME, O_RDONLY); /* warning for this one */
84 
85    /* fchmodat */
86    fchmodat(dfd, FILENAME, S_IRUSR | S_IWUSR, 0);
87    fchmodat(0x4303151, DIRECTORY FILENAME, S_IRUSR | S_IWUSR, 0);
88    fchmodat(AT_FDCWD, FILENAME, S_IRUSR | S_IWUSR, 0);
89    fchmodat(0x4303152, FILENAME, S_IRUSR | S_IWUSR, 0); /* warning for this one */
90 
91    /* mkdirat */
92    mkdirat(dfd, FILENAME, S_IRUSR | S_IWUSR);
93    mkdirat(0x9384151, DIRECTORY FILENAME, S_IRUSR | S_IWUSR);
94    mkdirat(AT_FDCWD, FILENAME, S_IRUSR | S_IWUSR);
95    mkdirat(0x9384152, FILENAME, S_IRUSR | S_IWUSR); /* warning for this one */
96 
97    /* utimensat */
98    utimensat(dfd, FILENAME, NULL, 0);
99    utimensat(0x59837215, DIRECTORY FILENAME, NULL, 0);
100    utimensat(AT_FDCWD, FILENAME, NULL, 0);
101    utimensat(0x59837216, FILENAME, NULL, 0); /* warning for this one */
102 
103    rmdir(DIRECTORY FILENAME);
104    rmdir(FILENAME);
105    close(dfd);
106    return 0;
107 }
108