Find src directory in same directory as fuzzer.
Hardcoding /out does not work on ossfuzz executors.
Bug: 69150303
Change-Id: I1bdf3a5765a20fa33f336354ff7d87d8f3137039
diff --git a/src/traced/probes/ftrace/test/cpu_reader_support.cc b/src/traced/probes/ftrace/test/cpu_reader_support.cc
index 9c4bfc4..a46199b 100644
--- a/src/traced/probes/ftrace/test/cpu_reader_support.cc
+++ b/src/traced/probes/ftrace/test/cpu_reader_support.cc
@@ -29,6 +29,22 @@
std::map<std::string, std::unique_ptr<ProtoTranslationTable>>* g_tables;
+std::string GetBinaryDirectory() {
+ char buf[512];
+ ssize_t rd = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
+ if (rd < 0) {
+ PERFETTO_ELOG("Failed to readlink(\"/proc/self/exe\"");
+ return "";
+ }
+ char* end = static_cast<char*>(memrchr(buf, '/', static_cast<size_t>(rd)));
+ if (!end || end == buf + sizeof(buf) - 1) {
+ PERFETTO_ELOG("Failed to find directory.");
+ return "";
+ }
+ *(end + 1) = '\0';
+ return std::string(buf);
+}
+
} // namespace
ProtoTranslationTable* GetTable(const std::string& name) {
@@ -40,7 +56,7 @@
struct stat st;
if (lstat(path.c_str(), &st) == -1 && errno == ENOENT) {
// For OSS fuzz, which does not run in the correct cwd.
- path = "/out/" + path;
+ path = GetBinaryDirectory() + path;
}
FtraceProcfs ftrace(path);
auto table = ProtoTranslationTable::Create(&ftrace, GetStaticEventInfo(),