Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitizes launcher tests using AddressSanitizer #731

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion launcher/fuzzed_data_provider_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class FuzzedDataProviderTest : public ::testing::Test {
// destroyed after all tests in this test suite have finished.
static void SetUpTestCase() {
using ::bazel::tools::cpp::runfiles::Runfiles;
FLAGS_cp = Runfiles::CreateForTest()->Rlocation(
std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest());
FLAGS_cp = runfiles->Rlocation(
"jazzer/launcher/testdata/fuzz_target_mocks_deploy.jar");

jvm_ = std::make_unique<JVM>();
Expand Down
13 changes: 9 additions & 4 deletions launcher/jvm_tooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,21 @@ std::string getExecutablePath() {
char buf[655536];
#if defined(__APPLE__)
uint32_t buf_size = sizeof(buf);
if (_NSGetExecutablePath(buf, &buf_size) != 0) {
ssize_t read_bytes = buf_size - 1;
bool failed _NSGetExecutablePath(buf, &buf_size) != 0;
hadi88 marked this conversation as resolved.
Show resolved Hide resolved
#elif defined(_WIN32)
if (GetModuleFileNameA(NULL, buf, sizeof(buf)) == 0) {
ssize_t read_bytes = GetModuleFileNameA(NULL, buf, sizeof(buf));
fmeum marked this conversation as resolved.
Show resolved Hide resolved
bool failed = (read_bytes == 0);
#elif defined(_ANDROID)
if (true) {
bool failed = true;
#else // Assume Linux
if (readlink("/proc/self/exe", buf, sizeof(buf)) == -1) {
ssize_t read_bytes = readlink("/proc/self/exe", buf, sizeof(buf));
bool failed = (read_bytes == -1);
#endif
if (failed) {
return "";
}
buf[read_bytes] = '\0';
return {buf};
}

Expand Down
3 changes: 2 additions & 1 deletion launcher/jvm_tooling_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class JvmToolingTest : public ::testing::Test {
FLAGS_jvm_args =
"-Denv1=va\\" ARG_SEPARATOR "l1\\\\" ARG_SEPARATOR "-Denv2=val2";
using ::bazel::tools::cpp::runfiles::Runfiles;
FLAGS_cp = Runfiles::CreateForTest()->Rlocation(
std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest());
FLAGS_cp = runfiles->Rlocation(
"jazzer/launcher/testdata/fuzz_target_mocks_deploy.jar");

jvm_ = std::unique_ptr<JVM>(new JVM());
Expand Down