]> git.pld-linux.org Git - packages/a2ps.git/blame - a2ps-security.patch
- build it with libpaper (s/BC: libpaper-devel/BR: libpaper-devel)
[packages/a2ps.git] / a2ps-security.patch
CommitLineData
bdc5d0e5 1--- a2ps-4.13/lib/routines.c~ 1999-10-16 06:46:37.000000000 +0200
2+++ a2ps-4.13/lib/routines.c 2003-08-21 09:58:57.361425544 +0200
3@@ -242,3 +242,50 @@
4 /* Don't complain if you can't unlink. Who cares of a tmp file? */
5 unlink (filename);
6 }
7+
8+/*
9+ * Securely generate a temp file, and make sure it gets
10+ * deleted upon exit.
11+ */
12+static char ** tempfiles = NULL;
13+static unsigned ntempfiles = 0;
14+
15+static void
16+cleanup_tempfiles()
17+{
18+ while (ntempfiles--)
19+ unlink(tempfiles[ntempfiles]);
20+}
21+
22+char *
23+safe_tempnam(const char *pfx)
24+{
25+ char *dirname, *filename;
26+ int fd;
27+
28+ if (!(dirname = getenv("TMPDIR")))
29+ dirname = "/tmp";
30+
31+ tempfiles = (char **) realloc(tempfiles,
32+ (ntempfiles+1) * sizeof(char *));
33+ if (tempfiles == NULL)
34+ return NULL;
35+
36+ filename = malloc(strlen(dirname) + strlen(pfx) + sizeof("/XXXXXX"));
37+ if (!filename)
38+ return NULL;
39+
40+ sprintf(filename, "%s/%sXXXXXX", dirname, pfx);
41+
42+ if ((fd = mkstemp(filename)) < 0) {
43+ free(filename);
44+ return NULL;
45+ }
46+ close(fd);
47+
48+ if (ntempfiles == 0)
49+ atexit(cleanup_tempfiles);
50+ tempfiles[ntempfiles++] = filename;
51+
52+ return filename;
53+}
54--- a2ps-4.13/lib/routines.h~ 1999-10-18 22:24:41.000000000 +0200
55+++ a2ps-4.13/lib/routines.h 2003-08-21 09:55:11.500761584 +0200
56@@ -255,7 +255,7 @@
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-
64+char * safe_tempnam(const char *);
65 #endif
This page took 0.039523 seconds and 4 git commands to generate.