git.strcat.st

/strcat/minitox.git/ - summarytreelogarchive

subject
null terminate /proc/self/fd/0 path from readlink
commit
29fab9e1f9151ba13c4e9f0624bbe621d461e30d
date
2026-04-17T20:52:08Z
message
diff
 minitox.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/minitox.c b/minitox.c
index 569c9d8..53aa5fc 100644
--- a/minitox.c
+++ b/minitox.c
@@ -415,10 +415,12 @@ void setup_arepl(void) {
         exit(1);
     }
 #else  // linux
-    if (readlink("/proc/self/fd/0", stdin_path, sizeof(stdin_path)) == -1) {
+    ssize_t nread = readlink("/proc/self/fd/0", stdin_path, sizeof(stdin_path) - 1);
+    if (nread == -1 || nread >= (ssize_t)(sizeof(stdin_path) - 1)) {
         fputs("! get stdin filename failed", stderr);
         exit(1);
     }
+    stdin_path[nread] = '\0';
 #endif
 
     NEW_STDIN_FILENO = open(stdin_path, O_RDONLY);