]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blob - pkgs/make/patches/make-3.81-fdleak.patch
Change file layout of the makefiles.
[people/amarx/ipfire-3.x.git] / pkgs / make / patches / make-3.81-fdleak.patch
1 diff -urp make-3.81/read.c make-3.81-leak/read.c
2 --- make-3.81/read.c 2006-03-17 15:24:20.000000000 +0100
3 +++ make-3.81-leak/read.c 2008-09-16 16:43:12.000000000 +0200
4 @@ -296,6 +300,37 @@ restore_conditionals (struct conditional
5 conditionals = saved;
6 }
7 \f
8 +/* If possible, open the file and mark it close-on-exec, so that make
9 + doesn't leak the descriptor to binaries called via $(shell ...).*/
10 +static FILE *
11 +open_makefile (char *filename)
12 +{
13 + FILE *fp;
14 +
15 +#if HAVE_FDOPEN
16 + int fd = open (filename, O_RDONLY);
17 + int save;
18 + if (fd < 0)
19 + return NULL;
20 +
21 + fp = fdopen (fd, "r");
22 + if (fp == NULL)
23 + {
24 + save = errno;
25 + close (fd);
26 + errno = save;
27 + return NULL;
28 + }
29 +
30 + CLOSE_ON_EXEC (fd);
31 +
32 +#else
33 + fp = fopen (filename, "r");
34 +#endif
35 +
36 + return fp;
37 +}
38 +
39 static int
40 eval_makefile (char *filename, int flags)
41 {
42 @@ -335,7 +376,8 @@ eval_makefile (char *filename, int flags
43 filename = expanded;
44 }
45
46 - ebuf.fp = fopen (filename, "r");
47 + ebuf.fp = open_makefile (filename);
48 +
49 /* Save the error code so we print the right message later. */
50 makefile_errno = errno;
51
52 @@ -348,7 +390,7 @@ eval_makefile (char *filename, int flags
53 for (i = 0; include_directories[i] != 0; ++i)
54 {
55 included = concat (include_directories[i], "/", filename);
56 - ebuf.fp = fopen (included, "r");
57 + ebuf.fp = open_makefile (included);
58 if (ebuf.fp)
59 {
60 filename = included;