1 ftp://ftp.freebsd.org/pub/FreeBSD/CERT/advisories/FreeBSD-SA-06:01.texindex.asc
3 Index: contrib/texinfo/util/texindex.c
4 ===================================================================
5 RCS file: /home/ncvs/src/contrib/texinfo/util/texindex.c,v
6 retrieving revision 1.1.1.8
7 diff -u -p -I__FBSDID -r1.1.1.8 texindex.c
8 --- contrib/texinfo/util/texindex.c 23 May 2005 10:46:22 -0000 1.1.1.8
9 +++ contrib/texinfo/util/texindex.c 8 Jan 2006 23:31:32 -0000
10 @@ -384,17 +384,33 @@ For more information about these matters
19 +findtempname (char *tempname)
23 + for (i = 0; i < tv_used; i++)
24 + if (strcmp (tv[i], tempname) == 0)
29 /* Return a name for temporary file COUNT. */
32 maketempname (int count)
34 static char *tempbase = NULL;
42 tempbase = concat (tempdir, "txidxXXXXXX");
44 fd = mkstemp (tempbase);
45 @@ -403,7 +419,52 @@ maketempname (int count)
48 sprintf (tempsuffix, ".%d", count);
49 - return concat (tempbase, tempsuffix);
50 + tempname = concat (tempbase, tempsuffix);
52 + * The open logic becomes a bit convoluted. If open(2) fails due to EEXIST,
53 + * it's likely because somebody attempted to race us, or because we have
54 + * already created this file.
56 + fd = open (tempname, O_CREAT|O_EXCL|O_WRONLY, 0600);
60 + * If errno is not EEXIST, then open failed for some other reason, so
61 + * we should terminate. If errno == EEXIST AND we didn't create this
62 + * file, terminate. Otherwise, it's safe to say that errno == EEXIST
63 + * because we already created it, in this event, we can just return.
65 + if (errno != EEXIST ||
66 + (errno == EEXIST && findtempname (tempname) == 0))
67 + pfatal_with_name (tempname);
77 + tv = calloc (tv_alloc, sizeof (char *));
80 + fprintf (stderr, "calloc failed\n");
84 + else if (tv_used == tv_alloc)
87 + tv = realloc (tv, tv_alloc * sizeof (char *));
90 + fprintf (stderr, "realloc failed");
94 + tv[tv_used++] = strdup (tempname);