NetBSD Problem Report #44656

From river@TCX.ORG.UK  Tue Mar  1 11:17:01 2011
Return-Path: <river@TCX.ORG.UK>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 4012463B8CE
	for <gnats-bugs@gnats.NetBSD.org>; Tue,  1 Mar 2011 11:17:01 +0000 (UTC)
Message-Id: <20110301111655.5BDCB48212@MAIL.TCX.ORG.UK>
Date: Tue,  1 Mar 2011 11:16:55 +0000 (GMT)
From: r.tarnell@IEEE.ORG
Reply-To: r.tarnell@IEEE.ORG
To: gnats-bugs@gnats.NetBSD.org
Subject: mail/postfix fails on NetBSD when pgsql is enabled
X-Send-Pr-Version: 3.95

>Number:         44656
>Category:       pkg
>Synopsis:       mail/postfix fails on NetBSD when pgsql is enabled
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 01 11:20:00 +0000 2011
>Closed-Date:    Tue Feb 26 19:59:49 +0000 2013
>Last-Modified:  Tue Feb 26 20:00:22 +0000 2013
>Originator:     r.tarnell@IEEE.ORG
>Release:        NetBSD 5.1.0_PATCH
>Organization:
TCX.ORG.UK
>Environment:
System: NetBSD tamara.TCX.ORG.UK 5.1.0_PATCH NetBSD 5.1.0_PATCH (TAMARA) #2: Thu Feb 24 06:06:17 GMT 2011 root@tamara.TCX.ORG.UK:/usr/src/sys/arch/amd64/compile/TAMARA amd64
Architecture: x86_64
Machine: amd64
>Description:
When postfix is built with pgsql support, libpq pulls in libpthread.  
libpthread contains a replacement version of __res_state() (aka _res) which 
aborts the program when called.  Since Postfix smtp and smtpd both use _res to 
perform DNS lookups for RBLs, any attempt to do an RBL lookup will crash 
Postfix:

Mar  1 11:00:03 tamara postfix/smtpd[23620]: connect from localhost[127.0.0.1]
Mar  1 11:00:03 tamara postfix/smtpd[23620]: 815C148212: client=localhost[127.0.0.1]
Mar  1 11:00:03 tamara postfix/cleanup[13517]: 815C148212: message-id=<20110301105559.67C537A490@turnera.esi.toolserver.org>
Mar  1 11:00:03 tamara postfix/qmgr[22476]: 815C148212: from=<daemon@turnera.esi.toolserver.org>, size=2266, nrcpt=1 (queue active)
Mar  1 11:00:03 tamara postfix/qmgr[22476]: warning: private/smtp socket: malformed response
Mar  1 11:00:03 tamara postfix/qmgr[22476]: warning: transport smtp failure -- see a previous warning/fatal/panic logfile record for the problem description
Mar  1 11:00:03 tamara postfix/master[6091]: warning: process /usr/pkg/libexec/postfix/smtp pid 13453 killed by signal 6
Mar  1 11:00:03 tamara postfix/master[6091]: warning: /usr/pkg/libexec/postfix/smtp: bad command startup -- throttling

>How-To-Repeat:
Build Postfix with pgsql support on NetBSD, configure it to use an RBL and then 
make an SMTP connection.

>Fix:
Use res_ninit instead of res_init, which works in multi-threaded programs.

However, it could easily be argued that the real bug here is in NetBSD 
libpthread.  There are plenty of examples of legitimate uses of _res in 
multi-threaded programs, and programs which are not multi-threaded but link 
against libpthread anyway (like Postfix).

--- src/dns/dns_lookup.c	2009-08-06 20:25:33.000000000 +0100
+++ src/dns/dns_lookup.c	2011-03-01 10:33:18.000000000 +0000
@@ -153,6 +153,8 @@

 /* Local stuff. */

+struct __res_state rstate;
+
  /*
   * Structure to keep track of things while decoding a name server reply.
   */
@@ -192,7 +194,7 @@
     /*
      * Initialize the name service.
      */
-    if ((_res.options & RES_INIT) == 0 && res_init() < 0) {
+    if ((rstate.options & RES_INIT) == 0 && res_ninit(&rstate) < 0) {
 	if (why)
 	    vstring_strcpy(why, "Name service initialization failure");
 	return (DNS_FAIL);
@@ -206,18 +208,18 @@

     if ((flags & USER_FLAGS) != flags)
 	msg_panic("dns_query: bad flags: %d", flags);
-    saved_options = (_res.options & USER_FLAGS);
+    saved_options = (rstate.options & USER_FLAGS);

     /*
      * Perform the lookup. Claim that the information cannot be found if and
      * only if the name server told us so.
      */
     for (;;) {
-	_res.options &= ~saved_options;
-	_res.options |= flags;
-	len = res_search((char *) name, C_IN, type, reply->buf, reply->buf_len);
-	_res.options &= ~flags;
-	_res.options |= saved_options;
+	rstate.options &= ~saved_options;
+	rstate.options |= flags;
+	len = res_nsearch(&rstate, (char *) name, C_IN, type, reply->buf, reply->buf_len);
+	rstate.options &= ~flags;
+	rstate.options |= saved_options;
 	if (len < 0) {
 	    if (why)
 		vstring_sprintf(why, "Host or domain name not found. "

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: garbled@NetBSD.org
State-Changed-When: Tue, 26 Feb 2013 19:59:49 +0000
State-Changed-Why:
Applied your patch, tested by myself to solve my problem too.  Also fixes PR43637
Thank you!


From: "Tim Rightnour" <garbled@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/44656 CVS commit: pkgsrc/mail/postfix
Date: Tue, 26 Feb 2013 19:56:19 +0000

 Module Name:	pkgsrc
 Committed By:	garbled
 Date:		Tue Feb 26 19:56:19 UTC 2013

 Modified Files:
 	pkgsrc/mail/postfix: distinfo
 Added Files:
 	pkgsrc/mail/postfix/patches: patch-src_dns_dns__lookup.c

 Log Message:
 Add fix from PR44656 to fix sig6 in postfix/smtp when compiled with any type
 of DB support (like mysql, postgres, etc).  Also fixes PR43637
 Tested by me.


 To generate a diff of this commit:
 cvs rdiff -u -r1.148 -r1.149 pkgsrc/mail/postfix/distinfo
 cvs rdiff -u -r0 -r1.1 \
     pkgsrc/mail/postfix/patches/patch-src_dns_dns__lookup.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.