From 6f5e764aa363f94048dadabcde94956e507edd87 Mon Sep 17 00:00:00 2001 From: wlemb Date: Tue, 28 Oct 2003 07:46:21 +0000 Subject: * contrib/eqn2graph/eqn2graph.sh, contrib/grap2graph/grap2graph.sh, contrib/pic2graph/pic2graph.sh: Implement secure management of temporary files. Pass `-P-pletter' to groff to avoid data outside of the converted area -- some versions of `convert' (for example 5.3.8) don't check the bounding box of the image but always use a fixed image size (letter paper format). * contrib/eqn2graph/eqn2graph.man, contrib/grap2graph/grap2graph.man, contrib/pic2graph/pic2graph.man: Updated. * src/roff/groff/groff.man: Document $TMP and $TEMP. --- contrib/eqn2graph/eqn2graph.man | 18 +++++++++++++++++- contrib/eqn2graph/eqn2graph.sh | 31 ++++++++++++++++++++++++------- contrib/grap2graph/grap2graph.man | 18 +++++++++++++++++- contrib/grap2graph/grap2graph.sh | 29 +++++++++++++++++++++++------ contrib/pic2graph/pic2graph.man | 18 +++++++++++++++++- contrib/pic2graph/pic2graph.sh | 30 ++++++++++++++++++++++++------ 6 files changed, 122 insertions(+), 22 deletions(-) (limited to 'contrib') diff --git a/contrib/eqn2graph/eqn2graph.man b/contrib/eqn2graph/eqn2graph.man index e7896fcc..3f34cc5e 100644 --- a/contrib/eqn2graph/eqn2graph.man +++ b/contrib/eqn2graph/eqn2graph.man @@ -1,4 +1,4 @@ -.\" $Id: eqn2graph.man,v 1.3 2003/07/02 15:37:30 wlemb Exp $ +.\" $Id: eqn2graph.man,v 1.4 2003/10/28 07:46:23 wlemb Exp $ .\" This documentation is released to the public domain. . . @@ -82,6 +82,22 @@ The initialization file. . . +.SH ENVIRONMENT +.TP +.B GROFF_TMPDIR +The directory in which temporary files will be created. +If this is not set +.B eqn2graph +searches the environment variables +.BR \%TMPDIR , +.BR TMP , +and +.B TEMP +(in that order). +Otherwise, temporary files will be created in +.BR /tmp . +. +. .SH "SEE ALSO" .BR pic2graph (@MAN1EXT@), .BR grap2graph (@MAN1EXT@), diff --git a/contrib/eqn2graph/eqn2graph.sh b/contrib/eqn2graph/eqn2graph.sh index e314dc91..efcd0187 100644 --- a/contrib/eqn2graph/eqn2graph.sh +++ b/contrib/eqn2graph/eqn2graph.sh @@ -32,7 +32,7 @@ # # Thus, we pass -U to groff(1), and everything else to convert(1). # -# $Id: eqn2graph.sh,v 1.2 2002/07/17 04:55:46 wlemb Exp $ +# $Id: eqn2graph.sh,v 1.3 2003/10/28 07:46:23 wlemb Exp $ # groff_opts="" convert_opts="" @@ -58,17 +58,34 @@ do shift done +# create temporary directory +tmp= +for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp; do + test -z "$d" && continue + + tmp=`(umask 077 && mktemp -d -q "$d/eqn2graph-XXXXXX") 2> /dev/null` \ + && test -n "$tmp" && test -d "$tmp" \ + && break + + tmp=$d/eqn2graph$$-$RANDOM + (umask 077 && mkdir $tmp) 2> /dev/null && break +done; +if test -z "$tmp"; then + echo "$0: cannot create temporary directory" >&2 + { (exit 1); exit 1; } +fi + +trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 2 15 + # Here goes: # 1. Add .EQ/.EN. # 2. Process through eqn(1) to emit troff markup. # 3. Process through groff(1) to emit Postscript. # 4. Use convert(1) to crop the Postscript and turn it into a bitmap. -tmp=/usr/tmp/eqn2graph-$$ -trap "rm ${tmp}.*" 0 2 15 read equation -(echo ".EQ"; echo 'delim $$'; echo ".EN"; echo '$'"${equation}"'$') | \ - groff -e $groff_opts -Tps >${tmp}.ps \ - && convert -crop 0x0 $convert_opts ${tmp}.ps ${tmp}.${format} \ - && cat ${tmp}.${format} +(echo ".EQ"; echo 'delim $$'; echo ".EN"; echo '$'"$equation"'$') | \ + groff -e $groff_opts -Tps -P-pletter > $tmp/eqn2graph.ps \ + && convert -crop 0x0 $convert_opts $tmp/eqn2graph.ps $tmp/eqn2graph.$format \ + && cat $tmp/eqn2graph.$format # End diff --git a/contrib/grap2graph/grap2graph.man b/contrib/grap2graph/grap2graph.man index cf259321..0c6d4568 100644 --- a/contrib/grap2graph/grap2graph.man +++ b/contrib/grap2graph/grap2graph.man @@ -1,4 +1,4 @@ -.\" $Id: grap2graph.man,v 1.2 2003/07/02 18:48:25 wlemb Exp $ +.\" $Id: grap2graph.man,v 1.3 2003/10/28 07:46:23 wlemb Exp $ .\" This documentation is released to the public domain. . . @@ -72,6 +72,22 @@ Command-line switches and arguments not listed above are passed to .BR convert (1). . . +.SH ENVIRONMENT +.TP +.B GROFF_TMPDIR +The directory in which temporary files will be created. +If this is not set +.B grap2graph +searches the environment variables +.BR \%TMPDIR , +.BR TMP , +and +.B TEMP +(in that order). +Otherwise, temporary files will be created in +.BR /tmp . +. +. .SH "SEE ALSO" .BR pic2graph (@MAN1EXT@), .BR eqn2graph (@MAN1EXT@), diff --git a/contrib/grap2graph/grap2graph.sh b/contrib/grap2graph/grap2graph.sh index 75bb881e..7737f1ef 100644 --- a/contrib/grap2graph/grap2graph.sh +++ b/contrib/grap2graph/grap2graph.sh @@ -28,7 +28,7 @@ # # Thus, we pass -U to groff(1), and everything else to convert(1). # -# $Id: grap2graph.sh,v 1.1 2003/07/02 15:35:01 wlemb Exp $ +# $Id: grap2graph.sh,v 1.2 2003/10/28 07:46:23 wlemb Exp $ # groff_opts="" convert_opts="" @@ -54,15 +54,32 @@ do shift done +# create temporary directory +tmp= +for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp; do + test -z "$d" && continue + + tmp=`(umask 077 && mktemp -d -q "$d/grap2graph-XXXXXX") 2> /dev/null` \ + && test -n "$tmp" && test -d "$tmp" \ + && break + + tmp=$d/grap2graph$$-$RANDOM + (umask 077 && mkdir $tmp) 2> /dev/null && break +done; +if test -z "$tmp"; then + echo "$0: cannot create temporary directory" >&2 + { (exit 1); exit 1; } +fi + +trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 2 15 + # Here goes: # 1. Add .G1/.G2. # 2. Process through grap(1) to emit pic markup. # 3. Process through groff(1) with pic preprocessing to emit Postscript. # 4. Use convert(1) to crop the Postscript and turn it into a bitmap. -tmp=/usr/tmp/grap2graph-$$ -trap "rm ${tmp}.*" 0 2 15 -(echo ".G1"; cat; echo ".G2") | grap | groff -p $groff_opts -Tps | \ - convert -crop 0x0 $convert_opts - ${tmp}.${format} \ - && cat ${tmp}.${format} +(echo ".G1"; cat; echo ".G2") | grap | groff -p $groff_opts -Tps -P-pletter | \ + convert -crop 0x0 $convert_opts - $tmp/grap2graph.$format \ + && cat $tmp/grap2graph.$format # End diff --git a/contrib/pic2graph/pic2graph.man b/contrib/pic2graph/pic2graph.man index 2e63f61b..36008cba 100644 --- a/contrib/pic2graph/pic2graph.man +++ b/contrib/pic2graph/pic2graph.man @@ -1,4 +1,4 @@ -.\" $Id: pic2graph.man,v 1.4 2003/07/02 15:37:57 wlemb Exp $ +.\" $Id: pic2graph.man,v 1.5 2003/10/28 07:46:24 wlemb Exp $ .\" This documentation is released to the public domain. .TH PIC2GRAPH @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@" .IX pic2graph @@ -106,6 +106,22 @@ The initialization file. . . +.SH ENVIRONMENT +.TP +.B GROFF_TMPDIR +The directory in which temporary files will be created. +If this is not set +.B pic2graph +searches the environment variables +.BR \%TMPDIR , +.BR TMP , +and +.B TEMP +(in that order). +Otherwise, temporary files will be created in +.BR /tmp . +. +. .SH "SEE ALSO" .BR eqn2graph (@MAN1EXT@), .BR grap2graph (@MAN1EXT@), diff --git a/contrib/pic2graph/pic2graph.sh b/contrib/pic2graph/pic2graph.sh index f4478519..4189a336 100644 --- a/contrib/pic2graph/pic2graph.sh +++ b/contrib/pic2graph/pic2graph.sh @@ -32,7 +32,7 @@ # We don't have complete option coverage on eqn because this is primarily # intended as a pic translator; we can live with eqn defaults. # -# $Id: pic2graph.sh,v 1.3 2002/12/21 08:32:56 wlemb Exp $ +# $Id: pic2graph.sh,v 1.4 2003/10/28 07:46:24 wlemb Exp $ # groffpic_opts="" gs_opts="" @@ -68,16 +68,34 @@ then eqndelim="delim $eqndelim" fi +# create temporary directory +tmp= +for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp; do + test -z "$d" && continue + + tmp=`(umask 077 && mktemp -d -q "$d/pic2graph-XXXXXX") 2> /dev/null` \ + && test -n "$tmp" && test -d "$tmp" \ + && break + + tmp=$d/pic2graph$$-$RANDOM + (umask 077 && mkdir $tmp) 2> /dev/null \ + && break +done; +if test -z "$tmp"; then + echo "$0: cannot create temporary directory" >&2 + { (exit 1); exit 1; } +fi + +trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 2 15 + # Here goes: # 1. Wrap the input in dummy .PS/PE macros (and add possibly null .EQ/.EN) # 2. Process through eqn and pic to emit troff markup. # 3. Process through groff to emit Postscript. # 4. Use convert(1) to crop the PostScript and turn it into a bitmap. -tmp=/usr/tmp/pic2graph-$$ -trap "rm ${tmp}.*" 0 2 15 (echo ".EQ"; echo $eqndelim; echo ".EN"; echo ".PS"; cat; echo ".PE") | \ - groff -e -p $groffpic_opts -Tps >${tmp}.ps \ - && convert -crop 0x0 $convert_opts ${tmp}.ps ${tmp}.${format} \ - && cat ${tmp}.${format} + groff -e -p $groffpic_opts -Tps -P-letter > $tmp/pic2graph.ps \ + && convert -crop 0x0 $convert_opts $tmp/pic2graph.ps $tmp/pic2graph.$format \ + && cat $tmp/pic2graph.$format # End -- cgit v1.2.1