Loading libs/binder/tests/parcel_fuzzer/random_fd.cpp +59 −34 Original line number Diff line number Diff line Loading @@ -29,8 +29,8 @@ std::vector<unique_fd> getRandomFds(FuzzedDataProvider* provider) { const char* fdType; std::vector<unique_fd> fds = provider->PickValueInArray< std::function<std::vector<unique_fd>()>>({ [&]() { std::function<std::vector<unique_fd>()>>( {[&]() { fdType = "ashmem"; std::vector<unique_fd> ret; ret.push_back(unique_fd( Loading Loading @@ -62,6 +62,31 @@ std::vector<unique_fd> getRandomFds(FuzzedDataProvider* provider) { ret.push_back(unique_fd(pipefds[1])); return ret; }, [&]() { fdType = "tempfd"; char name[PATH_MAX]; #if defined(__ANDROID__) snprintf(name, sizeof(name), "/data/local/tmp/android-tempfd-test-%d-XXXXXX", getpid()); #else snprintf(name, sizeof(name), "/tmp/android-tempfd-test-%d-XXXXXX", getpid()); #endif int fd = mkstemp(name); CHECK_NE(fd, -1) << "Failed to create file " << name << ", errno: " << errno; unlink(name); if (provider->ConsumeBool()) { CHECK_NE(TEMP_FAILURE_RETRY( ftruncate(fd, provider->ConsumeIntegralInRange<size_t>(0, 4096))), -1) << "Failed to truncate file, errno: " << errno; } std::vector<unique_fd> ret; ret.push_back(unique_fd(fd)); return ret; } })(); for (const auto& fd : fds) CHECK(fd.ok()) << fd.get() << " " << fdType; Loading Loading
libs/binder/tests/parcel_fuzzer/random_fd.cpp +59 −34 Original line number Diff line number Diff line Loading @@ -29,8 +29,8 @@ std::vector<unique_fd> getRandomFds(FuzzedDataProvider* provider) { const char* fdType; std::vector<unique_fd> fds = provider->PickValueInArray< std::function<std::vector<unique_fd>()>>({ [&]() { std::function<std::vector<unique_fd>()>>( {[&]() { fdType = "ashmem"; std::vector<unique_fd> ret; ret.push_back(unique_fd( Loading Loading @@ -62,6 +62,31 @@ std::vector<unique_fd> getRandomFds(FuzzedDataProvider* provider) { ret.push_back(unique_fd(pipefds[1])); return ret; }, [&]() { fdType = "tempfd"; char name[PATH_MAX]; #if defined(__ANDROID__) snprintf(name, sizeof(name), "/data/local/tmp/android-tempfd-test-%d-XXXXXX", getpid()); #else snprintf(name, sizeof(name), "/tmp/android-tempfd-test-%d-XXXXXX", getpid()); #endif int fd = mkstemp(name); CHECK_NE(fd, -1) << "Failed to create file " << name << ", errno: " << errno; unlink(name); if (provider->ConsumeBool()) { CHECK_NE(TEMP_FAILURE_RETRY( ftruncate(fd, provider->ConsumeIntegralInRange<size_t>(0, 4096))), -1) << "Failed to truncate file, errno: " << errno; } std::vector<unique_fd> ret; ret.push_back(unique_fd(fd)); return ret; } })(); for (const auto& fd : fds) CHECK(fd.ok()) << fd.get() << " " << fdType; Loading