string manipulation cleanup

This commit is contained in:
itojun 2003-05-17 21:26:47 +00:00
parent bb3fc85900
commit 5a8065df69
1 changed files with 10 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rshd.c,v 1.29 2003/03/03 18:29:55 dsl Exp $ */ /* $NetBSD: rshd.c,v 1.30 2003/05/17 21:26:47 itojun Exp $ */
/* /*
* Copyright (C) 1998 WIDE Project. * Copyright (C) 1998 WIDE Project.
@ -73,7 +73,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1992, 1993, 1994\n\
#if 0 #if 0
static char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94"; static char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94";
#else #else
__RCSID("$NetBSD: rshd.c,v 1.29 2003/03/03 18:29:55 dsl Exp $"); __RCSID("$NetBSD: rshd.c,v 1.30 2003/05/17 21:26:47 itojun Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -189,7 +189,7 @@ main(int argc, char *argv[])
char hbuf[NI_MAXHOST]; char hbuf[NI_MAXHOST];
if (getnameinfo((struct sockaddr *)&from, fromlen, hbuf, if (getnameinfo((struct sockaddr *)&from, fromlen, hbuf,
sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) { sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) {
strncpy(hbuf, "invalid", sizeof(hbuf)); strlcpy(hbuf, "invalid", sizeof(hbuf));
} }
syslog(LOG_ERR, "malformed \"from\" address (v4 mapped, %s)", syslog(LOG_ERR, "malformed \"from\" address (v4 mapped, %s)",
hbuf); hbuf);
@ -284,7 +284,7 @@ doit(struct sockaddr *fromp)
if (af == AF_INET) if (af == AF_INET)
{ {
u_char optbuf[BUFSIZ/3], *cp; u_char optbuf[BUFSIZ/3], *cp;
char lbuf[BUFSIZ], *lp; char lbuf[BUFSIZ], *lp, *ep;
int optsize = sizeof(optbuf), ipproto; int optsize = sizeof(optbuf), ipproto;
struct protoent *ip; struct protoent *ip;
@ -295,8 +295,9 @@ doit(struct sockaddr *fromp)
if (!getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf, &optsize) && if (!getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf, &optsize) &&
optsize != 0) { optsize != 0) {
lp = lbuf; lp = lbuf;
ep = lbuf + sizeof(lbuf);
for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3) for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3)
sprintf(lp, " %2.2x", *cp); snprintf(lp, ep - lp, " %2.2x", *cp);
syslog(LOG_NOTICE, syslog(LOG_NOTICE,
"Connection received from %s using IP options (ignored):%s", "Connection received from %s using IP options (ignored):%s",
naddr, lbuf); naddr, lbuf);
@ -565,10 +566,10 @@ fail:
} }
#endif #endif
environ = envinit; environ = envinit;
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6); strlcat(homedir, pwd->pw_dir, sizeof(homedir));
strcat(path, _PATH_DEFPATH); strlcat(path, _PATH_DEFPATH, sizeof(path));
strncat(shell, pwd->pw_shell, sizeof(shell)-7); strlcat(shell, pwd->pw_shell, sizeof(shell));
strncat(username, pwd->pw_name, sizeof(username)-6); strlcat(username, pwd->pw_name, sizeof(username));
#ifdef LOGIN_CAP #ifdef LOGIN_CAP
if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETALL) != 0) { if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETALL) != 0) {
syslog(LOG_ERR, "setusercontext: %m"); syslog(LOG_ERR, "setusercontext: %m");