Skip to content

Commit 7690add

Browse files
Check for leaking FDs in binder_parcel_fuzzer
Ignore-AOSP-First: na Flag: TEST_ONLY Test: binder_parcel_fuzzer Bug: 406499223 Change-Id: I65aa5ebd753c58041feb77c5b2de8abc3ca677a5
1 parent a0d6a71 commit 7690add

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

libs/binder/tests/parcel_fuzzer/main.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
#include <fuzzbinder/random_parcel.h>
2929
#include <fuzzer/FuzzedDataProvider.h>
3030

31-
#include <cstdlib>
32-
#include <ctime>
3331
#include <sys/resource.h>
3432
#include <sys/time.h>
33+
#include <cstdlib>
34+
#include <ctime>
35+
#include <filesystem>
3536

3637
#include "../../Utils.h"
3738

@@ -157,12 +158,21 @@ static AIBinder_Class* kNothingClass =
157158
AIBinder_Class_define("nothing", NothingClass_onCreate, NothingClass_onDestroy,
158159
NothingClass_onTransact);
159160

161+
static long numFds() {
162+
return std::distance(std::filesystem::directory_iterator("/proc/self/fd"),
163+
std::filesystem::directory_iterator{});
164+
}
160165
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
161166
if (size <= 1) return 0; // no use
162167

163168
// avoid timeouts, see b/142617274, b/142473153
164169
if (size > 50000) return 0;
165170

171+
struct rlimit limit{};
172+
CHECK_EQ(0, getrlimit(RLIMIT_NOFILE, &limit));
173+
uint64_t maxFds = limit.rlim_cur;
174+
int initialFds = numFds();
175+
166176
FuzzedDataProvider provider = FuzzedDataProvider(data, size);
167177

168178
const std::function<void(FuzzedDataProvider&&)> fuzzBackend[] = {
@@ -209,5 +219,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
209219

210220
provider.PickValueInArray(fuzzBackend)(std::move(provider));
211221

222+
CHECK_EQ(initialFds, numFds()) << "FDs are being leaked";
212223
return 0;
213224
}

0 commit comments

Comments
 (0)