--- sgml-tools-1.0.9/lib/SGMLTools/Utils.pm.tmpfile Thu Mar 8 09:54:40 2001 +++ sgml-tools-1.0.9/lib/SGMLTools/Utils.pm Thu Mar 8 09:56:42 2001 @@ -319,6 +319,7 @@ } chdir($savdir); + rmdir($tmpdir) || return -1; } =item trap_signals --- sgml-tools-1.0.9/lib/dist/fmt_latex2e.pl.tmpfile Thu Mar 8 09:56:52 2001 +++ sgml-tools-1.0.9/lib/dist/fmt_latex2e.pl Thu Mar 8 10:09:27 2001 @@ -156,8 +156,12 @@ { my $infile = shift; my $filename = $global->{filename}; + my $tmplatexdir = $global->{tmpbase} . ".dir"; + my $tmplatexnam = $tmplatexdir . "/" . $filename; $ENV{TEXINPUTS} .= ":$main::LibDir"; + mkdir ($tmplatexdir, 0750) || return -1; + # # Set the correct \documentclass options. The if statement is just # a small optimization. @@ -167,7 +171,7 @@ my $langlit = ISO2English ($global->{language}); $langlit = ",$langlit"; my $replace = $global->{papersize} . 'paper' . $langlit; - open OUTFILE, ">$filename.tex"; + open OUTFILE, ">$tmplatexnam.tex"; while (<$infile>) { if (/^\\documentclass/) @@ -194,7 +198,7 @@ } else { - copy ($infile, "$filename.tex"); + copy ($infile, "$tmplatexnam.tex"); } # @@ -202,6 +206,10 @@ # if ($latex2e->{output} eq "tex") { + copy ("$tmplatexnam.tex", "$filename.tex"); + unlink ("$tmplatexnam.tex"); + rmdir ($tmplatexdir) || return -1; + return 0; } @@ -211,11 +219,17 @@ # references have been resolved. This avoids large numbers of # spurious warnings. # - my ($latexcommand) = "latex '\\nonstopmode\\input{$filename.tex}'"; + my $current_dir; + chop ($current_dir = `pwd`); + # + # go to the temporary directory + chdir ($tmplatexdir); + + my ($latexcommand) = "latex '\\nonstopmode\\input{$tmplatexnam.tex}'"; my ($suppress) = $latex2e->{quick} ? "" : ' >/dev/null'; system $latexcommand . $suppress || die "LaTeX problem\n"; - $latex2e->{bibtex} && system "bibtex $filename.tex"; + $latex2e->{bibtex} && system "bibtex $tmplatexnam.tex"; $latex2e->{quick} || system $latexcommand . ' >/dev/null'; $latex2e->{quick} || system $latexcommand; if ($global->{debug} == 0) @@ -223,16 +237,32 @@ my @suffixes = qw(log blg aux toc lof lot dlog bbl); for my $suf (@suffixes) { - unlink "$filename.$suf"; + unlink "$tmplatexnam.$suf"; } } + # + # go back to the working directory + chdir ($current_dir); + # + # output dvi file if ($latex2e->{output} eq "dvi") { - $global->{debug} || unlink "$filename.tex"; + copy ("$tmplatexnam.dvi", "$filename.dvi"); + unless ( $global->{debug} ) + { + unlink ("$tmplatexnam.tex","$tmplatexnam.dvi"); + rmdir ($tmplatexdir) || return -1; + } return 0; } - `dvips -q -t $global->{papersize} -o $filename.ps $filename.dvi`; - $global->{debug} || unlink ("$filename.dvi", "$filename.tex"); + `dvips -q -t $global->{papersize} -o $tmplatexnam.ps $tmplatexnam.dvi`; + copy ("$tmplatexnam.ps", "$filename.ps"); + unlink ("$tmplatexnam.ps"); + unless ( $global->{debug} ) + { + unlink ("$tmplatexnam.tex", "$tmplatexnam.dvi", "$tmplatexnam.ps"); + rmdir ($tmplatexdir) || return -1; + } return 0; }; --- sgml-tools-1.0.9/lib/dist/fmt_rtf.pl.tmpfile Thu Mar 8 10:09:33 2001 +++ sgml-tools-1.0.9/lib/dist/fmt_rtf.pl Thu Mar 8 10:10:08 2001 @@ -55,7 +55,7 @@ my $split = "-2" if $rtf->{twosplit}; my $pipe = new FileHandle - "|$main::BinDir/rtf2rtf $split $global->{filename} >$global->{filename}.rtf"; + "|$main::BinDir/rtf2rtf $split \"$global->{filename}\" >\"$global->{filename}.rtf\""; copy ($infile, $pipe); $pipe->close; --- sgml-tools-1.0.9/lib/dist/fmt_txt.pl.tmpfile Thu Mar 8 10:11:06 2001 +++ sgml-tools-1.0.9/lib/dist/fmt_txt.pl Thu Mar 8 10:15:56 2001 @@ -234,7 +234,7 @@ else { $outfile = new FileHandle - "|$main::progs->{GROFF} -T $global->{pass} $global->{charset} -t $main::progs->{GROFFMACRO} >$global->{tmpbase}.txt.1"; + "|$main::progs->{GROFF} $global->{pass} -T $global->{charset} -t $main::progs->{GROFFMACRO} >\"$global->{tmpbase}.txt.1\""; } # --- sgml-tools-1.0.9/lib/SGMLTools.pm.tmpfile Thu Mar 8 09:44:33 2001 +++ sgml-tools-1.0.9/lib/SGMLTools.pm Thu Mar 8 09:54:28 2001 @@ -212,6 +212,13 @@ return @files; } +# Pre-create temp files safely +sub create_temp { + my $fh = new FileHandle(shift,O_CREAT|O_EXCL|O_WRONLY,0600); + $fh or die "$0: failed to create temporary file: $!"; + $fh->close; +} + =item SGMLTools::process_file With all the configuration done, this routine will take a single filename @@ -255,7 +262,11 @@ $global->{file} = $file; $global->{filepath} = $filepath; + # prepare temporary directory my $tmpdir = $ENV{'TMPDIR'} || '/tmp'; + $tmpdir = $tmpdir . '/' . 'sgml-tools-dir-' . $$; + mkdir ($tmpdir, 0700) || return -1; + my $tmpbase = $global->{tmpbase} = $tmpdir . '/sgmltmp.' . $filename . $$; $ENV{"SGML_SEARCH_PATH"} .= ":$filepath"; @@ -286,8 +297,10 @@ { $ifile = new FileHandle "$global->{NsgmlsPrePipe}|"; } + + create_temp("$tmpbase.1"); $writensgmls = new FileHandle - "$precmd|$main::progs->{NSGMLS} $global->{NsgmlsOpts} $ENV{SGMLDECL} >$tmpbase.1"; + "$precmd|$main::progs->{NSGMLS} $global->{NsgmlsOpts} $ENV{SGMLDECL} >\"$tmpbase.1\""; if ($global->{charset} eq "latin") { while (<$ifile>) @@ -386,7 +399,7 @@ # preASP ($inhandle, $outhandle); # my $inpreasp = new FileHandle "<$tmpbase.1"; - my $outpreasp = new FileHandle ">$tmpbase.2"; + my $outpreasp = new FileHandle "$tmpbase.2",O_WRONLY|O_CREAT|O_EXCL,0600; if (defined $Formats{$global->{format}}{preASP}) { &{$Formats{$global->{format}}{preASP}}($inpreasp, $outpreasp) == 0 or @@ -428,8 +441,9 @@ my $mapping = "$main::LibDir/site/$dtd/$global->{format}/mapping"; -r $mapping or $mapping = "$main::LibDir/dist/$dtd/$global->{format}/mapping"; - system ("$main::progs->{SGMLSASP} $style $mapping <$tmpbase.2| - expand -$global->{tabsize} >$tmpbase.3"); + create_temp("$tmpbase.3"); + system ("$main::progs->{SGMLSASP} $style $mapping <\"$tmpbase.2\" | + expand -$global->{tabsize} >\"$tmpbase.3\""); # # If a postASP stage is defined, let the format handle it.