Skip to content

Commit

Permalink
Sanitizes launcher tests using AddressSanitizer (#731)
Browse files Browse the repository at this point in the history
* Sanitizes launcher tests using https://github.com/google/sanitizers/wiki/AddressSanitizer

* Update launcher/jvm_tooling.cpp

Co-authored-by: Fabian Meumertzheim <[email protected]>

* Sanitizes launcher tests using https://github.com/google/sanitizers/wiki/AddressSanitizer

---------

Co-authored-by: Fabian Meumertzheim <[email protected]>
  • Loading branch information
hadi88 and fmeum committed Apr 26, 2023
1 parent 88ba6dd commit d68158d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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) {
uint32_t read_bytes = buf_size - 1;
bool failed = (_NSGetExecutablePath(buf, &buf_size) != 0);
#elif defined(_WIN32)
if (GetModuleFileNameA(NULL, buf, sizeof(buf)) == 0) {
DWORD read_bytes = GetModuleFileNameA(NULL, buf, sizeof(buf));
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

0 comments on commit d68158d

Please sign in to comment.