Hello,

Sending this to tech list as suggested by mmcc@...

The yacc(1) manual mentions TMPDIR is an extension.
The following patch re-factors the checks around TMPDIR.
This adds an explicit check for TMPDIR-is-a-directory.
With this patch applied, yacc can more reliably determine when it
should use _PATH_TMP.

- Michael


Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/yacc/main.c,v
retrieving revision 1.27
diff -u -p -u -r1.27 main.c
--- main.c      10 Oct 2015 14:23:47 -0000      1.27
+++ main.c      21 Jun 2016 03:47:30 -0000
@@ -33,6 +33,7 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <paths.h>
@@ -225,6 +226,18 @@ allocate(size_t n)
        return (v);
 }
 
+char *
+tmp_dir(void)
+{
+       struct stat st;
+       char *tmp;
+
+       tmp = getenv("TMPDIR");
+       if (tmp == NULL || *tmp == '\0' || lstat(tmp, &st) == -1 || 
!S_ISDIR(st.st_mode))
+               return (_PATH_TMP);
+       return (tmp);
+}
+
 #define TEMPNAME(s, c, d, l)   \
        (asprintf(&(s), "%.*s/yacc.%xXXXXXXXXXX", (int)(l), (d), (c)))
 
@@ -234,9 +247,7 @@ create_file_names(void)
        size_t len;
        char *tmpdir;
 
-       if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
-               tmpdir = _PATH_TMP;
-
+       tmpdir = tmp_dir();
        len = strlen(tmpdir);
        if (tmpdir[len - 1] == '/')
                len--;

Reply via email to