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/rshd/rshd.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'libexec/rshd/rshd.c') diff --git a/libexec/rshd/rshd.c b/libexec/rshd/rshd.c index 5ed7437b..24b7d35 100644 --- a/libexec/rshd/rshd.c +++ b/libexec/rshd/rshd.c @@ -42,7 +42,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94"; #endif static const char rcsid[] = - "$Id: rshd.c,v 1.23 1998/12/16 07:20:45 peter Exp $"; + "$Id: rshd.c,v 1.24 1999/04/06 23:05:58 brian Exp $"; #endif /* not lint */ /* @@ -216,7 +216,7 @@ doit(fromp) char *errorstr; char *cp, sig, buf[BUFSIZ]; char cmdbuf[NCARGS+1], locuser[16], remuser[16]; - char fromhost[2 * MAXHOSTNAMELEN + 1]; + char fromhost[MAXHOSTNAMELEN]; #ifdef LOGIN_CAP login_cap_t *lc; #endif @@ -348,9 +348,7 @@ doit(fromp) dup2(f, 2); #endif errorstr = NULL; - strncpy(fromhost, inet_ntoa(fromp->sin_addr), - sizeof(fromhost) - 1); - realhostname(fromhost, sizeof fromhost - 1, &fromp->sin_addr); + realhostname(fromhost, sizeof(fromhost) - 1, &fromp->sin_addr); fromhost[sizeof(fromhost) - 1] = '\0'; #ifdef KERBEROS @@ -784,7 +782,8 @@ local_domain(h) char *p1, *p2; localhost[0] = 0; - (void) gethostname(localhost, sizeof(localhost)); + (void) gethostname(localhost, sizeof(localhost) - 1); + localhost[sizeof(localhost) - 1] = '\0'; p1 = topdomain(localhost); p2 = topdomain(h); if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2)) -- cgit v1.1