From aragorn+ports@teaser.fr  Mon May 31 09:05:47 2004
Return-Path: <aragorn+ports@teaser.fr>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 6B5CB16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 31 May 2004 09:05:47 -0700 (PDT)
Received: from sulfateuse.babasse.net (sulfateuse.babasse.net [213.41.169.12])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D7B3E43D55
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 31 May 2004 09:05:45 -0700 (PDT)
	(envelope-from aragorn+ports@teaser.fr)
Received: from blackbox.babasse.net (sulfateuse.babasse.net [192.168.254.129])
	by sulfateuse.babasse.net (8.12.11/8.12.11) with ESMTP id i4VG5YjL066643
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 31 May 2004 18:05:35 +0200 (CEST)
	(envelope-from aragorn+ports@teaser.fr)
Received: from blackbox.babasse.net (localhost [127.0.0.1])
	by blackbox.babasse.net (8.12.11/8.12.11) with ESMTP id i4VG5Ypt066640
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 31 May 2004 18:05:34 +0200 (CEST)
	(envelope-from aragorn+ports@teaser.fr)
Received: (from cyril@localhost)
	by blackbox.babasse.net (8.12.11/8.12.11/Submit) id i4VG5YMi066639;
	Mon, 31 May 2004 18:05:34 +0200 (CEST)
	(envelope-from aragorn+ports@teaser.fr)
Message-Id: <200405311605.i4VG5YMi066639@blackbox.babasse.net>
Date: Mon, 31 May 2004 18:05:34 +0200 (CEST)
From: Cyril Guibourg <aragorn+ports@teaser.fr>
Reply-To: Cyril Guibourg <aragorn+ports@teaser.fr>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: milter-greylist 1.2.2 will crash upon conf reload
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         67419
>Category:       ports
>Synopsis:       milter-greylist 1.2.2 will crash upon conf reload
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          maintainer-update
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 31 09:10:25 PDT 2004
>Closed-Date:    Mon May 31 15:57:15 PDT 2004
>Last-Modified:  Mon May 31 15:57:15 PDT 2004
>Originator:     Cyril Guibourg
>Release:        FreeBSD 4.10-RELEASE i386
>Organization:
Home, sweet home
>Environment:
System: FreeBSD blackbox.babasse.net 4.10-RELEASE FreeBSD 4.10-RELEASE #4: Fri May 28 22:10:50 CEST 2004 root@blackbox.babasse.net:/usr/obj/usr/src/sys/EPIA-M9000 i386


>Description:

	Program will crash (SIGSEV) upon conf reload because of default
	stack size too low in libpthread.

>How-To-Repeat:

	Update or touch the configuration file and wait for the next incoming
	email.

>Fix:

	Given by software author: create a specific thread for conf
	reload, using pthread_attr_setstacksize() accordingly.

	Makefile diff and patch for ${WRKSRC}/conf.c follow.

	Thanks.



--- Makefile.orig	Thu May 27 13:44:54 2004
+++ Makefile	Mon May 31 17:03:09 2004
@@ -7,6 +7,7 @@
 
 PORTNAME=	milter-greylist
 PORTVERSION=	1.2.2
+PORTREVISION=	1
 CATEGORIES=	mail
 MASTER_SITES=	ftp://ftp.espci.fr/pub/milter-greylist/
 EXTRACT_SUFX=	.tgz
@@ -33,15 +34,16 @@
 		${FILESDIR}/milter-greylist.sh > ${WRKSRC}/milter-greylist.sh
 
 post-install:
-	${MKDIR} /var/milter-greylist /var/db/milter-greylist
-	${CHOWN} smmsp /var/milter-greylist /var/db/milter-greylist
-	${MKDIR} ${PREFIX}/etc/rc.d
-	${INSTALL_SCRIPT} ${WRKSRC}/milter-greylist.sh ${PREFIX}/etc/rc.d/
+	@${MKDIR} /var/milter-greylist /var/db/milter-greylist
+	@${CHOWN} smmsp /var/milter-greylist /var/db/milter-greylist
+	@${MKDIR} ${PREFIX}/etc/rc.d
+	@${INSTALL_SCRIPT} ${WRKSRC}/milter-greylist.sh ${PREFIX}/etc/rc.d/
 .if !defined(NOPORTDOCS)
-	${MKDIR} ${DOCSDIR}
-	${MKDIR} ${EXAMPLESDIR}
-	${INSTALL_DATA} ${WRKSRC}/README ${DOCSDIR}
-	${INSTALL_DATA} ${WRKSRC}/greylist.conf ${EXAMPLESDIR}
+	@${MKDIR} ${DOCSDIR}
+	@${MKDIR} ${EXAMPLESDIR}
+	@${INSTALL_DATA} ${WRKSRC}/README ${DOCSDIR}
+	@${INSTALL_DATA} ${WRKSRC}/greylist.conf ${EXAMPLESDIR}
 .endif
+	@${CAT} ${PKGMESSAGE}
 
 .include <bsd.port.mk>

	>8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8 >8

--- conf.c.orig	Fri Apr  2 17:06:52 2004
+++ conf.c	Mon May 31 16:58:06 2004
@@ -34,7 +34,7 @@
 #ifdef HAVE_SYS_CDEFS_H
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$Id: conf.c,v 1.15 2004/04/02 15:06:52 manu Exp $");
+__RCSID("$Id: conf.c,v 1.15 (sigsev patch) 2004/04/02 15:06:52 manu Exp $");
 #endif
 #endif
 
@@ -83,6 +83,8 @@
 conf_load(void) 	/* exceptlist must be write-locked */
 {
 	FILE *stream;
+	pthread_t tid;
+	pthread_attr_t attr;
 
 	/*
 	 * Reset the configuration to its default 
@@ -100,8 +102,49 @@
 		return;
 	}
 
+	/*
+	 * On some platforms, the thread stack limit is too low and
+	 * conf_parse will get a SIGSEGV because it overflows the
+	 * stack.
+	 *
+	 * In order to fix this, we spawn a new thread just for 
+	 * parsing the config file, and we request a stack big 
+	 * enough to hold the parser data. 2 MB seems okay.
+	 */
+
 	conf_in = stream;
-	conf_parse();
+
+	if (pthread_attr_init(&attr) != 0) {
+		syslog(LOG_ERR, "pthread_attr_init failed: %s", 
+		strerror(errno));
+		exit(EX_OSERR);
+	}
+
+	if (pthread_attr_setstacksize(&attr, 2 * 1024 * 1024) != 0) {
+		syslog(LOG_ERR, "pthread_attr_setstacksize failed: %s",
+		strerror(errno));
+		exit(EX_OSERR);
+	}
+
+	if (pthread_create(&tid, &attr, 
+		(void *(*)(void *))conf_parse, NULL) != 0) {
+		syslog(LOG_ERR, "pthread_create failed: %s", 
+		strerror(errno));
+		exit(EX_OSERR);
+	}
+
+	if (pthread_join(tid, NULL) != 0) {
+		syslog(LOG_ERR, "pthread_join failed: %s",
+		strerror(errno));
+		exit(EX_OSERR);
+	}
+
+	if (pthread_attr_destroy(&attr) != 0) {
+		syslog(LOG_ERR, "pthread_attr_destroy failed: %s",
+		strerror(errno));
+		exit(EX_OSERR);
+	}
+
 	fclose(stream);
 
 	(void)gettimeofday(&conffile_modified, NULL);
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: pav 
State-Changed-When: Mon May 31 15:57:07 PDT 2004 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67419 
>Unformatted:
