Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/faithd void unbounded sprintf().



details:   https://anonhg.NetBSD.org/src/rev/218b3cca9496
branches:  trunk
changeset: 479739:218b3cca9496
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Dec 20 16:22:41 1999 +0000

description:
void unbounded sprintf().
fix proc title.

diffstat:

 usr.sbin/faithd/faithd.c |  16 ++++++++------
 usr.sbin/faithd/ftp.c    |  52 ++++++++++++++++++++++++------------------------
 2 files changed, 35 insertions(+), 33 deletions(-)

diffs (truncated from 303 to 300 lines):

diff -r 42702bc2bfb0 -r 218b3cca9496 usr.sbin/faithd/faithd.c
--- a/usr.sbin/faithd/faithd.c  Mon Dec 20 16:03:19 1999 +0000
+++ b/usr.sbin/faithd/faithd.c  Mon Dec 20 16:22:41 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: faithd.c,v 1.6 1999/12/20 16:03:19 itojun Exp $        */
+/*     $NetBSD: faithd.c,v 1.7 1999/12/20 16:22:41 itojun Exp $        */
 
 /*
  * Copyright (C) 1997 and 1998 WIDE Project.
@@ -85,6 +85,7 @@
 char *serverarg[MAXARGV + 1];
 static char *faithdname = NULL;
 char logname[BUFSIZ];
+char procname[BUFSIZ];
 struct myaddrs {
        struct myaddrs *next;
        struct sockaddr *addr;
@@ -169,7 +170,7 @@
 
                memset(&ss, 0, sizeof(ss));
                memset(&hints, 0, sizeof(hints));
-               sprintf(serv, "%u", NAMESERVER_PORT);
+               snprintf(serv, sizeof(serv), "%u", NAMESERVER_PORT);
                hints.ai_flags = AI_NUMERICHOST;
                if (getaddrinfo(ns, serv, &hints, &res) ==  0) {
                        res_init();
@@ -272,7 +273,8 @@
 
        start_daemon();
 
-       sprintf(logname, "accepting port %s", service);
+       snprintf(logname, sizeof(logname), "faithd %s", service);
+       snprintf(procname, sizeof(procname), "accepting port %s", service);
        openlog(logname, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
        syslog(LOG_INFO, "Staring faith daemon for %s port", service);
 
@@ -296,7 +298,7 @@
         * Wait, accept, fork, faith....
         */
 again:
-       setproctitle(logname);
+       setproctitle(procname);
 
        FD_ZERO(&rfds);
        FD_SET(s_wld, &rfds);
@@ -642,7 +644,7 @@
        char buf[BUFSIZ];
 
        va_start(ap, fmt);
-       vsprintf(buf, fmt, ap);
+       vsnprintf(buf, sizeof(buf), fmt, ap);
        va_end(ap);
        fprintf(stderr, "%s\n", buf);
        exit(EXIT_FAILURE);
@@ -655,7 +657,7 @@
        char buf[BUFSIZ];
 
        va_start(ap, fmt);
-       vsprintf(buf, fmt, ap);
+       vsnprintf(buf, sizeof(buf), fmt, ap);
        va_end(ap);
        syslog(LOG_ERR, buf);
        exit(EXIT_FAILURE);
@@ -668,7 +670,7 @@
        char buf[BUFSIZ];
 
        va_start(ap, fmt);
-       vsprintf(buf, fmt, ap);
+       vsnprintf(buf, sizeof(buf), fmt, ap);
        va_end(ap);
        syslog(LOG_INFO, buf);
        exit(EXIT_SUCCESS);
diff -r 42702bc2bfb0 -r 218b3cca9496 usr.sbin/faithd/ftp.c
--- a/usr.sbin/faithd/ftp.c     Mon Dec 20 16:03:19 1999 +0000
+++ b/usr.sbin/faithd/ftp.c     Mon Dec 20 16:22:41 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp.c,v 1.3 1999/12/20 15:35:55 itojun Exp $   */
+/*     $NetBSD: ftp.c,v 1.4 1999/12/20 16:22:41 itojun Exp $   */
 
 /*
  * Copyright (C) 1997 and 1998 WIDE Project.
@@ -404,7 +404,7 @@
        case NONE:
                if (!passivemode && rbuf[0] == '1') {
                        if (ftp_activeconn() < 0) {
-                               n = sprintf(rbuf,
+                               n = snprintf(rbuf, sizeof(rbuf),
                                        "425 Cannot open data connetion\r\n");
                        }
                }
@@ -497,7 +497,7 @@
                wport6 = socket(sin6->sin6_family, SOCK_STREAM, 0);
                if (wport6 == -1) {
 passivefail:
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "500 could not translate from PASV\r\n");
                        write(src, sbuf, n);
                        return n;
@@ -553,7 +553,7 @@
 
                        a = (char *)&sin6->sin6_addr;
                        p = (char *)&sin6->sin6_port;
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
 "228 Entering Long Passive Mode (%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\r\n",
                                6, 16, UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), 
                                UC(a[4]), UC(a[5]), UC(a[6]), UC(a[7]), 
@@ -564,7 +564,7 @@
                        passivemode = 1;
                        return n;
                } else {
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
 "229 Entering Extended Passive Mode (|||%d|)\r\n",
                                ntohs(sin6->sin6_port));
                        write(dst, sbuf, n);
@@ -618,7 +618,7 @@
                wport6 = socket(sin->sin_family, SOCK_STREAM, 0);
                if (wport6 == -1) {
 passivefail2:
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "500 could not translate from EPSV\r\n");
                        write(src, sbuf, n);
                        return n;
@@ -674,7 +674,7 @@
 
                        a = (char *)&sin->sin_addr;
                        p = (char *)&sin->sin_port;
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
 "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n",
                                UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), 
                                UC(p[0]), UC(p[1]));
@@ -778,7 +778,7 @@
                wport4 = wport6 = port4 = port6 = -1;
 
                if (epsvall) {
-                       n = sprintf(sbuf, "501 %s disallowed in EPSV ALL\r\n",
+                       n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n",
                                cmd);
                        write(src, sbuf, n);
                        return n;
@@ -792,7 +792,7 @@
                              &ho[12], &ho[13], &ho[14], &ho[15],
                              &pal, &po[0], &po[1]);
                if (n != 21 || af != 6 || hal != 16|| pal != 2) {
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "501 illegal parameter to LPRT\r\n");
                        write(src, sbuf, n);
                        return n;
@@ -813,7 +813,7 @@
                error = getsockname(dst, (struct sockaddr *)&data4, &n);
                if (error == -1) {
 lprtfail:
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "500 could not translate to PORT\r\n");
                        write(src, sbuf, n);
                        return n;
@@ -854,7 +854,7 @@
                sin = (struct sockaddr_in *)&data4;
                a = (char *)&sin->sin_addr;
                p = (char *)&sin->sin_port;
-               n = sprintf(sbuf, "PORT %d,%d,%d,%d,%d,%d\r\n",
+               n = snprintf(sbuf, sizeof(sbuf), "PORT %d,%d,%d,%d,%d,%d\r\n",
                                  UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),
                                  UC(p[0]), UC(p[1]));
                write(dst, sbuf, n);
@@ -877,7 +877,7 @@
                wport4 = wport6 = port4 = port6 = -1;
 
                if (epsvall) {
-                       n = sprintf(sbuf, "501 %s disallowed in EPSV ALL\r\n",
+                       n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n",
                                cmd);
                        write(src, sbuf, n);
                        return n;
@@ -890,7 +890,7 @@
                        p++;
                if (!*p) {
 eprtparamfail:
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "501 illegal parameter to EPRT\r\n");
                        write(src, sbuf, n);
                        return n;
@@ -911,7 +911,7 @@
 
                n = sscanf(afp, "%d", &af);
                if (n != 1 || af != 2) {
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "501 unsupported address family to EPRT\r\n");
                        write(src, sbuf, n);
                        return n;
@@ -920,13 +920,13 @@
                hints.ai_family = AF_UNSPEC;
                error = getaddrinfo(hostp, portp, &hints, &res);
                if (error) {
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "501 EPRT: %s\r\n", gai_strerror(error));
                        write(src, sbuf, n);
                        return n;
                }
                if (res->ai_next) {
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "501 EPRT: %s resolved to multiple addresses\r\n", hostp);
                        write(src, sbuf, n);
                        return n;
@@ -948,14 +948,14 @@
                wport4 = wport6 = port4 = port6 = -1;
 
                if (epsvall) {
-                       n = sprintf(sbuf, "501 %s disallowed in EPSV ALL\r\n",
+                       n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n",
                                cmd);
                        write(src, sbuf, n);
                        return n;
                }
 
                /* transmit PASV */
-               n = sprintf(sbuf, "PASV\r\n");
+               n = snprintf(sbuf, sizeof(sbuf), "PASV\r\n");
                write(dst, sbuf, n);
                *state = LPSV;
                passivemode = 0;        /* to be set to 1 later */
@@ -970,7 +970,7 @@
                close(port6);
                wport4 = wport6 = port4 = port6 = -1;
 
-               n = sprintf(sbuf, "PASV\r\n");
+               n = snprintf(sbuf, sizeof(sbuf), "PASV\r\n");
                write(dst, sbuf, n);
                *state = EPSV;
                passivemode = 0;        /* to be set to 1 later */
@@ -981,7 +981,7 @@
                 * EPSV ALL
                 */
                epsvall = 1;
-               n = sprintf(sbuf, "200 EPSV ALL command successful.\r\n");
+               n = snprintf(sbuf, sizeof(sbuf), "200 EPSV ALL command successful.\r\n");
                write(src, sbuf, n);
                return n;
 #ifdef FAITH4
@@ -1003,7 +1003,7 @@
                n = sscanf(p, "%u,%u,%u,%u,%u,%u",
                        &ho[0], &ho[1], &ho[2], &ho[3], &po[0], &po[1]);
                if (n != 6) {
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "501 illegal parameter to PORT\r\n");
                        write(src, sbuf, n);
                        return n;
@@ -1023,7 +1023,7 @@
                error = getsockname(dst, (struct sockaddr *)&data4, &n);
                if (error == -1) {
 portfail:
-                       n = sprintf(sbuf,
+                       n = snprintf(sbuf, sizeof(sbuf),
                                "500 could not translate to EPRT\r\n");
                        write(src, sbuf, n);
                        return n;
@@ -1065,7 +1065,7 @@
                        wport4 = -1;
                        goto portfail;
                }
-               n = sprintf(sbuf, "EPRT |%d|%s|%s|\r\n", af, host, serv);
+               n = snprintf(sbuf, sizeof(sbuf), "EPRT |%d|%s|%s|\r\n", af, host, serv);
                write(dst, sbuf, n);
                *state = nstate;
                passivemode = 0;
@@ -1084,7 +1084,7 @@
                wport4 = wport6 = port4 = port6 = -1;
 
                /* transmit EPSV */
-               n = sprintf(sbuf, "EPSV\r\n");
+               n = snprintf(sbuf, sizeof(sbuf), "EPSV\r\n");
                write(dst, sbuf, n);
                *state = PASV;
                passivemode = 0;        /* to be set to 1 later */
@@ -1094,7 +1094,7 @@
                /*
                 * reject PORT/PASV
                 */
-               n = sprintf(sbuf, "502 %s not implemented.\r\n", cmd);
+               n = snprintf(sbuf, sizeof(sbuf), "502 %s not implemented.\r\n", cmd);
                write(src, sbuf, n);
                return n;
 #endif /* FAITH4 */
@@ -1111,7 +1111,7 @@
                 */
 
                if (ftp_passiveconn() < 0) {
-                       n = sprintf(sbuf, "425 Cannot open data connetion\r\n");
+                       n = snprintf(sbuf, sizeof(sbuf), "425 Cannot open data connetion\r\n");



Home | Main Index | Thread Index | Old Index