From 6c6e5e9b999b57f235137aa5435cc86256d150b7 Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Thu, 5 Jan 2023 21:59:45 +0100 Subject: [PATCH] Handle readlink errors (#1292) --- src/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 10910056..19b7d40f 100644 --- a/src/main.c +++ b/src/main.c @@ -36,8 +36,9 @@ static void get_exe_filename(char *buf, int sz) { buf[len] = '\0'; #elif __linux__ char path[] = "/proc/self/exe"; - int len = readlink(path, buf, sz - 1); - buf[len] = '\0'; + ssize_t len = readlink(path, buf, sz - 1); + if (len > 0) + buf[len] = '\0'; #elif __APPLE__ /* use realpath to resolve a symlink if the process was launched from one. ** This happens when Homebrew installs a cack and creates a symlink in