android-cloexec-open.cpp
6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// RUN: %check_clang_tidy %s android-cloexec-open %t
#define O_RDWR 1
#define O_EXCL 2
#define __O_CLOEXEC 3
#define O_CLOEXEC __O_CLOEXEC
#define TEMP_FAILURE_RETRY(exp) \
({ \
int _rc; \
do { \
_rc = (exp); \
} while (_rc == -1); \
})
extern "C" int open(const char *fn, int flags, ...);
extern "C" int open64(const char *fn, int flags, ...);
extern "C" int openat(int dirfd, const char *pathname, int flags, ...);
void a() {
open("filename", O_RDWR);
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 'open' should use O_CLOEXEC where possible [android-cloexec-open]
// CHECK-FIXES: O_RDWR | O_CLOEXEC
TEMP_FAILURE_RETRY(open("filename", O_RDWR));
// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: 'open' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_CLOEXEC
open("filename", O_RDWR | O_EXCL);
// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: 'open' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
TEMP_FAILURE_RETRY(open("filename", O_RDWR | O_EXCL));
// CHECK-MESSAGES: :[[@LINE-1]]:54: warning: 'open' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
}
void b() {
open64("filename", O_RDWR);
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: 'open64' should use O_CLOEXEC where possible [android-cloexec-open]
// CHECK-FIXES: O_RDWR | O_CLOEXEC
TEMP_FAILURE_RETRY(open64("filename", O_RDWR));
// CHECK-MESSAGES: :[[@LINE-1]]:47: warning: 'open64' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_CLOEXEC
open64("filename", O_RDWR | O_EXCL);
// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: 'open64' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
TEMP_FAILURE_RETRY(open64("filename", O_RDWR | O_EXCL));
// CHECK-MESSAGES: :[[@LINE-1]]:56: warning: 'open64' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
}
void c() {
openat(0, "filename", O_RDWR);
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'openat' should use O_CLOEXEC where possible [android-cloexec-open]
// CHECK-FIXES: O_RDWR | O_CLOEXEC
TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR));
// CHECK-MESSAGES: :[[@LINE-1]]:50: warning: 'openat' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_CLOEXEC
openat(0, "filename", O_RDWR | O_EXCL);
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: 'openat' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR | O_EXCL));
// CHECK-MESSAGES: :[[@LINE-1]]:59: warning: 'openat' should use O_CLOEXEC where
// CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC
}
void f() {
open("filename", 3);
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 'open' should use O_CLOEXEC where possible [android-cloexec-open]
// CHECK-FIXES: 3 | O_CLOEXEC
TEMP_FAILURE_RETRY(open("filename", 3));
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: 'open' should use O_CLOEXEC where
// CHECK-FIXES: 3 | O_CLOEXEC
open64("filename", 3);
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'open64' should use O_CLOEXEC where possible [android-cloexec-open]
// CHECK-FIXES: 3 | O_CLOEXEC
TEMP_FAILURE_RETRY(open64("filename", 3));
// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: 'open64' should use O_CLOEXEC where
// CHECK-FIXES: 3 | O_CLOEXEC
openat(0, "filename", 3);
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 'openat' should use O_CLOEXEC where possible [android-cloexec-open]
// CHECK-FIXES: 3 | O_CLOEXEC
TEMP_FAILURE_RETRY(openat(0, "filename", 3));
// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: 'openat' should use O_CLOEXEC where
// CHECK-FIXES: 3 | O_CLOEXEC
int flag = 3;
open("filename", flag);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open("filename", flag));
// CHECK-MESSAGES-NOT: warning:
open64("filename", flag);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open64("filename", flag));
// CHECK-MESSAGES-NOT: warning:
openat(0, "filename", flag);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(openat(0, "filename", flag));
// CHECK-MESSAGES-NOT: warning:
}
namespace i {
int open(const char *pathname, int flags, ...);
int open64(const char *pathname, int flags, ...);
int openat(int dirfd, const char *pathname, int flags, ...);
void d() {
open("filename", O_RDWR);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open("filename", O_RDWR));
// CHECK-MESSAGES-NOT: warning:
open64("filename", O_RDWR);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open64("filename", O_RDWR));
// CHECK-MESSAGES-NOT: warning:
openat(0, "filename", O_RDWR);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR));
// CHECK-MESSAGES-NOT: warning:
}
} // namespace i
void e() {
open("filename", O_CLOEXEC);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open("filename", O_CLOEXEC));
// CHECK-MESSAGES-NOT: warning:
open("filename", O_RDWR | O_CLOEXEC);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open("filename", O_RDWR | O_CLOEXEC));
// CHECK-MESSAGES-NOT: warning:
open("filename", O_RDWR | O_CLOEXEC | O_EXCL);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open("filename", O_RDWR | O_CLOEXEC | O_EXCL));
// CHECK-MESSAGES-NOT: warning:
open64("filename", O_CLOEXEC);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open64("filename", O_CLOEXEC));
// CHECK-MESSAGES-NOT: warning:
open64("filename", O_RDWR | O_CLOEXEC);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open64("filename", O_RDWR | O_CLOEXEC));
// CHECK-MESSAGES-NOT: warning:
open64("filename", O_RDWR | O_CLOEXEC | O_EXCL);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open64("filename", O_RDWR | O_CLOEXEC | O_EXCL));
// CHECK-MESSAGES-NOT: warning:
openat(0, "filename", O_CLOEXEC);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(openat(0, "filename", O_CLOEXEC));
// CHECK-MESSAGES-NOT: warning:
openat(0, "filename", O_RDWR | O_CLOEXEC);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR | O_CLOEXEC));
// CHECK-MESSAGES-NOT: warning:
openat(0, "filename", O_RDWR | O_CLOEXEC | O_EXCL);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR | O_CLOEXEC | O_EXCL));
// CHECK-MESSAGES-NOT: warning:
}
class G {
public:
int open(const char *pathname, int flags, ...);
int open64(const char *pathname, int flags, ...);
int openat(int dirfd, const char *pathname, int flags, ...);
void h() {
open("filename", O_RDWR);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open("filename", O_RDWR));
// CHECK-MESSAGES-NOT: warning:
open64("filename", O_RDWR);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(open64("filename", O_RDWR));
// CHECK-MESSAGES-NOT: warning:
openat(0, "filename", O_RDWR);
// CHECK-MESSAGES-NOT: warning:
TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR));
// CHECK-MESSAGES-NOT: warning:
}
};