From b44defe60a1e89e8f52abd40f90b849b7806c190 Mon Sep 17 00:00:00 2001 From: Sander in 't Veld Date: Fri, 27 Jul 2018 19:04:04 +0200 Subject: [PATCH] [Linux] Null-terminate output from readlink in Discord_Register. (#208) * Explicitly null-terminate the output from readlink in discord_register_linux.cpp. * The return value of readlink is a signed size_t. --- src/discord_register_linux.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/discord_register_linux.cpp b/src/discord_register_linux.cpp index b10f96d..34f8701 100644 --- a/src/discord_register_linux.cpp +++ b/src/discord_register_linux.cpp @@ -33,9 +33,11 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const char exePath[1024]; if (!command || !command[0]) { - if (readlink("/proc/self/exe", exePath, sizeof(exePath)) <= 0) { + ssize_t size = readlink("/proc/self/exe", exePath, sizeof(exePath)); + if (size <= 0 || size >= sizeof(exePath)) { return; } + exePath[size] = '\0'; command = exePath; }