Subject: pkg_chk doesn't work due too a fmt(1) bug (was: CVS commit: src/usr.bin/fmt)
To: Christos Zoulas <>
From: Bernd Ernesti <>
List: tech-pkg
Date: 01/03/2006 23:22:37
On Thu, Dec 15, 2005 at 09:32:00PM +0000, Christos Zoulas wrote:
> Module Name:	src
> Committed By:	christos
> Date:		Thu Dec 15 21:32:00 UTC 2005
> Modified Files:
> 	src/usr.bin/fmt: fmt.c
> Added Files:
> 	src/usr.bin/fmt: buffer.h
> Log Message:
> PR/32305: seebs: Eliminate buffer overflows and simplify code by using
> dynamically allocated buffers.


I had strange problems with the latest fmt(1) and notice that there were
some changes lately. So I did go back to rev 1.18 of fmt.c and my problems
were gone.

'pkg_chk -a' fails to merge the old pkgchk_update-HOSTNAME.conf file, while
comparing the currently installed packages with the old ones.
The resultin pkgchk_update-HOSTNAME.conf file is only 3 bytes long and
contains 'a ' + RETURN.

I have over 400 packages installed and the pkgchk_update-HOSTNAME.conf file
is 8556 bytes long, where the size of that file doesn't matter. It is the output
from $(pkgdirs_from_installed) which causes fmt to fail in such a way.

It comes down to the following lines (line 710 and following of,v 1.21):

 tmp=$(cat $PKGCHK_UPDATE_CONF;echo $(pkgdirs_from_installed)|fmt -1)
 echo $tmp | fmt -1 | ${SORT} -u > $PKGCHK_UPDATE_CONF

where pkgdirs_from_installed is the following function to get all the pathnames
of the installed packages, relative to PKGSRCDIR.

    ${PKG_INFO} -Bqa | ${AWK} -F= '/PKGPATH=/{print $2}' | ${SORT}

I reduced the old pkgchk_update-HOSTNAME.conf file so it contains just one
line (package), but still got the wrong updated file. $tmp was allready corrupt
at this point. Removing the pkgdirs_from_installed part 'fixed' $tmp, but then
the whole function would not do what it should do.