From 804c61b7c1405f4440327f6f6ebbe9813f67938f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 17 Jun 2024 13:50:36 +0800 Subject: [PATCH] Platform (Linux): fix invalid call to `realpath(3)` --- src/util/platform/FFPlatform_unix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index d4d39babb..4ba4d2a5f 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -35,12 +35,13 @@ static void getExePath(FFPlatform* platform) else exePathLen--; // remove terminating NUL #else - int exePathLen = 0; + ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1); + exePath[exePathLen] = '\0'; #endif if (exePathLen > 0) { ffStrbufEnsureFree(&platform->exePath, PATH_MAX); - if (realpath(platform->exePath.chars, exePath)) + if (realpath(exePath, platform->exePath.chars)) ffStrbufRecalculateLength(&platform->exePath); else ffStrbufSetNS(&platform->exePath, (uint32_t) exePathLen, exePath);