Subject: lib/1940: getnetent reads an alias when there is none
To: None <gnats-bugs@gnats.netbsd.org>
From: Greg Hudson <ghudson@MIT.EDU>
List: netbsd-bugs
Date: 01/13/1996 23:42:10
>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 (Library Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Jan 14 00:05:01 1996
>Last-Modified:
>Originator: Greg Hudson
>Organization:
MIT SIPB
>Release: 1.1
>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);
>Audit-Trail:
>Unformatted: