Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/rshd string manipulation cleanup



details:   https://anonhg.NetBSD.org/src/rev/0bc1dcc7e509
branches:  trunk
changeset: 547393:0bc1dcc7e509
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sat May 17 21:26:47 2003 +0000

description:
string manipulation cleanup

diffstat:

 libexec/rshd/rshd.c |  19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diffs (62 lines):

diff -r 5fba36d6d2b8 -r 0bc1dcc7e509 libexec/rshd/rshd.c
--- a/libexec/rshd/rshd.c       Sat May 17 21:24:38 2003 +0000
+++ b/libexec/rshd/rshd.c       Sat May 17 21:26:47 2003 +0000
@@ -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.
@@ -73,7 +73,7 @@
 #if 0
 static char sccsid[] = "@(#)rshd.c     8.2 (Berkeley) 4/6/94";
 #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 /* not lint */
 
@@ -189,7 +189,7 @@
                char hbuf[NI_MAXHOST];
                if (getnameinfo((struct sockaddr *)&from, fromlen, hbuf,
                                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)",
                    hbuf);
@@ -284,7 +284,7 @@
        if (af == AF_INET)
       {
        u_char optbuf[BUFSIZ/3], *cp;
-       char lbuf[BUFSIZ], *lp;
+       char lbuf[BUFSIZ], *lp, *ep;
        int optsize = sizeof(optbuf), ipproto;
        struct protoent *ip;
 
@@ -295,8 +295,9 @@
        if (!getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf, &optsize) &&
            optsize != 0) {
                lp = lbuf;
+               ep = lbuf + sizeof(lbuf);
                for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3)
-                       sprintf(lp, " %2.2x", *cp);
+                       snprintf(lp, ep - lp, " %2.2x", *cp);
                syslog(LOG_NOTICE,
                    "Connection received from %s using IP options (ignored):%s",
                    naddr, lbuf);
@@ -565,10 +566,10 @@
        }
 #endif
        environ = envinit;
-       strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
-       strcat(path, _PATH_DEFPATH);
-       strncat(shell, pwd->pw_shell, sizeof(shell)-7);
-       strncat(username, pwd->pw_name, sizeof(username)-6);
+       strlcat(homedir, pwd->pw_dir, sizeof(homedir));
+       strlcat(path, _PATH_DEFPATH, sizeof(path));
+       strlcat(shell, pwd->pw_shell, sizeof(shell));
+       strlcat(username, pwd->pw_name, sizeof(username));
 #ifdef LOGIN_CAP
        if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETALL) != 0) {
                syslog(LOG_ERR, "setusercontext: %m");



Home | Main Index | Thread Index | Old Index