Skip to content

Commit 2a83b86

Browse files
authored
Platform (Linux): fix exe path detection (#1468)
On error, -1 is returned from readlink()
1 parent d967d05 commit 2a83b86

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/util/platform/FFPlatform_unix.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ static void getExePath(FFPlatform* platform)
2121
char exePath[PATH_MAX + 1];
2222
#ifdef __linux__
2323
ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1);
24-
exePath[exePathLen] = '\0';
24+
if (exePathLen >= 0)
25+
exePath[exePathLen] = '\0';
2526
#elif defined(__APPLE__)
2627
int exePathLen = proc_pidpath((int) getpid(), exePath, sizeof(exePath));
2728
#elif defined(__FreeBSD__) || defined(__NetBSD__)
@@ -44,7 +45,8 @@ static void getExePath(FFPlatform* platform)
4445
size_t exePathLen = 0;
4546
#elif defined(__sun)
4647
ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1);
47-
exePath[exePathLen] = '\0';
48+
if (exePathLen >= 0)
49+
exePath[exePathLen] = '\0';
4850
#endif
4951
if (exePathLen > 0)
5052
{

0 commit comments

Comments
 (0)