|
|
0d8902 |
--- a2ps-4.13/lib/routines.c.security Sat Oct 16 05:46:37 1999
|
|
|
0d8902 |
+++ a2ps-4.13/lib/routines.c Mon Feb 12 17:45:15 2001
|
|
|
0d8902 |
@@ -242,3 +242,50 @@
|
|
|
0d8902 |
/* Don't complain if you can't unlink. Who cares of a tmp file? */
|
|
|
0d8902 |
unlink (filename);
|
|
|
0d8902 |
}
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+/*
|
|
|
0d8902 |
+ * Securely generate a temp file, and make sure it gets
|
|
|
0d8902 |
+ * deleted upon exit.
|
|
|
0d8902 |
+ */
|
|
|
0d8902 |
+static char ** tempfiles;
|
|
|
0d8902 |
+static unsigned ntempfiles;
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+static void
|
|
|
0d8902 |
+cleanup_tempfiles()
|
|
|
0d8902 |
+{
|
|
|
0d8902 |
+ while (ntempfiles--)
|
|
|
0d8902 |
+ unlink(tempfiles[ntempfiles]);
|
|
|
0d8902 |
+}
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+char *
|
|
|
0d8902 |
+safe_tempnam(const char *pfx)
|
|
|
0d8902 |
+{
|
|
|
0d8902 |
+ char *dirname, *filename;
|
|
|
0d8902 |
+ int fd;
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+ if (!(dirname = getenv("TMPDIR")))
|
|
|
0d8902 |
+ dirname = "/tmp";
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+ tempfiles = (char **) realloc(tempfiles,
|
|
|
0d8902 |
+ (ntempfiles+1) * sizeof(char *));
|
|
|
0d8902 |
+ if (tempfiles == NULL)
|
|
|
0d8902 |
+ return NULL;
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+ filename = malloc(strlen(dirname) + strlen(pfx) + sizeof("/XXXXXX"));
|
|
|
0d8902 |
+ if (!filename)
|
|
|
0d8902 |
+ return NULL;
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+ sprintf(filename, "%s/%sXXXXXX", dirname, pfx);
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+ if ((fd = mkstemp(filename)) < 0) {
|
|
|
0d8902 |
+ free(filename);
|
|
|
0d8902 |
+ return NULL;
|
|
|
0d8902 |
+ }
|
|
|
0d8902 |
+ close(fd);
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+ if (ntempfiles == 0)
|
|
|
0d8902 |
+ atexit(cleanup_tempfiles);
|
|
|
0d8902 |
+ tempfiles[ntempfiles++] = filename;
|
|
|
0d8902 |
+
|
|
|
0d8902 |
+ return filename;
|
|
|
0d8902 |
+}
|
|
|
0d8902 |
--- a2ps-4.13/lib/routines.h.security Mon Oct 18 21:24:41 1999
|
|
|
0d8902 |
+++ a2ps-4.13/lib/routines.h Mon Feb 12 17:39:30 2001
|
|
|
0d8902 |
@@ -255,7 +255,8 @@
|
|
|
0d8902 |
/* If _STR_ is not defined, give it a tempname in _TMPDIR_ */
|
|
|
0d8902 |
#define tempname_ensure(Str) \
|
|
|
0d8902 |
do { \
|
|
|
0d8902 |
- (Str) = (Str) ? (Str) : tempnam (NULL, "a2_"); \
|
|
|
0d8902 |
+ (Str) = (Str) ? (Str) : safe_tempnam("a2_"); \
|
|
|
0d8902 |
} while (0)
|
|
|
0d8902 |
+char * safe_tempnam(const char *);
|
|
|
0d8902 |
|
|
|
0d8902 |
#endif
|