1 --- a2ps-4.13/lib/routines.c.security Sat Oct 16 05:46:37 1999
2 +++ a2ps-4.13/lib/routines.c Mon Feb 12 17:45:15 2001
4 /* Don't complain if you can't unlink. Who cares of a tmp file? */
9 + * Securely generate a temp file, and make sure it gets
10 + * deleted upon exit.
12 +static char ** tempfiles;
13 +static unsigned ntempfiles;
18 + while (ntempfiles--)
19 + unlink(tempfiles[ntempfiles]);
23 +safe_tempnam(const char *pfx)
25 + char *dirname, *filename;
28 + if (!(dirname = getenv("TMPDIR")))
31 + tempfiles = (char **) realloc(tempfiles,
32 + (ntempfiles+1) * sizeof(char *));
33 + if (tempfiles == NULL)
36 + filename = malloc(strlen(dirname) + strlen(pfx) + sizeof("/XXXXXX"));
40 + sprintf(filename, "%s/%sXXXXXX", dirname, pfx);
42 + if ((fd = mkstemp(filename)) < 0) {
48 + if (ntempfiles == 0)
49 + atexit(cleanup_tempfiles);
50 + tempfiles[ntempfiles++] = filename;
54 --- a2ps-4.13/lib/routines.h.security Mon Oct 18 21:24:41 1999
55 +++ a2ps-4.13/lib/routines.h Mon Feb 12 17:39:30 2001
57 /* If _STR_ is not defined, give it a tempname in _TMPDIR_ */
58 #define tempname_ensure(Str) \
60 - (Str) = (Str) ? (Str) : tempnam (NULL, "a2_"); \
61 + (Str) = (Str) ? (Str) : safe_tempnam("a2_"); \
63 +char * safe_tempnam(const char *);