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/talkd/talkd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libexec/talkd/talkd.c') diff --git a/libexec/talkd/talkd.c b/libexec/talkd/talkd.c index bb61f7e..72e4a5f 100644 --- a/libexec/talkd/talkd.c +++ b/libexec/talkd/talkd.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)talkd.c 8.1 (Berkeley) 6/4/93"; #endif static const char rcsid[] = - "$Id: talkd.c,v 1.8 1997/12/02 12:33:42 charnier Exp $"; + "$Id: talkd.c,v 1.9 1998/12/01 21:12:57 dillon Exp $"; #endif /* not lint */ /* @@ -73,7 +73,7 @@ int sockt; int debug = 0; long lastmsgtime; -char hostname[MAXHOSTNAMELEN + 1]; +char hostname[MAXHOSTNAMELEN]; #define TIMEOUT 30 #define MAXIDLE 120 @@ -97,10 +97,11 @@ main(argc, argv) errx(1, "getuid: not super-user"); #endif openlog("talkd", LOG_PID, LOG_DAEMON); - if (gethostname(hostname, sizeof (hostname) - 1) < 0) { + if (gethostname(hostname, sizeof(hostname) - 1) < 0) { syslog(LOG_ERR, "gethostname: %m"); _exit(1); } + hostname[sizeof(hostname) - 1] = '\0'; if (chdir(_PATH_DEV) < 0) { syslog(LOG_ERR, "chdir: %s: %m", _PATH_DEV); _exit(1); -- cgit v1.1