summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-28 00:44:42 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-28 00:44:42 -0600
commitde0d26a1e6b2916996867c4c11f5146302720587 (patch)
tree50c14b4754d61e08a9769b551137ced10716f9b8
parent06e1dd50e4c2e93150b4e14ee2cbed566900cd3a (diff)
downloadzash-de0d26a1e6b2916996867c4c11f5146302720587.tar.gz
fix(redir): reject a TMPDIR too long for the here-document path
The snprintf() into path[PATH_MAX] was unchecked: with a TMPDIR longer than that, the name was truncated and mkstemp() could be pointed at a different directory than the one meant. The length is now checked and the here document falls back to the pipe it already uses on failure.
-rw-r--r--src/redir.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/redir.c b/src/redir.c
index 2d328a9..edfc212 100644
--- a/src/redir.c
+++ b/src/redir.c
@@ -109,7 +109,10 @@ static int heredoc_open(const redir *r) {
}
const char *dir = var_get("TMPDIR");
char path[PATH_MAX];
- snprintf(path, sizeof path, "%s/zashXXXXXX", dir && *dir ? dir : "/tmp");
+ int n = snprintf(path, sizeof path, "%s/zashXXXXXX",
+ dir && *dir ? dir : "/tmp");
+ if (n < 0 || (size_t)n >= sizeof path) /* a TMPDIR longer than PATH_MAX */
+ return -1;
int fd = mkstemp(path);
if (fd < 0)
return -1;