1 https://sources.debian.org/data/main/a/a2ps/1:4.14-5/debian/patches/09_CVE-2001-1593.diff
3 Index: b/lib/routines.c
4 ===================================================================
8 /* Don't complain if you can't unlink. Who cares of a tmp file? */
13 + * Securely generate a temp file, and make sure it gets
14 + * deleted upon exit.
16 +static char ** tempfiles;
17 +static unsigned ntempfiles;
22 + while (ntempfiles--)
23 + unlink(tempfiles[ntempfiles]);
27 +safe_tempnam(const char *pfx)
29 + char *dirname, *filename;
32 + if (!(dirname = getenv("TMPDIR")))
35 + tempfiles = (char **) realloc(tempfiles,
36 + (ntempfiles+1) * sizeof(char *));
37 + if (tempfiles == NULL)
40 + filename = malloc(strlen(dirname) + strlen(pfx) + sizeof("/XXXXXX"));
44 + sprintf(filename, "%s/%sXXXXXX", dirname, pfx);
46 + if ((fd = mkstemp(filename)) < 0) {
52 + if (ntempfiles == 0)
53 + atexit(cleanup_tempfiles);
54 + tempfiles[ntempfiles++] = filename;
58 Index: b/lib/routines.h
59 ===================================================================
63 /* If _STR_ is not defined, give it a tempname in _TMPDIR_ */
64 #define tempname_ensure(Str) \
66 - (Str) = (Str) ? (Str) : tempnam (NULL, "a2_"); \
67 + (Str) = (Str) ? (Str) : safe_tempnam("a2_"); \
69 +char * safe_tempnam(const char *);