From 3ee51b9e14f288ab7f1f31bdc4ad07ab4d1c55b8 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Fri, 18 Dec 2015 11:58:39 -0800 Subject: [PATCH] Fix 0-termination. --- src/host/premake.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/host/premake.c b/src/host/premake.c index c9b7ce44..be7983b7 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -232,7 +232,10 @@ int premake_locate_executable(lua_State* L, const char* argv0) #if PLATFORM_WINDOWS DWORD len = GetModuleFileName(NULL, buffer, PATH_MAX); if (len > 0) + { + buffer[len] = 0; path = buffer; + } #endif #if PLATFORM_MACOSX @@ -243,23 +246,32 @@ int premake_locate_executable(lua_State* L, const char* argv0) #endif #if PLATFORM_LINUX - int len = readlink("/proc/self/exe", buffer, PATH_MAX); + int len = readlink("/proc/self/exe", buffer, PATH_MAX - 1); if (len > 0) + { + buffer[len] = 0; path = buffer; + } #endif #if PLATFORM_BSD - int len = readlink("/proc/curproc/file", buffer, PATH_MAX); + int len = readlink("/proc/curproc/file", buffer, PATH_MAX - 1); if (len < 0) - len = readlink("/proc/curproc/exe", buffer, PATH_MAX); + len = readlink("/proc/curproc/exe", buffer, PATH_MAX - 1); if (len > 0) + { + buffer[len] = 0; path = buffer; + } #endif #if PLATFORM_SOLARIS - int len = readlink("/proc/self/path/a.out", buffer, PATH_MAX); + int len = readlink("/proc/self/path/a.out", buffer, PATH_MAX - 1); if (len > 0) + { + buffer[len] = 0; path = buffer; + } #endif /* As a fallback, search the PATH with argv[0] */