From 99f33cab614088fafd64180b665481c23115ec07 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 4 Jul 2021 23:44:37 -0400 Subject: [PATCH] Fix Symlink Code --- VERSION | 2 +- docs/CHANGELOG.md | 3 +++ libreborn/include/libreborn/exec.h | 10 +++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index 7ec1d6db4..3e3c2f1e5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.0 +2.1.1 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8b717edbe..a00c8709c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +**2.1.1** +* Fix Symlink Code + **2.1.0** * Allow Binding ``Q`` Key To Item Dropping * Expose More Feature Flags diff --git a/libreborn/include/libreborn/exec.h b/libreborn/include/libreborn/exec.h index 12630b4ee..34493b3e7 100644 --- a/libreborn/include/libreborn/exec.h +++ b/libreborn/include/libreborn/exec.h @@ -30,11 +30,11 @@ static inline char *get_binary_directory() { if (lstat(EXE_PATH, &sb) == -1) { ERR("Unable To Get " EXE_PATH " Symlink Size: %s", strerror(errno)); } - ssize_t path_size = sb.st_size + 1; - if (sb.st_size == 0) { + ssize_t path_size = sb.st_size; + if (sb.st_size <= 0) { path_size = PATH_MAX; } - char *exe = (char *) malloc(path_size); + char *exe = (char *) malloc(path_size + 1); ALLOC_CHECK(exe); // Read Link ssize_t r = readlink(EXE_PATH, exe, path_size); @@ -44,10 +44,10 @@ static inline char *get_binary_directory() { if (r > path_size) { ERR("%s", "Size Of Symlink " EXE_PATH " Changed"); } - exe[path_size] = '\0'; + exe[r + 1] = '\0'; // Chop Off Last Component - for (int i = path_size - 1; i >= 0; i--) { + for (int i = r; i >= 0; i--) { if (exe[i] == '/') { exe[i] = '\0'; break;