Subject: Re: pkg/36518: pkg_select compile error on Linux
To: None <linux-pkg-people@netbsd.org, gnats-admin@netbsd.org,>
From: Frank W. Josellis <frank@dynamical-systems.org>
List: pkgsrc-bugs
Date: 12/18/2007 15:35:02
The following reply was made to PR pkg/36518; it has been noted by GNATS.

From: "Frank W. Josellis" <frank@dynamical-systems.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/36518: pkg_select compile error on Linux
Date: Tue, 18 Dec 2007 16:32:51 +0100 (CET)

 As I would appreciate to have this tool available on Linux, I did some 
 patching which you can find attached below. Let me give a few additional 
 remarks on this:
 
 (1) The cast '(const char*)NULL' in ftpio.c is not a Linux issue, it has 
 been included to prevent Dragonfly's gcc-4.1.2 from stopping here and 
 complaining about missing sentinel.
 
 (2) Except for the diffs in file.c, any modifications were done to cope 
 with build errors on Linux. The changes for loadfile() in file.c actually 
 fix a bug which appears to be graciously tolerated by BSD but results in a 
 memory corruption for Linux:
 
 ---
 *** glibc detected *** pkg_select: free(): invalid next size (fast): 0x08059008 ***
 ======= Backtrace: =========
 /lib/libc.so.6[0xb7dc4bcd]
 /lib/libc.so.6(cfree+0x90)[0xb7dc8350]
 pkg_select[0x804c788]
 pkg_select[0x8051b85]
 pkg_select[0x804a9bf]
 /lib/libc.so.6(__libc_start_main+0xdc)[0xb7d6f36c]
 pkg_select[0x8049b21]
 ======= Memory map: ========
 08048000-08057000 r-xp 00000000 03:07 1324032    /usr/pkg/bin/pkg_select
 08057000-08058000 rw-p 0000e000 03:07 1324032    /usr/pkg/bin/pkg_select
 08058000-0809b000 rw-p 08058000 00:00 0          [heap]
 b7c00000-b7c21000 rw-p b7c00000 00:00 0 
 b7c21000-b7d00000 ---p b7c21000 00:00 0 
 b7d49000-b7d53000 r-xp 00000000 03:07 1221693    /usr/lib/libgcc_s.so.1
 b7d53000-b7d54000 rw-p 00009000 03:07 1221693    /usr/lib/libgcc_s.so.1
 b7d54000-b7d55000 rw-p b7d54000 00:00 0 
 b7d55000-b7d57000 r-xp 00000000 03:07 570208     /lib/libdl-2.7.so
 b7d57000-b7d58000 r--p 00001000 03:07 570208     /lib/libdl-2.7.so
 b7d58000-b7d59000 rw-p 00002000 03:07 570208     /lib/libdl-2.7.so
 b7d59000-b7ea1000 r-xp 00000000 03:07 570207     /lib/libc-2.7.so
 b7ea1000-b7ea3000 r--p 00148000 03:07 570207     /lib/libc-2.7.so
 b7ea3000-b7ea4000 rw-p 0014a000 03:07 570207     /lib/libc-2.7.so
 b7ea4000-b7ea7000 rw-p b7ea4000 00:00 0 
 b7ea7000-b7ee0000 r-xp 00000000 03:07 570092     /lib/libncurses.so.5.6
 b7ee0000-b7ee8000 rw-p 00039000 03:07 570092     /lib/libncurses.so.5.6
 b7ee8000-b7ee9000 rw-p b7ee8000 00:00 0 
 b7ef8000-b7ef9000 r-xp b7ef8000 00:00 0          [vdso]
 b7ef9000-b7f15000 r-xp 00000000 03:07 570230     /lib/ld-2.7.so
 b7f15000-b7f16000 r--p 0001b000 03:07 570230     /lib/ld-2.7.so
 b7f16000-b7f17000 rw-p 0001c000 03:07 570230     /lib/ld-2.7.so
 ---
 
 
 (3) Depending on the particular Linux distribution, one may still get an 
 error if the contents of /usr/share/groff are different from what is 
 expected by nbcompat when trying to format a catpage. The catpage isn't 
 installed anyway, and that's ok. My suggestion would be either to avoid 
 this step completely or to use groff from pkgsrc, if present. But that's a 
 problem for nbcompat rather than pkg_select.
 
 Regards,
 Frank Josellis
 
 
 
 --- pkg_select-20050817nb2.patch begins here ---
 diff -Nur pkg_select.BAK/Makefile pkg_select/Makefile
 --- pkg_select.BAK/Makefile	2007-03-17 08:06:24.000000000 +0100
 +++ pkg_select/Makefile	2007-12-18 13:12:13.000000000 +0100
 @@ -20,6 +20,8 @@
  CONF_FILES=	${EXAMPLEDIR}/${PKGBASE}.conf.example	\
  			${PKG_SYSCONFDIR}/${PKGBASE}.conf
  
 +USE_FEATURES=	nbcompat
 +
  SUBST_CLASSES+=		path
  SUBST_STAGE.path=	pre-configure
  SUBST_MESSAGE.path=	Adjusting path.
 diff -Nur pkg_select.BAK/distinfo pkg_select/distinfo
 --- pkg_select.BAK/distinfo	2007-03-17 08:06:25.000000000 +0100
 +++ pkg_select/distinfo	2007-12-18 13:12:13.000000000 +0100
 @@ -6,3 +6,8 @@
  SHA1 (patch-aa) = c59ecd6d4cfdde450aac1f2794ab7d42da8cbc07
  SHA1 (patch-ab) = a8750c8a5603fa63e0fc17c4be3db7cd340e75b7
  SHA1 (patch-ac) = 2ac66f0222d8f0f80af51eac1878d9f9e97dbbcb
 +SHA1 (patch-ad) = a0600588eec2d622ebdf93a787d14b5a76e47417
 +SHA1 (patch-ae) = 0e232a59599386a5704f84a3bdf8dd37762c5b2b
 +SHA1 (patch-af) = 5300af0b9f91ed7855ca7da7f9b9c764b74af578
 +SHA1 (patch-ag) = adb0e919d4364e10fc122d5643a4c608d0faf213
 +SHA1 (patch-ah) = 9a38e36b9a9364d67f1331c7a82cb5584b5371fc
 diff -Nur pkg_select.BAK/patches/patch-ad pkg_select/patches/patch-ad
 --- pkg_select.BAK/patches/patch-ad	1970-01-01 01:00:00.000000000 +0100
 +++ pkg_select/patches/patch-ad	2007-12-18 13:12:13.000000000 +0100
 @@ -0,0 +1,12 @@
 +--- curses_helpers.c.orig	2005-05-12 13:03:09.000000000 +0200
 ++++ curses_helpers.c	2007-12-18 12:56:28.000000000 +0100
 +@@ -298,7 +298,8 @@
 + 			mvwprintw(popup, y, x + dispw + 1, " ");
 + 		}
 + 
 +-		strlcpy(dispbuf, (char *) (buf + offset), dispw + 1);
 ++		strncpy(dispbuf, (char *) (buf + offset), dispw);
 ++		dispbuf[dispw] = '\0';
 + 		mvwprintw(popup, y, x + 1, fmt, dispbuf);
 + 		wmove(popup, y, x + 1 + pos);
 + 
 diff -Nur pkg_select.BAK/patches/patch-ae pkg_select/patches/patch-ae
 --- pkg_select.BAK/patches/patch-ae	1970-01-01 01:00:00.000000000 +0100
 +++ pkg_select/patches/patch-ae	2007-12-18 13:12:13.000000000 +0100
 @@ -0,0 +1,19 @@
 +--- ftpio.c.orig	2005-05-12 12:35:36 +0200
 ++++ ftpio.c	2007-12-16 12:11:17 +0100
 +@@ -1,6 +1,6 @@
 + /*	$NetBSD: ftpio.c,v 1.61 2003/12/20 02:37:49 grant Exp $	*/
 + 
 +-#include <sys/cdefs.h>
 ++#include <nbcompat.h>
 + #ifndef lint
 + __RCSID("$NetBSD: ftpio.c,v 1.61 2003/12/20 02:37:49 grant Exp $");
 + #endif
 +@@ -490,7 +490,7 @@
 + 		/* we deal with curses, don't really want 
 + 		   stderr to mess display */
 + 		close(2);
 +-		rc1 = execlp(FTP_CMD, argv0, "-detv", base, NULL);
 ++		rc1 = execlp(FTP_CMD, argv0, "-detv", base, (const char*)NULL);
 + 		warn("setupCoproc: execlp() failed");
 + 		exit(1);
 + 		break;
 diff -Nur pkg_select.BAK/patches/patch-af pkg_select/patches/patch-af
 --- pkg_select.BAK/patches/patch-af	1970-01-01 01:00:00.000000000 +0100
 +++ pkg_select/patches/patch-af	2007-12-18 13:12:13.000000000 +0100
 @@ -0,0 +1,11 @@
 +--- main.c.orig	2005-08-17 10:16:19.000000000 +0200
 ++++ main.c	2007-12-16 01:43:32.000000000 +0100
 +@@ -32,7 +32,7 @@
 +  * $Id: main.c,v 1.39 2005/08/17 08:16:19 imil Exp $ 
 +  */
 + 
 +-#include <sys/cdefs.h>
 ++#include <nbcompat.h>
 + #ifndef lint
 + #if 0
 + static char *rcsid = "$Id: main.c,v 1.39 2005/08/17 08:16:19 imil Exp $";
 diff -Nur pkg_select.BAK/patches/patch-ag pkg_select/patches/patch-ag
 --- pkg_select.BAK/patches/patch-ag	1970-01-01 01:00:00.000000000 +0100
 +++ pkg_select/patches/patch-ag	2007-12-18 13:12:13.000000000 +0100
 @@ -0,0 +1,11 @@
 +--- parsedirs.c.orig	2005-02-28 12:49:44.000000000 +0100
 ++++ parsedirs.c	2007-12-16 01:50:20.000000000 +0100
 +@@ -34,7 +34,7 @@
 + 
 + #include "pkg_select.h"
 + 
 +-#if __NetBSD__
 ++#if __NetBSD__ || __linux__
 + #define DIRENT const struct dirent
 + #else
 + #define DIRENT struct dirent
 diff -Nur pkg_select.BAK/patches/patch-ah pkg_select/patches/patch-ah
 --- pkg_select.BAK/patches/patch-ah	1970-01-01 01:00:00.000000000 +0100
 +++ pkg_select/patches/patch-ah	2007-12-18 13:12:13.000000000 +0100
 @@ -0,0 +1,23 @@
 +--- file.c.orig	2005-03-09 12:30:07.000000000 +0100
 ++++ file.c	2007-12-18 12:57:44.000000000 +0100
 +@@ -156,10 +156,7 @@
 + 	if (len == 0)
 + 		return(NULL);
 + 
 +-	XMALLOC(lfile, ++len * sizeof(char *));
 +-
 +-	for (i = 0; i < len; i++)
 +-		lfile[i] = NULL;
 ++	XMALLOC(lfile, (len + 1) * sizeof(char *));
 + 
 + 	if ((fp = fopen(path, "r")) == NULL)
 + 		err(1, "fopen");
 +@@ -167,7 +164,7 @@
 + 	for (i = 0; fgets(buf, MAXLEN, fp) && (i < len); i++)
 + 		XSTRDUP(lfile[i], buf);
 + 
 +-	lfile[i] = NULL;
 ++	lfile[len] = NULL;
 + 
 + 	fclose(fp);
 +
 --- pkg_select-20050817nb2.patch ends here ---