Date: Fri, 09 Mar 2001 21:25:45 +0000 From: Brian Somers <brian@Awfulhak.org> To: freebsd-audit@FreeBSD.org Cc: Brian Somers <brian@Awfulhak.org> Subject: netstat/MAXHOSTNAMELEN fixes Message-ID: <200103092125.f29LPju04945@hak.lan.Awfulhak.org>
next in thread | raw e-mail | index | archive | help
Would someone mind casting an eye over the attached patch ? It fixes uses of MAXHOSTNAMELEN and uses trimdomain() from libutil rather than rolling our own. Ta. -- Brian <brian@Awfulhak.org> <brian@[uk.]FreeBSD.org> <http://www.Awfulhak.org> <brian@[uk.]OpenBSD.org> Don't _EVER_ lose your sense of humour ! Index: Makefile =================================================================== RCS file: /home/ncvs/src/usr.bin/netstat/Makefile,v retrieving revision 1.15 diff -u -r1.15 Makefile --- Makefile 2000/07/04 16:26:46 1.15 +++ Makefile 2001/03/09 20:54:45 @@ -11,8 +11,8 @@ #.PATH: ${.CURDIR}/../../sys/netiso BINGRP= kmem BINMODE=2555 -DPADD= ${LIBKVM} ${LIBIPX} ${LIBNETGRAPH} -LDADD= -lkvm -lipx -lnetgraph +DPADD= ${LIBKVM} ${LIBIPX} ${LIBNETGRAPH} ${LIBUTIL} +LDADD= -lkvm -lipx -lnetgraph -lutil CFLAGS+=-DINET6 -DIPSEC .include <bsd.prog.mk> Index: inet.c =================================================================== RCS file: /home/ncvs/src/usr.bin/netstat/inet.c,v retrieving revision 1.38 diff -u -r1.38 inet.c --- inet.c 2000/07/04 16:26:46 1.38 +++ inet.c 2001/03/09 20:56:51 @@ -72,6 +72,7 @@ #include <arpa/inet.h> #include <err.h> #include <errno.h> +#include <libutil.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> @@ -715,7 +716,7 @@ struct in_addr *inp; { register char *cp; - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; struct hostent *hp; struct netent *np; @@ -733,7 +734,7 @@ hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET); if (hp) { cp = hp->h_name; - trimdomain(cp); + trimdomain(cp, strlen(cp)); } } } Index: inet6.c =================================================================== RCS file: /home/ncvs/src/usr.bin/netstat/inet6.c,v retrieving revision 1.6 diff -u -r1.6 inet6.c --- inet6.c 2000/08/07 16:39:33 1.6 +++ inet6.c 2001/03/09 20:45:50 @@ -1015,7 +1015,7 @@ register char *cp; static char line[50]; struct hostent *hp; - static char domain[MAXHOSTNAMELEN + 1]; + static char domain[MAXHOSTNAMELEN]; static int first = 1; if (first && !nflag) { Index: main.c =================================================================== RCS file: /home/ncvs/src/usr.bin/netstat/main.c,v retrieving revision 1.37 diff -u -r1.37 main.c --- main.c 2000/08/03 14:53:41 1.37 +++ main.c 2001/03/09 20:56:51 @@ -702,33 +702,3 @@ " netstat [-M core] [-N system] [-p protocol]"); exit(1); } - -void -trimdomain(cp) - char *cp; -{ - static char domain[MAXHOSTNAMELEN + 1]; - static int first = 1; - char *s; - - if (first) { - first = 0; - if (gethostname(domain, MAXHOSTNAMELEN) == 0 && - (s = strchr(domain, '.'))) - (void) strcpy(domain, s + 1); - else - domain[0] = 0; - } - - if (domain[0]) { - while ((cp = strchr(cp, '.'))) { - if (!strcasecmp(cp + 1, domain)) { - *cp = 0; /* hit it */ - break; - } else { - cp++; - } - } - } -} - Index: netstat.h =================================================================== RCS file: /home/ncvs/src/usr.bin/netstat/netstat.h,v retrieving revision 1.18 diff -u -r1.18 netstat.h --- netstat.h 2000/07/05 02:02:54 1.18 +++ netstat.h 2001/03/09 20:55:10 @@ -61,7 +61,6 @@ int kread __P((u_long addr, char *buf, int size)); char *plural __P((int)); char *plurales __P((int)); -void trimdomain __P((char *)); void protopr __P((u_long, char *, int)); void tcp_stats __P((u_long, char *)); Index: route.c =================================================================== RCS file: /home/ncvs/src/usr.bin/netstat/route.c,v retrieving revision 1.45 diff -u -r1.45 route.c --- route.c 2000/09/18 11:14:40 1.45 +++ route.c 2001/03/09 20:56:51 @@ -62,6 +62,7 @@ #include <sys/sysctl.h> #include <arpa/inet.h> +#include <libutil.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> @@ -637,7 +638,7 @@ u_long in; { register char *cp; - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; struct hostent *hp; cp = 0; @@ -646,7 +647,7 @@ AF_INET); if (hp) { cp = hp->h_name; - trimdomain(cp); + trimdomain(cp, strlen(cp)); } } if (cp) { @@ -715,7 +716,7 @@ u_long in, mask; { char *cp = 0; - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; struct netent *np = 0; u_long net, omask, dmask; register u_long i; @@ -729,7 +730,7 @@ np = getnetbyaddr(net, AF_INET); if (np) { cp = np->n_name; - trimdomain(cp); + trimdomain(cp, strlen(cp)); } } if (cp) @@ -753,7 +754,7 @@ struct sockaddr_in6 *sa6; struct in6_addr *mask; { - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; u_char *p = (u_char *)mask; u_char *lim; int masklen, illegal = 0, flag = NI_WITHSCOPEID; @@ -816,7 +817,7 @@ routename6(sa6) struct sockaddr_in6 *sa6; { - static char line[MAXHOSTNAMELEN + 1]; + static char line[MAXHOSTNAMELEN]; int flag = NI_WITHSCOPEID; /* use local variable for safety */ struct sockaddr_in6 sa6_local = {AF_INET6, sizeof(sa6_local),}; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103092125.f29LPju04945>