aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Kevin Backhouse <kevinbackhouse@github.com>2022-06-23 14:40:34 +0100
committerGravatar GitHub <noreply@github.com>2022-06-23 09:40:34 -0400
commitd1e407f0f335d167620c48a4bd93ff65aaec7bac (patch)
tree36c5f224ed7df5355411cffddec94e7a77d644e3
parentccd918bb59c49750b41a6d2652f69cfd68f7d7a4 (diff)
Use /proc/self/exe to deduce the correct path. (#7908)
-rw-r--r--projects/ruby/fuzz_ruby_gems.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/projects/ruby/fuzz_ruby_gems.c b/projects/ruby/fuzz_ruby_gems.c
index a627839d..7f955b58 100644
--- a/projects/ruby/fuzz_ruby_gems.c
+++ b/projects/ruby/fuzz_ruby_gems.c
@@ -251,16 +251,22 @@ static init_TargetFunction_ptr init_functions[] = {
// will work.
static int setenv_rubylib() {
char rubylib[0x1000];
- char cwd[PATH_MAX];
- const char *outpath = getenv("OUT");
+ char exepath[PATH_MAX];
- getcwd(cwd, sizeof(cwd));
- if (!outpath) {
- outpath = cwd;
- }
+ // Deduce the location of the OUT directory from the executable path.
+ ssize_t n = readlink("/proc/self/exe", exepath, sizeof(exepath));
+
+ // Find the parent directory.
+ do {
+ if (n <= 0) {
+ return -1;
+ }
+ } while(exepath[--n] != '/');
+ exepath[n] = '\0';
+ fprintf(stderr, "exepath = %s\n", exepath);
// init_ruby_load_paths() is automatically generated by build.sh
- const int r = init_ruby_load_paths(rubylib, sizeof(rubylib), outpath);
+ const int r = init_ruby_load_paths(rubylib, sizeof(rubylib), exepath);
if (r < 0 || (size_t)r >= sizeof(rubylib)) {
return -1;
}