netpbm-security-scripts.patch 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. diff --git a/converter/other/anytopnm b/converter/other/anytopnm
  2. index acf8813..335312a 100755
  3. --- a/converter/other/anytopnm
  4. +++ b/converter/other/anytopnm
  5. @@ -511,10 +511,7 @@ else
  6. inputFile="-"
  7. fi
  8. -tempdir="${TMPDIR-/tmp}/anytopnm.$$"
  9. -mkdir -m 0700 $tempdir || \
  10. - { echo "Could not create temporary file. Exiting."; exit 1;}
  11. -trap 'rm -rf $tempdir' 0
  12. +tempdir=$(mktemp -d -t anytopnm.XXXXXXXXXX) || exit 1
  13. # Take out all spaces
  14. # Find the filename extension for last-ditch efforts later
  15. @@ -537,12 +534,17 @@ typeDescription=`file "$file" | cut -d: -f2- | cut -c2-`
  16. determineType "$file" "$mimeType" "$typeDescription" "$fileExtension"
  17. if [ "$filetype" = "unknown" ]; then
  18. - echo "$progname: unknown file type. " \
  19. - "'file' says mime type is '$mimeType', " 1>&2
  20. - echo "type description is '$typeDescription'" 1>&2
  21. + if [ -d "$tempdir" ] ; then
  22. + rm -rf "$tempdir"
  23. + fi
  24. +
  25. exit 1
  26. fi
  27. convertIt $file $filetype
  28. +if [ -d "$tempdir" ] ; then
  29. + rm -rf "$tempdir"
  30. +fi
  31. +
  32. exit 0
  33. diff --git a/editor/pamstretch-gen b/editor/pamstretch-gen
  34. index ba0e818..250fca0 100755
  35. --- a/editor/pamstretch-gen
  36. +++ b/editor/pamstretch-gen
  37. @@ -31,9 +31,7 @@ if [ "$1" = "" ]; then
  38. exit 1
  39. fi
  40. -tempdir="${TMPDIR-/tmp}/pamstretch-gen.$$"
  41. -mkdir -m 0700 $tempdir || \
  42. - { echo "Could not create temporary file. Exiting."; exit 1;}
  43. +tempfile=$(mktemp /tmp/pnmig.XXXXXXXXXX) || exit 1
  44. trap 'rm -rf $tempdir' 0 1 3 15
  45. tempfile=$tempdir/pnmig
  46. diff --git a/editor/pnmmargin b/editor/pnmmargin
  47. index 0f57d1d..e0d3625 100755
  48. --- a/editor/pnmmargin
  49. +++ b/editor/pnmmargin
  50. @@ -11,11 +11,7 @@
  51. # documentation. This software is provided "as is" without express or
  52. # implied warranty.
  53. -tempdir="${TMPDIR-/tmp}/pnmmargin.$$"
  54. -mkdir -m 0700 $tempdir || \
  55. - { echo "Could not create temporary file. Exiting." 1>&2; exit 1;}
  56. -trap 'rm -rf $tempdir' 0 1 3 15
  57. -
  58. +tempdir=$(mktemp -d -t ppmmargin.XXXXXXX) || exit 1
  59. tmp1=$tempdir/pnmm1
  60. tmp2=$tempdir/pnmm2
  61. tmp3=$tempdir/pnmm3
  62. @@ -90,6 +86,7 @@ else
  63. -white | -black )
  64. pnmpad $plainopt $color \
  65. -left=$size -right=$size -top=$size -bottom=$size $tmp1
  66. + rm -rf "$tempdir"
  67. exit
  68. ;;
  69. * )
  70. @@ -103,4 +100,4 @@ else
  71. pnmcat -tb $plainopt $tmp3 $tmp4 $tmp3
  72. fi
  73. -
  74. +rm -rf "$tempdir"
  75. diff --git a/editor/ppmfade b/editor/ppmfade
  76. index 027fc79..8eb094f 100755
  77. --- a/editor/ppmfade
  78. +++ b/editor/ppmfade
  79. @@ -40,6 +40,7 @@ exec perl -w -x -S -- "$0" "$@"
  80. #
  81. ##############################################################################
  82. use strict;
  83. +use File::Temp "tempdir";
  84. my $SPREAD = 1;
  85. my $SHIFT = 2;
  86. @@ -137,20 +138,26 @@ if ($first_file ne "undefined") {
  87. print("Frames are " . $width . "W x " . $height . "H\n");
  88. +#
  89. +# We create a tmp-directory right here
  90. +#
  91. +my $tmpdir = tempdir("ppmfade.XXXXXX", CLEANUP => 1);
  92. +
  93. +
  94. if ($first_file eq "undefined") {
  95. print "Fading from black to ";
  96. - system("ppmmake \\#000 $width $height >junk1$$.ppm");
  97. + system("ppmmake \\#000 $width $height >$tmpdir/junk1$$.ppm");
  98. } else {
  99. print "Fading from $first_file to ";
  100. - system("cp", $first_file, "junk1$$.ppm");
  101. + system("cp", $first_file, "$tmpdir/junk1$$.ppm");
  102. }
  103. if ($last_file eq "undefined") {
  104. print "black.\n";
  105. - system("ppmmake \\#000 $width $height >junk2$$.ppm");
  106. + system("ppmmake \\#000 $width $height >$tmpdir/junk2$$.ppm");
  107. } else {
  108. print "$last_file\n";
  109. - system("cp", $last_file, "junk2$$.ppm");
  110. + system("cp", $last_file, "$tmpdir/junk2$$.ppm");
  111. }
  112. #
  113. @@ -158,14 +165,14 @@ if ($last_file eq "undefined") {
  114. #
  115. # Here's what our temporary files are:
  116. -# junk1$$.ppm: The original (fade-from) image
  117. -# junk2$$.ppm: The target (fade-from) image
  118. -# junk3$$.ppm: The frame of the fade for the current iteration of the
  119. -# the for loop.
  120. -# junk1a$$.ppm: If the fade involves a ppmmix sequence from one intermediate
  121. -# image to another, this is the first frame of that
  122. -# sequence.
  123. -# junk2a$$.ppm: This is the last frame of the above-mentioned ppmmix sequence
  124. +# $tmpdir/junk1$$.ppm: The original (fade-from) image
  125. +# $tmpdir/junk2$$.ppm: The target (fade-from) image
  126. +# $tmpdir/junk3$$.ppm: The frame of the fade for the current iteration of the
  127. +# the for loop.
  128. +# $tmpdir/junk1a$$.ppm: If the fade involves a ppmmix sequence from one intermediate
  129. +# image to another, this is the first frame of that
  130. +# sequence.
  131. +# $tmpdir/junk2a$$.ppm: This is the last frame of the above-mentioned ppmmix sequence
  132. my $i; # Frame number
  133. for ($i = 1; $i <= $nframes; $i++) {
  134. @@ -173,147 +180,147 @@ for ($i = 1; $i <= $nframes; $i++) {
  135. if ($mode eq $SPREAD) {
  136. if ($i <= 10) {
  137. my $n = $spline20[$i] * 100;
  138. - system("ppmspread $n junk1$$.ppm >junk3$$.ppm");
  139. + system("ppmspread $n $tmpdir/junk1$$.ppm >$tmpdir/junk3$$.ppm");
  140. } elsif ($i <= 20) {
  141. my $n;
  142. $n = $spline20[$i] * 100;
  143. - system("ppmspread $n junk1$$.ppm >junk1a$$.ppm");
  144. + system("ppmspread $n $tmpdir/junk1$$.ppm >$tmpdir/junk1a$$.ppm");
  145. $n = (1-$spline20[$i-10]) * 100;
  146. - system("ppmspread $n junk2$$.ppm >junk2a$$.ppm");
  147. + system("ppmspread $n $tmpdir/junk2$$.ppm >$tmpdir/junk2a$$.ppm");
  148. $n = $spline10[$i-10];
  149. - system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
  150. + system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm");
  151. } else {
  152. my $n = (1-$spline20[$i-10])*100;
  153. - system("ppmspread $n junk2$$.ppm >junk3$$.ppm");
  154. + system("ppmspread $n $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
  155. }
  156. } elsif ($mode eq $SHIFT) {
  157. if ($i <= 10) {
  158. my $n = $spline20[$i] * 100;
  159. - system("ppmshift $n junk1$$.ppm >junk3$$.ppm");
  160. + system("ppmshift $n $tmpdir/junk1$$.ppm >$tmpdir/junk3$$.ppm");
  161. } elsif ($i <= 20) {
  162. my $n;
  163. $n = $spline20[$i] * 100;
  164. - system("ppmshift $n junk1$$.ppm >junk1a$$.ppm");
  165. + system("ppmshift $n $tmpdir/junk1$$.ppm >$tmpdir/junk1a$$.ppm");
  166. $n = (1-$spline20[$i-10])*100;
  167. - system("ppmshift $n junk2$$.ppm >junk2a$$.ppm");
  168. + system("ppmshift $n $tmpdir/junk2$$.ppm >$tmpdir/junk2a$$.ppm");
  169. $n = $spline10[$i-10];
  170. - system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
  171. + system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm");
  172. } else {
  173. my $n = (1-$spline20[$i-10]) * 100;
  174. - system("ppmshift $n junk2$$.ppm >junk3$$.ppm");
  175. + system("ppmshift $n $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
  176. }
  177. } elsif ($mode eq $RELIEF) {
  178. if ($i == 1) {
  179. - system("ppmrelief junk1$$.ppm >junk1r$$.ppm");
  180. + system("ppmrelief $tmpdir/junk1$$.ppm >$tmpdir/junk1r$$.ppm");
  181. }
  182. if ($i <= 10) {
  183. my $n = $spline10[$i];
  184. - system("ppmmix $n junk1$$.ppm junk1r$$.ppm >junk3$$.ppm");
  185. + system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1r$$.ppm >$tmpdir/junk3$$.ppm");
  186. } elsif ($i <= 20) {
  187. my $n = $spline10[$i-10];
  188. - system("ppmmix $n junk1r$$.ppm junk2r$$.ppm >junk3$$.ppm");
  189. + system("ppmmix $n $tmpdir/junk1r$$.ppm $tmpdir/junk2r$$.ppm >$tmpdir/junk3$$.ppm");
  190. } else {
  191. my $n = $spline10[$i-20];
  192. - system("ppmmix $n junk2r$$.ppm junk2$$.ppm >junk3$$.ppm");
  193. + system("ppmmix $n $tmpdir/junk2r$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
  194. }
  195. if ($i == 10) {
  196. - system("ppmrelief junk2$$.ppm >junk2r$$.ppm");
  197. + system("ppmrelief $tmpdir/junk2$$.ppm >$tmpdir/junk2r$$.ppm");
  198. }
  199. } elsif ($mode eq $OIL) {
  200. if ($i == 1) {
  201. - system("ppmtopgm junk1$$.ppm | pgmoil >junko$$.ppm");
  202. - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
  203. - ">junk1o$$.ppm");
  204. + system("ppmtopgm $tmpdir/junk1$$.ppm | pgmoil >$tmpdir/junko$$.ppm");
  205. + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
  206. + ">$tmpdir/junk1o$$.ppm");
  207. }
  208. if ($i <= 10) {
  209. my $n = $spline10[$i];
  210. - system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
  211. + system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm");
  212. } elsif ($i <= 20) {
  213. my $n = $spline10[$i-10];
  214. - system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
  215. + system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm");
  216. } else {
  217. my $n = $spline10[$i-20];
  218. - system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
  219. + system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
  220. }
  221. if ($i == 10) {
  222. - system("ppmtopgm junk2$$.ppm | pgmoil >junko$$.ppm");
  223. - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
  224. - ">junk2o$$.ppm");
  225. + system("ppmtopgm $tmpdir/junk2$$.ppm | pgmoil >$tmpdir/junko$$.ppm");
  226. + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
  227. + ">$tmpdir/junk2o$$.ppm");
  228. }
  229. } elsif ($mode eq $EDGE) {
  230. if ($i == 1) {
  231. - system("ppmtopgm junk1$$.ppm | pgmedge >junko$$.ppm");
  232. - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
  233. - ">junk1o$$.ppm");
  234. + system("ppmtopgm $tmpdir/junk1$$.ppm | pgmedge >$tmpdir/junko$$.ppm");
  235. + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
  236. + ">$tmpdir/junk1o$$.ppm");
  237. }
  238. if ($i <= 10) {
  239. my $n = $spline10[$i];
  240. - system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
  241. + system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm");
  242. } elsif ($i <= 20) {
  243. my $n = $spline10[$i-10];
  244. - system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
  245. + system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm");
  246. } else {
  247. my $n = $spline10[$i-20];
  248. - system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
  249. + system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
  250. }
  251. if ($i == 10) {
  252. - system("ppmtopgm junk2$$.ppm | pgmedge >junko$$.ppm");
  253. - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
  254. - ">junk2o$$.ppm");
  255. + system("ppmtopgm $tmpdir/junk2$$.ppm | pgmedge >$tmpdir/junko$$.ppm");
  256. + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
  257. + ">$tmpdir/junk2o$$.ppm");
  258. }
  259. } elsif ($mode eq $BENTLEY) {
  260. if ($i == 1) {
  261. - system("ppmtopgm junk1$$.ppm | pgmbentley >junko$$.ppm");
  262. - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
  263. - ">junk1o$$.ppm");
  264. + system("ppmtopgm $tmpdir/junk1$$.ppm | pgmbentley >$tmpdir/junko$$.ppm");
  265. + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
  266. + ">$tmpdir/junk1o$$.ppm");
  267. }
  268. if ($i <= 10) {
  269. my $n = $spline10[$i];
  270. - system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
  271. + system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm");
  272. } elsif ($i <= 20) {
  273. my $n = $spline10[$i-10];
  274. - system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
  275. + system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm");
  276. } else {
  277. my $n = $spline10[$i-20];
  278. - system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
  279. + system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
  280. }
  281. if ($i == 10) {
  282. - system("ppmtopgm junk2$$.ppm | pgmbentley >junko$$.ppm");
  283. - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
  284. - ">junk2o$$.ppm");
  285. + system("ppmtopgm $tmpdir/junk2$$.ppm | pgmbentley >$tmpdir/junko$$.ppm");
  286. + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
  287. + ">$tmpdir/junk2o$$.ppm");
  288. }
  289. } elsif ($mode eq $BLOCK) {
  290. if ($i <= 10) {
  291. my $n = 1 - 1.9*$spline20[$i];
  292. - system("pamscale $n junk1$$.ppm | " .
  293. - "pamscale -width $width -height $height >junk3$$.ppm");
  294. + system("pamscale $n $tmpdir/junk1$$.ppm | " .
  295. + "pamscale -width $width -height $height >$tmpdir/junk3$$.ppm");
  296. } elsif ($i <= 20) {
  297. my $n = $spline10[$i-10];
  298. - system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
  299. + system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm");
  300. } else {
  301. my $n = 1 - 1.9*$spline20[31-$i];
  302. - system("pamscale $n junk2$$.ppm | " .
  303. - "pamscale -width $width -height $height >junk3$$.ppm");
  304. + system("pamscale $n $tmpdir/junk2$$.ppm | " .
  305. + "pamscale -width $width -height $height >$tmpdir/junk3$$.ppm");
  306. }
  307. if ($i == 10) {
  308. - system("cp", "junk3$$.ppm", "junk1a$$.ppm");
  309. - system("pamscale $n junk2$$.ppm | " .
  310. - "pamscale -width $width -height $height >junk2a$$.ppm");
  311. + system("cp", "$tmpdir/junk3$$.ppm", "$tmpdir/junk1a$$.ppm");
  312. + system("pamscale $n $tmpdir/junk2$$.ppm | " .
  313. + "pamscale -width $width -height $height >$tmpdir/junk2a$$.ppm");
  314. }
  315. } elsif ($mode eq $MIX) {
  316. my $fade_factor = sqrt(1/($nframes-$i+1));
  317. - system("ppmmix $fade_factor junk1$$.ppm junk2$$.ppm >junk3$$.ppm");
  318. + system("ppmmix $fade_factor $tmpdir/junk1$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
  319. } else {
  320. print("Internal error: impossible mode value '$mode'\n");
  321. }
  322. my $outfile = sprintf("%s.%04d.ppm", $base_name, $i);
  323. - system("cp", "junk3$$.ppm", $outfile);
  324. + system("cp", "$tmpdir/junk3$$.ppm", $outfile);
  325. }
  326. #
  327. # Clean up shop.
  328. #
  329. -system("rm junk*$$.ppm");
  330. +system("rm $tmpdir/junk*$$.ppm");
  331. exit(0);
  332. diff --git a/editor/ppmshadow b/editor/ppmshadow
  333. index 62cdf8b..72e1b22 100755
  334. --- a/editor/ppmshadow
  335. +++ b/editor/ppmshadow
  336. @@ -97,9 +97,10 @@ sub makeConvolutionKernel($$) {
  337. my $tmpdir = $ENV{TMPDIR} || "/tmp";
  338. -my $ourtmp = "$tmpdir/ppmshadow$$";
  339. -mkdir($ourtmp, 0777) or
  340. - die("Unable to create directory for temporary files '$ourtmp");
  341. +my $ourtmp; chomp($ourtmp = `mktemp -d -t PPMshadow.XXXXXX`);
  342. +if ($? >> 8) {
  343. + die "Can't create directory for temporary files";
  344. +}
  345. # Process command line options