Merge branch 'vendor/OPENSSH'
[dragonfly.git] / gnu / usr.bin / texinfo / texindex / texindex.c.patch
1 $DragonFly: src/gnu/usr.bin/texinfo/texindex/texindex.c.patch,v 1.1 2006/02/11 01:21:27 joerg Exp $
2 Security fix for CAN-2005-3001.
3
4 Index: texindex.c
5 ===================================================================
6 RCS file: /cvs/src/contrib/texinfo-4/util/texindex.c,v
7 retrieving revision 1.1
8 diff -u -r1.1 texindex.c
9 --- texindex.c  28 Aug 2005 12:23:25 -0000      1.1
10 +++ texindex.c  11 Feb 2006 01:11:08 -0000
11 @@ -387,14 +387,15 @@
12  /* Return a name for temporary file COUNT. */
13  
14  static char *
15 -maketempname (int count)
16 +maketempname (int count, int can_exist)
17  {
18    static char *tempbase = NULL;
19 +  char *tempname;
20    char tempsuffix[10];
21 +  int fd;
22  
23    if (!tempbase)
24      {
25 -      int fd;
26        tempbase = concat (tempdir, "txidxXXXXXX");
27  
28        fd = mkstemp (tempbase);
29 @@ -403,7 +404,14 @@
30      }
31  
32    sprintf (tempsuffix, ".%d", count);
33 -  return concat (tempbase, tempsuffix);
34 +  tempname = concat (tempbase, tempsuffix);
35 +  if (!can_exist) {
36 +    fd = open (tempname, O_CREAT|O_EXCL|O_WRONLY, 0600);
37 +    if (fd == -1)
38 +      pfatal_with_name (tempname);
39 +    close (fd);
40 +  }
41 +  return tempname;
42  }
43  
44  
45 @@ -415,7 +423,7 @@
46    if (keep_tempfiles)
47      return;
48    while (last_deleted_tempcount < to_count)
49 -    unlink (maketempname (++last_deleted_tempcount));
50 +    unlink (maketempname (++last_deleted_tempcount, 1));
51  }
52  
53  \f
54 @@ -882,7 +890,7 @@
55  
56    for (i = 0; i < ntemps; i++)
57      {
58 -      char *outname = maketempname (++tempcount);
59 +      char *outname = maketempname (++tempcount, 0);
60        FILE *ostream = fopen (outname, "w");
61        long tempsize = 0;
62  
63 @@ -930,7 +938,7 @@
64  
65    for (i = 0; i < ntemps; i++)
66      {
67 -      char *newtemp = maketempname (++tempcount);
68 +      char *newtemp = maketempname (++tempcount, 0);
69        sort_in_core (tempfiles[i], MAX_IN_CORE_SORT, newtemp);
70        if (!keep_tempfiles)
71          unlink (tempfiles[i]);
72 @@ -1400,7 +1408,7 @@
73        int nf = MAX_DIRECT_MERGE;
74        if (i + 1 == ntemps)
75          nf = nfiles - i * MAX_DIRECT_MERGE;
76 -      tempfiles[i] = maketempname (++tempcount);
77 +      tempfiles[i] = maketempname (++tempcount, 0);
78        value |= merge_direct (&infiles[i * MAX_DIRECT_MERGE], nf, tempfiles[i]);
79      }
80