From 1344151b195c5ff83c2337427c1fdb1162250045 Mon Sep 17 00:00:00 2001 From: Evan Gates Date: Mon, 18 Sep 2023 20:38:35 -0600 Subject: vis-single: respect TMPDIR The temporary directory for vis-single was hard coded to /tmp. If /tmp happens to be mounted noexec then vis fails as it cannot run anything placed inside the temporary directory. If the TMPDIR environment variable is set, respect it for vis-single. --- vis-single.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/vis-single.c b/vis-single.c index 11af10f..1a1e2c3 100644 --- a/vis-single.c +++ b/vis-single.c @@ -19,8 +19,12 @@ #include "vis-single-payload.inc" +#ifndef VIS_TMP_DIR +#define VIS_TMP_DIR "/tmp" +#endif + #ifndef VIS_TMP -#define VIS_TMP "/tmp/.vis-single-XXXXXX" +#define VIS_TMP ".vis-single-XXXXXX" #endif #ifndef VIS_TERMINFO @@ -94,8 +98,14 @@ static int unlink_cb(const char *path, const struct stat *sb, int typeflag, stru int main(int argc, char **argv) { int rc = EXIT_FAILURE; - char exe[256], path[PATH_MAX]; - char tmp_dirname[] = VIS_TMP; + char exe[256], path[PATH_MAX], tmp_dirname[PATH_MAX]; + + char *tmpdir = getenv("TMPDIR"); + if (snprintf(tmp_dirname, sizeof(tmp_dirname), "%s/%s", + tmpdir ? tmpdir : VIS_TMP_DIR, VIS_TMP) < 0) { + perror("snprintf"); + return rc; + } if (!mkdtemp(tmp_dirname)) { perror("mkdtemp"); -- cgit v1.2.3