NetBSD Problem Report #1940

From gnats  Sat Jan 13 23:58:45 1996
Received: from lola-granola.MIT.EDU by pain.lcs.mit.edu (8.6.12/8.6.9) with ESMTP id XAA28157 for <gnats-bugs@gnats.NetBSD.ORG>; Sat, 13 Jan 1996 23:42:11 -0500
Message-Id: <199601140442.XAA07257@lola-granola.MIT.EDU>
Date: Sat, 13 Jan 1996 23:42:10 -0500
From: Greg Hudson <ghudson@mit.edu>
Reply-To: ghudson@mit.edu
To: gnats-bugs@gnats.NetBSD.ORG
Subject: getnetent reads an alias when there is none
X-Send-Pr-Version: 3.2

>Number:         1940
>Category:       lib
>Synopsis:       getnetent may read the network address as an alias
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 14 05:05:01 +0000 1996
>Closed-Date:    Sun Jan 14 05:10:17 +0000 1996
>Last-Modified:  Sun Mar 23 01:53:51 +0000 2014
>Originator:     Greg Hudson
>Release:        1.1
>Organization:
MIT SIPB
>Environment:
System: NetBSD lola-granola 1.1A NetBSD 1.1A (LOLA) #143: Sat Jan 13 01:51:04 EST 1996 mycroft@lola-granola:/afs/sipb.mit.edu/project/netbsd/dev/current-source/build/i386_nbsd1/sys/arch/i386/compile/LOLA i386


>Description:
	When there are no aliases in a line in /etc/networks, getnetent()
	will read in the network address as an alias.

	This bug also exists in the bind 4.9.3 release.  I'll send a bug
	report to Paul Vixie about it.

>How-To-Repeat:
	Since NetBSD doesn't ship with an /etc/networks file, make a
	sample file containing the following lines:

		name1	1.1 alias_a alias_b
		name2	2.2

	Then compile and run this sample program:

		#include <stdio.h>
		#include <netdb.h>

		int main()
		{
		    struct netent *net;
		    char **alias;

		    setnetent(0);
		    while ((net = getnetent()) != NULL) {
			printf("%s\t%d\t%lu:", net->n_name, net->n_addrtype,
			       net->n_net);
			for (alias = net->n_aliases; *alias; alias++)
			    printf(" %s", *alias);
			putchar('\n');
		    }
		    return 0;
		}

	Notice that the second line of output contains an alias "2.2".

>Fix:

Per getprotoent.c:

*** /usr/src/lib/libc/net/getnetent.c	Thu Mar  9 03:54:05 1995
--- getnetent.c	Sat Jan 13 23:35:30 1996
***************
*** 109,126 ****
  	net.n_net = inet_network(cp);
  	net.n_addrtype = AF_INET;
  	q = net.n_aliases = net_aliases;
! 	if (p != NULL) 
  		cp = p;
! 	while (cp && *cp) {
! 		if (*cp == ' ' || *cp == '\t') {
! 			cp++;
! 			continue;
  		}
- 		if (q < &net_aliases[MAXALIASES - 1])
- 			*q++ = cp;
- 		cp = strpbrk(cp, " \t");
- 		if (cp != NULL)
- 			*cp++ = '\0';
  	}
  	*q = NULL;
  	return (&net);
--- 109,127 ----
  	net.n_net = inet_network(cp);
  	net.n_addrtype = AF_INET;
  	q = net.n_aliases = net_aliases;
! 	if (p != NULL) {
  		cp = p;
! 		while (cp && *cp) {
! 			if (*cp == ' ' || *cp == '\t') {
! 				cp++;
! 				continue;
! 			}
! 			if (q < &net_aliases[MAXALIASES - 1])
! 				*q++ = cp;
! 			cp = strpbrk(cp, " \t");
! 			if (cp != NULL)
! 				*cp++ = '\0';
  		}
  	}
  	*q = NULL;
  	return (&net);
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ghudson 
State-Changed-When: Sun Jan 14 00:10:17 EST 1996 
State-Changed-Why:  
Fix from PR applied to source tree. 

>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.