|
28 | 28 | #include <fuzzbinder/random_parcel.h> |
29 | 29 | #include <fuzzer/FuzzedDataProvider.h> |
30 | 30 |
|
31 | | -#include <cstdlib> |
32 | | -#include <ctime> |
33 | 31 | #include <sys/resource.h> |
34 | 32 | #include <sys/time.h> |
| 33 | +#include <cstdlib> |
| 34 | +#include <ctime> |
| 35 | +#include <filesystem> |
35 | 36 |
|
36 | 37 | #include "../../Utils.h" |
37 | 38 |
|
@@ -157,12 +158,21 @@ static AIBinder_Class* kNothingClass = |
157 | 158 | AIBinder_Class_define("nothing", NothingClass_onCreate, NothingClass_onDestroy, |
158 | 159 | NothingClass_onTransact); |
159 | 160 |
|
| 161 | +static long numFds() { |
| 162 | + return std::distance(std::filesystem::directory_iterator("/proc/self/fd"), |
| 163 | + std::filesystem::directory_iterator{}); |
| 164 | +} |
160 | 165 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
161 | 166 | if (size <= 1) return 0; // no use |
162 | 167 |
|
163 | 168 | // avoid timeouts, see b/142617274, b/142473153 |
164 | 169 | if (size > 50000) return 0; |
165 | 170 |
|
| 171 | + struct rlimit limit{}; |
| 172 | + CHECK_EQ(0, getrlimit(RLIMIT_NOFILE, &limit)); |
| 173 | + uint64_t maxFds = limit.rlim_cur; |
| 174 | + int initialFds = numFds(); |
| 175 | + |
166 | 176 | FuzzedDataProvider provider = FuzzedDataProvider(data, size); |
167 | 177 |
|
168 | 178 | const std::function<void(FuzzedDataProvider&&)> fuzzBackend[] = { |
@@ -209,5 +219,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
209 | 219 |
|
210 | 220 | provider.PickValueInArray(fuzzBackend)(std::move(provider)); |
211 | 221 |
|
| 222 | + CHECK_EQ(initialFds, numFds()) << "FDs are being leaked"; |
212 | 223 | return 0; |
213 | 224 | } |
0 commit comments