From 4ded3b39fd454f5bff04f7f3135eac30b1fcded0 Mon Sep 17 00:00:00 2001 From: Masato Takahashi Date: Sat, 23 May 2020 09:45:45 +0900 Subject: [PATCH] libobs: Fix os_get_executable_path_ptr on Linux Terminate a non-terminated string generated by readlink() to pass to dirname() that needs terminated string as a parameter. --- libobs/util/platform-nix.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libobs/util/platform-nix.c b/libobs/util/platform-nix.c index 1dd81077e..26800d52f 100644 --- a/libobs/util/platform-nix.c +++ b/libobs/util/platform-nix.c @@ -287,7 +287,10 @@ char *os_get_executable_path_ptr(const char *name) } count = pathlen; #else - ssize_t count = readlink("/proc/self/exe", exe, PATH_MAX); + ssize_t count = readlink("/proc/self/exe", exe, PATH_MAX - 1); + if (count >= 0) { + exe[count] = '\0'; + } #endif const char *path_out = NULL; struct dstr path;