mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB

  1. Copied from www.linuxfromscratch.org to ROCK Linux.
  2. Updated By: Bruce Dubbs (bdubbs -aT- linuxfromscratch -DoT- org)
  3. Date: 2005-12-12
  4. Submitted By: Archaic (archaic -aT- linuxfromscratch -DoT- org)
  5. Date: 2005-10-08
  6. Initial Package Version: 4.8
  7. Origin: http://gentoo.kems.net/gentoo-portage/sys-apps/texinfo/files/texinfo-4.8-tempfile.patch
  8. Upstream Status: A few patches are floating around in Debian BZ #328365 of which
  9. upstream hasn't made a full commitment on yet.
  10. Description: (CAN-2005-3011) texindex in texinfo 4.8 and earlier allows local
  11. users to overwrite arbitrary files via a symlink attack on
  12. temporary files.
  13. Update: Changed to not pass a constant string to mktemp().
  14. diff -Naur texinfo-4.9.orig/util/texindex.c texinfo-4.9/util/texindex.c
  15. --- texinfo-4.9.orig/util/texindex.c 2007-07-23 07:11:38.000000000 -0400
  16. +++ texinfo-4.9/util/texindex.c 2007-07-23 07:11:49.000000000 -0400
  17. @@ -99,6 +99,9 @@
  18. /* Directory to use for temporary files. On Unix, it ends with a slash. */
  19. char *tempdir;
  20. +/* Basename for temp files inside of tempdir. */
  21. +char *tempbase;
  22. +
  23. /* Number of last temporary file. */
  24. int tempcount;
  25. @@ -153,6 +156,7 @@
  26. main (int argc, char **argv)
  27. {
  28. int i;
  29. + char template[]="txidxXXXXXX";
  30. tempcount = 0;
  31. last_deleted_tempcount = 0;
  32. @@ -190,6 +194,11 @@
  33. decode_command (argc, argv);
  34. + /* XXX mkstemp not appropriate, as we need to have somewhat predictable
  35. + * names. But race condition was fixed, see maketempname.
  36. + */
  37. + tempbase = mktemp (template);
  38. +
  39. /* Process input files completely, one by one. */
  40. for (i = 0; i < num_infiles; i++)
  41. @@ -390,21 +399,21 @@
  42. static char *
  43. maketempname (int count)
  44. {
  45. - static char *tempbase = NULL;
  46. char tempsuffix[10];
  47. -
  48. - if (!tempbase)
  49. - {
  50. - int fd;
  51. - tempbase = concat (tempdir, "txidxXXXXXX");
  52. -
  53. - fd = mkstemp (tempbase);
  54. - if (fd == -1)
  55. - pfatal_with_name (tempbase);
  56. - }
  57. + char *name, *tmp_name;
  58. + int fd;
  59. sprintf (tempsuffix, ".%d", count);
  60. - return concat (tempbase, tempsuffix);
  61. + tmp_name = concat (tempdir, tempbase);
  62. + name = concat (tmp_name, tempsuffix);
  63. + free(tmp_name);
  64. +
  65. + fd = open (name, O_CREAT|O_EXCL|O_WRONLY, 0600);
  66. + if (fd == -1)
  67. + pfatal_with_name (name);
  68. +
  69. + close(fd);
  70. + return name;
  71. }