~ubuntu-branches/ubuntu/natty/texinfo/natty

« back to all changes in this revision

Viewing changes to debian/patches/30_texindex_racecondition.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Frank Küster
  • Date: 2006-11-22 12:04:54 UTC
  • mfrom: (2.1.6 feisty)
  • Revision ID: james.westby@ubuntu.com-20061122120454-g1z6y312bcimvxe2
Tags: 4.8.dfsg.1-4
* Apply patch by Josh Bressers <bressers@redhat.com> to fix
  CVE-2006-4810, added as 33_texindex_CVE-2006-4810.dpatch
* Add myself to Uploaders so this doesn't look like an NMU.  

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## 30_texindex_racecondition.dpatch by Henry Jensen <jensen@scan-plus.de>
 
3
## and Norbert Preining <preining@logic.at>
 
4
## backport of cvs fixes
 
5
##
 
6
## All lines beginning with `## DP:' are a description of the patch.
 
7
## DP: No description.
 
8
 
 
9
@DPATCH@
 
10
--- branches/upstream/current/util/texindex.c   2005-09-30 11:28:05.000000000 +0200
 
11
+++ texinfo-cvs/util/texindex.c 2005-10-06 08:35:26.000000000 +0200
 
12
@@ -99,6 +99,9 @@
 
13
 /* Directory to use for temporary files.  On Unix, it ends with a slash.  */
 
14
 char *tempdir;
 
15
 
 
16
+/* Start of filename to use for temporary files.  */
 
17
+char *tempbase;
 
18
+
 
19
 /* Number of last temporary file.  */
 
20
 int tempcount;
 
21
 
 
22
@@ -144,7 +147,7 @@
 
23
 void fatal (const char *format, const char *arg);
 
24
 void error (const char *format, const char *arg);
 
25
 void *xmalloc (), *xrealloc ();
 
26
-char *concat (char *s1, char *s2);
 
27
+static char *concat3 (const char *, const char *, const char *);
 
28
 void flush_tempfiles (int to_count);
 
29
 
 
30
 #define MAX_IN_CORE_SORT 500000
 
31
@@ -190,6 +193,11 @@
 
32
 
 
33
   decode_command (argc, argv);
 
34
 
 
35
+  /* XXX mkstemp not appropriate, as we need to have somewhat predictable
 
36
+   * names. But race condition was fixed, see maketempname.
 
37
+   */
 
38
+  tempbase = mktemp (concat3 ("txiXXXXXX", "", ""));
 
39
+
 
40
   /* Process input files completely, one by one.  */
 
41
 
 
42
   for (i = 0; i < num_infiles; i++)
 
43
@@ -220,7 +228,7 @@
 
44
 
 
45
       outfile = outfiles[i];
 
46
       if (!outfile)
 
47
-        outfile = concat (infiles[i], "s");
 
48
+        outfile = concat3 (infiles[i], "s", "");
 
49
 
 
50
       need_initials = 0;
 
51
       first_initial = '\0';
 
52
@@ -318,7 +326,7 @@
 
53
   if (tempdir == NULL)
 
54
     tempdir = DEFAULT_TMPDIR;
 
55
   else
 
56
-    tempdir = concat (tempdir, "/");
 
57
+    tempdir = concat3 (tempdir, "/", "");
 
58
 
 
59
   keep_tempfiles = 0;
 
60
 
 
61
@@ -384,26 +395,25 @@
 
62
     usage (1);
 
63
 }
 
64
 
 
65
-/* Return a name for temporary file COUNT. */
 
66
+/* Return a name for temporary file COUNT, or NULL if failure. */
 
67
 
 
68
 static char *
 
69
 maketempname (int count)
 
70
 {
 
71
-  static char *tempbase = NULL;
 
72
   char tempsuffix[10];
 
73
+  char *name;
 
74
+  int fd;
 
75
 
 
76
-  if (!tempbase)
 
77
+  sprintf (tempsuffix, ".%d", count);
 
78
+  name =  concat3 (tempdir, tempbase, tempsuffix);
 
79
+  fd = open (name, O_CREAT|O_EXCL|O_WRONLY, 0600);
 
80
+  if (fd == -1)
 
81
+    return NULL;
 
82
+  else
 
83
     {
 
84
-      int fd;
 
85
-      tempbase = concat (tempdir, "txidxXXXXXX");
 
86
-
 
87
-      fd = mkstemp (tempbase);
 
88
-      if (fd == -1)
 
89
-        pfatal_with_name (tempbase);
 
90
+      close(fd);
 
91
+      return(name);
 
92
     }
 
93
-
 
94
-  sprintf (tempsuffix, ".%d", count);
 
95
-  return concat (tempbase, tempsuffix);
 
96
 }
 
97
 
 
98
 
 
99
@@ -931,6 +941,8 @@
 
100
   for (i = 0; i < ntemps; i++)
 
101
     {
 
102
       char *newtemp = maketempname (++tempcount);
 
103
+      if (!newtemp)
 
104
+        pfatal_with_name("temp file");
 
105
       sort_in_core (tempfiles[i], MAX_IN_CORE_SORT, newtemp);
 
106
       if (!keep_tempfiles)
 
107
         unlink (tempfiles[i]);
 
108
@@ -1401,6 +1413,8 @@
 
109
       if (i + 1 == ntemps)
 
110
         nf = nfiles - i * MAX_DIRECT_MERGE;
 
111
       tempfiles[i] = maketempname (++tempcount);
 
112
+      if (!tempfiles[i])
 
113
+       pfatal_with_name("temp file");
 
114
       value |= merge_direct (&infiles[i * MAX_DIRECT_MERGE], nf, tempfiles[i]);
 
115
     }
 
116
 
 
117
@@ -1612,17 +1626,18 @@
 
118
 }
 
119
 
 
120
 
 
121
-/* Return a newly-allocated string concatenating S1 and S2.  */
 
122
+/* Return a newly-allocated string concatenating S1, S2, and S3.  */
 
123
 
 
124
-char *
 
125
-concat (char *s1, char *s2)
 
126
+static char *
 
127
+concat3 (const char *s1, const char *s2, const char *s3)
 
128
 {
 
129
-  int len1 = strlen (s1), len2 = strlen (s2);
 
130
-  char *result = (char *) xmalloc (len1 + len2 + 1);
 
131
+  int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
 
132
+  char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
 
133
 
 
134
   strcpy (result, s1);
 
135
   strcpy (result + len1, s2);
 
136
-  *(result + len1 + len2) = 0;
 
137
+  strcpy (result + len1 + len2, s3);
 
138
+  *(result + len1 + len2 + len3) = 0;
 
139
 
 
140
   return result;
 
141
 }