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);