From rasputin@shaft.techsupport.co.uk  Fri Aug 31 06:14:05 2001
Return-Path: <rasputin@shaft.techsupport.co.uk>
Received: from shaft.techsupport.co.uk (shaft.techsupport.co.uk [212.250.77.214])
	by hub.freebsd.org (Postfix) with ESMTP id 7B59F37B403
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 31 Aug 2001 06:14:04 -0700 (PDT)
Received: from rasputin by shaft.techsupport.co.uk with local (Exim 3.22 #1)
	id 15ckp2-0001vs-00
	for FreeBSD-gnats-submit@freebsd.org; Fri, 31 Aug 2001 10:42:44 +0100
Message-Id: <E15ckp2-0001vs-00@shaft.techsupport.co.uk>
Date: Fri, 31 Aug 2001 10:42:44 +0100
From: Rasputin <rasputnik@hellooperator.net>
Reply-To: Rasputin <rasputnik@hellooperator.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: /usr/sbin/portmap cannot listen to localhost UDP only (patch)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         30235
>Category:       bin
>Synopsis:       /usr/sbin/portmap cannot listen to localhost UDP only (patch)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 31 06:20:00 PDT 2001
>Closed-Date:    Sun Jul 31 12:06:01 GMT 2005
>Last-Modified:  Sun Jul 31 12:06:01 GMT 2005
>Originator:     Rasputin
>Release:        FreeBSD 4.4-PRERELEASE i386
>Organization:
SubMonkey.net
>Environment:
System: FreeBSD shaft.techsupport.co.uk 4.4-PRERELEASE FreeBSD 4.4-PRERELEASE #2: Wed Aug 8 17:59:16 BST 2001 setantae@shaft.techsupport.co.uk:/usr/obj/usr/src/sys/SHAFT i386


	
>Description:
	portmap(8) states that the -h commandline flag specifies
	specific IP addresses to listen on for UDP. It also states that 127.0.0.1
	is added to the list automatically.
	This causes portmap to attmept to bind twice to 127.0.0.1 if given
	'-h 127.0.0.1', preventing it from starting.

	Without this flag, there is no way to bind only to localhost
	(omitting -h causes portmap to bind to INADDR_ANY).

	The folllowing patch brings portmap into line with its manpage
	(i.e the behaviour of tcp ports has not been changed)
>How-To-Repeat:
	portmap -h 127.0.0.1
>Fix:

--- portmap.c.orig	Tue Apr 10 00:35:19 2001
+++ portmap.c	Thu Aug 30 13:51:06 2001
@@ -159,12 +159,26 @@
 	 * If no hosts were specified, just bind to INADDR_ANY.  Otherwise
 	 * make sure 127.0.0.1 is added to the list.
 	 */
-	++nhosts;
-	hosts = realloc(hosts, nhosts * sizeof(char *));
-	if (nhosts == 1)
+	if (nhosts == 0){
+		++nhosts;
+		hosts = realloc(hosts, nhosts * sizeof(char *));
 		hosts[0] = "0.0.0.0";
-	else
-		hosts[nhosts - 1] = "127.0.0.1";
+		}
+	else {
+	/* add localhost if not already there */
+
+		int n, lh_requested = 0;
+
+		for(n=0;n<nhosts;n++) {
+		if(!strcmp(hosts[n],"127.0.0.1")) lh_requested = 1;
+		}
+
+		if (!lh_requested) {
+			++nhosts;
+			hosts = realloc(hosts, nhosts * sizeof(char *));
+			hosts[nhosts - 1] = "127.0.0.1";
+		}
+	}
 
 	/*
 	 * Add UDP socket(s) - bind to specific IPs if asked to
>Release-Note:
>Audit-Trail:

From: Frank Tobin <ftobin@neverending.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc: rasputin@shaft.techsupport.co.uk
Subject: Re: bin/30235: /usr/sbin/portmap cannot listen to localhost UDP only
 (patch)
Date: Tue, 23 Oct 2001 12:14:05 -0400 (EDT)

 The patch seems to work.
 
 Bug 31393 (submitted by me) should be marked as a duplicate.
 
 -- 
 Frank Tobin		http://www.neverending.org/~ftobin/
 
State-Changed-From-To: open->closed 
State-Changed-By: bms 
State-Changed-When: Mon Jun 14 21:04:42 GMT 2004 
State-Changed-Why:  
Fixed by design. Both -CURRENT and -STABLE now use rpcbind which 
has the -h option implemented. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=30235 
State-Changed-From-To: closed->patched 
State-Changed-By: bms 
State-Changed-When: Tue Jun 15 22:41:13 GMT 2004 
State-Changed-Why:  
Doh! This is only fixed in -CURRENT. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=30235 

From: Robert Faulds <robert@mongonet.net>
To: freebsd-gnats-submit@FreeBSD.org, rasputnik@hellooperator.net
Cc:  
Subject: Re: bin/30235: /usr/sbin/portmap cannot listen to localhost UDP only
 (patch)
Date: Tue, 16 Nov 2004 12:01:53 -0800

 Could we get this patch applied to stable, please?
 
 Robert

From: Dick Davies <rasputnik@hellooperator.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc: Robert Faulds <robert@mongonet.net>
Subject: Re: bin/30235: /usr/sbin/portmap cannot listen to localhost UDP only (patch)
Date: Tue, 16 Nov 2004 22:14:30 +0000

 * Robert Faulds <robert@mongonet.net> [1102 20:02]:
 > Could we get this patch applied to stable, please?
 
 Please don't, it would be embarassing. I sent that patch 3 years ago,
 when I was only halfway through K&R. I can't believe it's taken that
 long to be looked at. I suspect no-one had the heart to close it,
 saying 'this is ugly as sin, I'm not committing this')..
 
 
 It was a kludge at the time (there *must* be a saner way to check an
 IP than to use strcmp) and it's not right to commit such a mess.
 
 A better fix would be to backport rpcbind to 4.* - I just checked that
 on a 5.3 system and it works as documented - then the portmap code could
 be taken out and shot.
 
 NB: this doesn't work for tcp ports in any case, and I don't know enough
 about NFS to know why '-h' only applies to udp. So a firewall would be a 
 safer option if you are concerned about exposing ports. But feel free to 
 use the patch if it's any use to you.
 
 -- 
 With that big new contract, I've been able to make those government mandated
 upgrades you've all been suing me about. - Prof. Farnsworth
 Rasputin :: Jack of All Trades - Master of Nuns
State-Changed-From-To: patched->closed 
State-Changed-By: matteo 
State-Changed-When: Sun Jul 31 12:05:38 GMT 2005 
State-Changed-Why:  
Fixed but will not be MFCed to RELENG_4 

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