noweb-2.9-insecure-tmp-file.patch.input 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. --- awkname
  2. +++ awkname
  3. @@ -5,7 +5,7 @@
  4. esac
  5. rc=0
  6. -new=/tmp/$$.new; old=/tmp/$$.old
  7. +new=$(tempfile -p new); old=$(tempfile -p old)
  8. for file in lib/emptydefn lib/unmarkup lib/toascii \
  9. awk/noidx awk/totex awk/tohtml awk/noindex \
  10. --- awk/totex.nw
  11. +++ awk/totex.nw
  12. @@ -24,7 +24,7 @@
  13. @
  14. On an ugly system, we have to put it in a file.
  15. <<invoke awk program using file>>=
  16. -awkfile=/tmp/totex$$.awk
  17. +awkfile=$(tempfile -p totex)
  18. trap 'rm -f $awkfile; exit 1' 0 1 2 15 # clean up files
  19. cat > $awkfile << 'EOF'
  20. <<awk program for conversion to {\TeX}>>
  21. --- lib/toascii
  22. +++ lib/toascii
  23. @@ -7,9 +7,9 @@
  24. *) echo "This can't happen -- $i passed to toascii" 1>&2 ; exit 1 ;;
  25. esac
  26. done
  27. -awkfile="tmp/awk$$.tmp"
  28. -textfile="/tmp/text$$.tmp"
  29. -tagsfile="/tmp/tags$$.tmp"
  30. +awkfile=$(tempfile -p awk -s .tmp)
  31. +textfile=$(tempfile -p text -s .tmp)
  32. +tagsfile=$(tempfile -p tags -s .tmp)
  33. export awkfile textfile tagsfile
  34. trap 'rm -f $awkfile $textfile $tagsfile' 0 1 2 10 14 15
  35. nawk 'BEGIN { textfile=ENVIRON["textfile"]
  36. --- shell/cpif
  37. +++ shell/cpif
  38. @@ -17,7 +17,7 @@
  39. 0) echo 'Usage: '`basename $0`' [ -eq -ne ] file...' 1>&2; exit 2
  40. esac
  41. -new=/tmp/$$
  42. +new=$(tempfile)
  43. trap 'rm -f $new; exit 1' 1 2 15 # clean up files
  44. cat >$new
  45. --- shell/nonu
  46. +++ shell/nonu
  47. @@ -2,7 +2,7 @@
  48. LIB=/usr/public/pkg/noweb/lib
  49. # attempt to convert nuweb to noweb using sam
  50. -tmp=/tmp/nonu$$
  51. +tmp=$(tempfile -p nonu)
  52. trap '/bin/rm -f $tmp; exit 1' 1 2 15 # clean up files
  53. cp $1 $tmp || exit 1
  54. --- shell/roff.nw
  55. +++ shell/roff.nw
  56. @@ -80,7 +80,7 @@
  57. other, and quoting each quote is ugly. The pragmatic solution is to
  58. copy the awk program into a temporary file, using a shell here-document.
  59. <<invoke awk program>>=
  60. -awkfile="/tmp/noweb$$.awk"
  61. +awkfile=$(tempfile -p noweb -s .awk)
  62. trap 'rm -f $awkfile' 0 1 2 10 14 15
  63. cat > $awkfile << 'EOF'
  64. <<awk program>>
  65. @@ -662,12 +662,13 @@
  66. base="`basename $1 | sed '/\./s/\.[^.]*$//'`"
  67. tagsfile="$base.nwt"
  68. +tmpfile=$(tempfile -p tags)
  69. (echo ".so $macrodir/tmac.w"
  70. if [ -r "$tagsfile" ]; then
  71. - cp $tagsfile /tmp/tags.$$
  72. + cp $tagsfile $tmpfile
  73. $AWK '<<action for [[tags]] line>>
  74. - <<functions>>' /tmp/tags.$$
  75. - rm -f /tmp/tags.$$
  76. + <<functions>>' $tmpfile
  77. + rm -f $tmpfile
  78. fi
  79. cat "$@") |
  80. ($ROFF $opts 2>$tagsfile)
  81. --- shell/noroff
  82. +++ shell/noroff
  83. @@ -35,9 +35,10 @@
  84. base="`basename $1 | sed '/\./s/\.[^.]*$//'`"
  85. tagsfile="$base.nwt"
  86. +tmpfile=$(tempfile -p tags)
  87. (echo ".so $macrodir/tmac.w"
  88. if [ -r "$tagsfile" ]; then
  89. - cp $tagsfile /tmp/tags.$$
  90. + cp $tagsfile $tmpfile
  91. $AWK '{
  92. if (sub(/^###TAG### / , "")) tags[$1] = $2
  93. else if (sub(/^###BEGINCHUNKS###/, "")) printf ".de CLIST\n.CLISTBEGIN\n"
  94. @@ -88,8 +89,8 @@
  95. # print str3
  96. # print convquote(str3)
  97. # }
  98. - function tag(s) { if (s in tags) return tags[s]; else return "???" }' /tmp/tags.$$
  99. - rm -f /tmp/tags.$$
  100. + function tag(s) { if (s in tags) return tags[s]; else return "???" }' $tmpfile
  101. + rm -f $tmpfile
  102. fi
  103. cat "$@") |
  104. ($ROFF $opts 2>$tagsfile)
  105. --- shell/toroff
  106. +++ shell/toroff
  107. @@ -9,7 +9,7 @@
  108. exit 1;;
  109. esac
  110. done
  111. -awkfile="/tmp/noweb$$.awk"
  112. +awkfile=$(tempfile -p noweb -s .awk)
  113. trap 'rm -f $awkfile' 0 1 2 10 14 15
  114. cat > $awkfile << 'EOF'
  115. /^@begin docs 0$/ { if (delay) next }
  116. --- lib/toascii.nw
  117. +++ lib/toascii.nw
  118. @@ -28,9 +28,9 @@
  119. Also arranged here is a temporary file for storage of the awk program on an
  120. ugly system, as discussed below.
  121. <<arrange temporary files>>=
  122. -awkfile="tmp/awk$$.tmp"
  123. -textfile="/tmp/text$$.tmp"
  124. -tagsfile="/tmp/tags$$.tmp"
  125. +awkfile=$(tempfile -p awk -s .tmp) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
  126. +textfile=$(tempfile -p text -s .tmp) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
  127. +tagsfile=$(tempfile -p tags -s .tmp) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
  128. export awkfile textfile tagsfile
  129. trap 'rm -f $awkfile $textfile $tagsfile' 0 1 2 10 14 15
  130. @ %def textfile tagsfile awkfile
  131. --- shell/roff.mm
  132. +++ shell/roff.mm
  133. @@ -214,7 +214,7 @@
  134. .ADDLIST 1a
  135. .PRINTLIST
  136. -awkfile="/tmp/noweb$$.awk"
  137. +awkfile=$(tempfile -p noweb -s .awk) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
  138. trap 'rm -f $awkfile' 0 1 2 10 14 15
  139. cat > $awkfile \&<< 'EOF'
  140. \c
  141. @@ -1628,14 +1628,15 @@
  142. tagsfile="$base.nwt"
  143. (echo ".so $macrodir/tmac.w"
  144. if [ -r "$tagsfile" ]; then
  145. - cp $tagsfile /tmp/tags.$$
  146. + tagstemp=$(tempfile -p tags) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
  147. + cp $tagsfile $tagstemp
  148. $AWK '\c
  149. .USE "action for \*[BEGINCONVQUOTE]tags\*[ENDCONVQUOTE] line" 11c
  150. \&
  151. \c
  152. .USE "functions" 8a
  153. -\&' /tmp/tags.$$
  154. - rm -f /tmp/tags.$$
  155. +\&' $tagstemp
  156. + rm -f $tagstemp
  157. fi
  158. cat "$@") |
  159. ($ROFF $opts 2>$tagsfile)