OCaml 4.14.0 rebuild
[arch-packages.git] / a2ps / trunk / a2ps-4.13-security.patch
blobcff6225355a5113278a55f0478096ae66a92fe3b
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
3 @@ -242,3 +242,50 @@
4 /* Don't complain if you can't unlink. Who cares of a tmp file? */
5 unlink (filename);
8 +/*
9 + * Securely generate a temp file, and make sure it gets
10 + * deleted upon exit.
11 + */
12 +static char ** tempfiles;
13 +static unsigned ntempfiles;
15 +static void
16 +cleanup_tempfiles()
18 + while (ntempfiles--)
19 + unlink(tempfiles[ntempfiles]);
22 +char *
23 +safe_tempnam(const char *pfx)
25 + char *dirname, *filename;
26 + int fd;
28 + if (!(dirname = getenv("TMPDIR")))
29 + dirname = "/tmp";
31 + tempfiles = (char **) realloc(tempfiles,
32 + (ntempfiles+1) * sizeof(char *));
33 + if (tempfiles == NULL)
34 + return NULL;
36 + filename = malloc(strlen(dirname) + strlen(pfx) + sizeof("/XXXXXX"));
37 + if (!filename)
38 + return NULL;
40 + sprintf(filename, "%s/%sXXXXXX", dirname, pfx);
42 + if ((fd = mkstemp(filename)) < 0) {
43 + free(filename);
44 + return NULL;
45 + }
46 + close(fd);
48 + if (ntempfiles == 0)
49 + atexit(cleanup_tempfiles);
50 + tempfiles[ntempfiles++] = filename;
52 + return 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
56 @@ -255,7 +255,8 @@
57 /* If _STR_ is not defined, give it a tempname in _TMPDIR_ */
58 #define tempname_ensure(Str) \
59 do { \
60 - (Str) = (Str) ? (Str) : tempnam (NULL, "a2_"); \
61 + (Str) = (Str) ? (Str) : safe_tempnam("a2_"); \
62 } while (0)
63 +char * safe_tempnam(const char *);
65 #endif