From c6c6c7de65eae103002ebb9bee8881e1e2e903df Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 7 Apr 1999 08:27:45 +0000 Subject: Ensure that things returned by gethostname() and friends are terminated and allow for a maximum host name length of MAXHOSTNAMELEN - 1. Put parenthesis around sizeof args. Make some variables static. Fix telnetd -u (broken by my last commit) Prompted by: bde --- libexec/telnetd/sys_term.c | 3 +-- libexec/telnetd/telnetd.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'libexec/telnetd') diff --git a/libexec/telnetd/sys_term.c b/libexec/telnetd/sys_term.c index c08228e..d53c6c7 100644 --- a/libexec/telnetd/sys_term.c +++ b/libexec/telnetd/sys_term.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)sys_term.c 8.2 (Berkeley) 12/15/93"; #endif static const char rcsid[] = - "$Id: sys_term.c,v 1.19 1997/12/24 19:21:09 imp Exp $"; + "$Id: sys_term.c,v 1.20 1998/05/14 10:07:29 jb Exp $"; #endif /* not lint */ #include "telnetd.h" @@ -52,7 +52,6 @@ extern char *altlogin; # define PARENT_DOES_UTMP #endif -int utmp_len = MAXHOSTNAMELEN; #ifdef NEWINIT #include #else /* NEWINIT*/ diff --git a/libexec/telnetd/telnetd.c b/libexec/telnetd/telnetd.c index 8baaaf4..fd4b6da 100644 --- a/libexec/telnetd/telnetd.c +++ b/libexec/telnetd/telnetd.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)telnetd.c 8.2 (Berkeley) 12/15/93"; #endif static const char rcsid[] = - "$Id: telnetd.c,v 1.16 1999/04/06 00:29:41 brian Exp $"; + "$Id: telnetd.c,v 1.17 1999/04/06 23:05:58 brian Exp $"; #endif /* not lint */ #include "telnetd.h" @@ -90,7 +90,8 @@ int auth_level = 0; int require_SecurID = 0; #endif -extern int utmp_len; +char remote_hostname[UT_HOSTSIZE + 1]; +int utmp_len = sizeof(remote_hostname) - 1; int registerd_host_only = 0; #ifdef STREAMSPTY @@ -361,6 +362,10 @@ main(argc, argv) case 'u': utmp_len = atoi(optarg); + if (utmp_len < 0) + utmp_len = -utmp_len; + if (utmp_len >= sizeof(remote_hostname)) + utmp_len = sizeof(remote_hostname) - 1; break; case 'U': @@ -758,7 +763,6 @@ terminaltypeok(s) char *hostname; char host_name[MAXHOSTNAMELEN]; -char remote_hostname[UT_HOSTSIZE + 1]; extern void telnet P((int, int, char *)); @@ -813,12 +817,14 @@ doit(who) #endif /* _SC_CRAY_SECURE_SYS */ /* get name of connected client */ - if (realhostname(remote_hostname, sizeof remote_hostname - 1, + if (realhostname(remote_hostname, utmp_len, &who->sin_addr) == HOSTNAME_INVALIDADDR && registerd_host_only) fatal(net, "Couldn't resolve your address into a host name.\r\n\ Please contact your net administrator"); + remote_hostname[utmp_len] = '\0'; - (void) gethostname(host_name, sizeof (host_name)); + (void) gethostname(host_name, sizeof(host_name) - 1); + host_name[sizeof(host_name) - 1] = '\0'; hostname = host_name; #if defined(AUTHENTICATION) -- cgit v1.1