Subject: pkg/34816: pkgtools/pkg_chk-1.82 uses /tmp unconditionally for scratch
To: None <,,>
From: None <>
List: pkgsrc-bugs
Date: 10/14/2006 19:20:02
>Number:         34816
>Category:       pkg
>Synopsis:       pkgtools/pkg_chk-1.82 uses /tmp unconditionally for scratch
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 14 19:20:02 +0000 2006
>Originator:     Jim Bernard
>Release:        NetBSD 4.99.2
System: NetBSD 4.99.2 #0: Sat Sep 16 12:17:30 MDT 2006 i386
Architecture: i386
Machine: i386
	The pkg_chk shell script unconditionally puts its scratch
	directory under /tmp and sets TMPDIR to the directory created.
	This can lead to filling of the file system containing /tmp
	when installing large package trees, and externally setting
	TMPDIR doesn't help.

	While I'm here: I noticed that pkg_chk executes pkg_add,
	pkg_delete, and pkg_info as arguments to /usr/bin/env, but
	/usr/bin/env is given no flags, nor any environment variables
	to set, and the programs are specified by full path names,
	such as "/usr/bin/env  /usr/sbin/pkg_add ...".  That would seem
	to make the use of /usr/bin/env superfluous.  Perhaps the intent
	was to execute the version of (e.g.) pkg_add in the location where
	the shell would find it in $PATH.  If so, then it's appropriate
	to use just (e.g.) "/usr/bin/env pkg_add ..." without the path
	prefix to pkg_add.

	Run pkg_chk with TMPDIR set to, say, /var/tmp, and notice that
	the temporary directory it creates is in /tmp.  Or just read
	the script.

	Here's a candidate patch.

--- /usr/pkg/sbin/pkg_chk	2006-10-14 09:57:23.000000000 -0600
+++ ./pkg_chk	2006-10-14 12:50:20.000000000 -0600
@@ -86,12 +86,12 @@
-    rm -f $TMPFILE
-    rmdir $TMPDIR
+    rm -f $PKG_CHK_TMPFILE
+    rmdir $PKG_TMPDIR
     exit "$@"
@@ -246,13 +246,13 @@
     # Unfortunately pkgsrc always outputs to a file, but it does helpfully
     # allows # us to specify the name
-    rm -f $TMPFILE
-    cat $TMPFILE
+    rm -f $PKG_CHK_TMPFILE
     # DEPCHECKLIST contains packages for which binary packages are known to
@@ -666,12 +666,12 @@
 if [ $# != 0 ];then
     usage "Additional argument ($*) given"
-TMPDIR=`mktemp -d /tmp/${0##*/}.XXXXXX`
+export PKG_TMPDIR=`mktemp -d ${PKG_TMPDIR:-${TMPDIR:-/tmp}}/${0##*/}.XXXXXX`
 # Hide PKG_PATH to avoid breakage in 'make' calls
 unset PKG_PATH || true