Subject: pkg/20978: mail/deliver is not compatible with recent NetBSD libc
To: None <>
From: None <>
List: netbsd-bugs
Date: 04/01/2003 21:48:10
>Number:         20978
>Category:       pkg
>Synopsis:       mail/deliver is not compatible with recent NetBSD libc
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 01 20:49:00 PST 2003
>Originator:     Jim Bernard
>Release:        NetBSD 1.6Q
System: NetBSD zoo 1.6Q NetBSD 1.6Q (ZOO-$Revision: 1.84 $) #0: Sat Mar 22 17:47:47 MST 2003 jim@roc:/wd1/var/tmp/compile/sys/arch/i386/compile/ZOO i386
Architecture: i386
Machine: i386
	The deliver program fails to work (loses all mail) when recent
	versions of libc are installed.  Error messages look like:

	  _20016F.myhost: can't generate unique temp for /var/mail/user
	  _20016F.myhost: delivery error on host myhost
	  Reason(s) for failure:
		  "user": Can't write to mailbox
	  _01016F.myhost: can't create lockfile /tmp/dl.loglock: File exists

	The problem is that it uses the basename function to construct file
	names [in lock.c (dotlock_name) and subs.c (unique)], and its usage
	of basename assumes that the function returns a pointer that
	references a location within the source string (which deliver then
	uses to modify the string).  However NetBSD's libc/gen/basename.c
	was changed on Oct. 17, 2002 (rev. 1.5 of basename.c) to always
	return a pointer to static storage containing the base name, so
	deliver fails to construct usable file names.

	Install deliver and a libc more recent than Oct. 17, 2002 and
	use deliver to filter your mail.

	The usage of a function called basename in deliver isn't all that
	closely aligned with the behavior of the similarly named function
	in libc.  In fact, deliver provides its own basename function for
	systems that don't have a suitable one, and the provided function
	has just the right behavior for what deliver assumes.  So, the
	easiest fix is to use that one instead of the one from libc.  This
	requires only a minor change to one of the patch files, patch-af,
	which creates the NetBSD configuration header file.  Here's the
	modified patch-af file in its entirety:

--- /dev/null	2003-03-15 16:33:11.000000000 -0700
+++ conf/os-netbsd.h
@@ -0,0 +1,33 @@
+ * Deliver configuration for NetBSD.
+ *
+ */
+/* Mostly it's POSIX. */
+#include <base-posix.h>
+/* Then again... */
+#undef  SAFEPATH
+#define SAFEPATH    "/bin:/usr/bin:/usr/pkg/bin"  /* Safe dirs for PATH	*/
+#undef  SYSV_USRMAIL		/* Mailboxes in /usr/mail, as per SysV	*/
+#define MBX_DIR     "/var/mail"
+#undef  HAS_TIMEZONE		/* Has global variable timezone (SVID)	*/
+#define HAS_MKTIME		/* Has mktime()           		*/
+/* We avoid defining HAS_BASENAME because NetBSD's basename(3), as of
+ * revision 1.5 of basename.c (October 17, 2002), returns a pointer to
+ * a copy of the base name in static storage, and uses of basename in
+ * the code are incompatible with that behavior.  So we rely instead on
+ * the basename replacement included here.
+ */
+#undef  HAS_BASENAME		/* Has basename()			*/
+#define HAS_LONGNAMES		/* Long filenames (>14) supported	*/
+/* Note that we don't define HAS_USLEEP, since deliver wants to use it
+ * for sleeping for more than one second, but the implementation limits
+ * the sleep time to strictly less than one second.
+ */