Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/bootp use boundedd string ops



details:   https://anonhg.NetBSD.org/src/rev/42aa9417f97c
branches:  trunk
changeset: 549405:42aa9417f97c
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jul 14 06:08:04 2003 +0000

description:
use boundedd string ops

diffstat:

 usr.sbin/bootp/bootpd/bootpd.c       |  22 +++++++++++-----------
 usr.sbin/bootp/bootptest/bootptest.c |   6 +++---
 usr.sbin/bootp/common/hwaddr.c       |  11 ++++++-----
 usr.sbin/bootp/common/readfile.c     |  13 +++++++------
 4 files changed, 27 insertions(+), 25 deletions(-)

diffs (176 lines):

diff -r 0e5eb765763c -r 42aa9417f97c usr.sbin/bootp/bootpd/bootpd.c
--- a/usr.sbin/bootp/bootpd/bootpd.c    Mon Jul 14 06:03:36 2003 +0000
+++ b/usr.sbin/bootp/bootpd/bootpd.c    Mon Jul 14 06:08:04 2003 +0000
@@ -22,7 +22,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: bootpd.c,v 1.18 2003/05/17 20:58:39 itojun Exp $");
+__RCSID("$NetBSD: bootpd.c,v 1.19 2003/07/14 06:08:04 itojun Exp $");
 #endif
 
 /*
@@ -626,7 +626,7 @@
                        return;
                }
        } else {
-               strcpy(bp->bp_sname, hostname);
+               strlcpy(bp->bp_sname, hostname, sizeof(bp->bp_sname));
        }
 
        /* If it uses an unknown network type, ignore the request.  */
@@ -744,10 +744,10 @@
        if (hp->flags.exec_file) {
                char tst[100];
                /* XXX - Check string lengths? -gwr */
-               strcpy (tst, hp->exec_file->string);
-               strcat (tst, " ");
-               strcat (tst, hp->hostname->string);
-               strcat (tst, " &");
+               strlcpy(tst, hp->exec_file->string, sizeof(tst));
+               strlcat(tst, " ", sizeof(tst));
+               strlcat(tst, hp->hostname->string, sizeof(tst));
+               strlcat(tst, " &", sizeof(tst));
                if (debug)
                        report(LOG_INFO, "executing %s", tst);
                system(tst);    /* Hope this finishes soon... */
@@ -877,10 +877,10 @@
        }
        if (bootfile) {
                if (bootfile[0] != '/') {
-                       strcat(realpath, "/");
+                       strlcat(realpath, "/", sizeof(realpath));
                        realpath[sizeof(realpath) - 1] = '\0';
                }
-               strcat(realpath, bootfile);
+               strlcat(realpath, bootfile, sizeof(realpath));
                realpath[sizeof(realpath) - 1] = '\0';
                bootfile = NULL;
        }
@@ -889,8 +889,8 @@
         * First try to find the file with a ".host" suffix
         */
        n = strlen(clntpath);
-       strcat(clntpath, ".");
-       strcat(clntpath, hp->hostname->string);
+       strlcat(clntpath, ".", sizeof(clntpath));
+       strlcat(clntpath, hp->hostname->string, sizeof(clntpath));
        if (chk_access(realpath, &bootsize) < 0) {
                clntpath[n] = 0;                        /* Try it without the suffix */
                if (chk_access(realpath, &bootsize) < 0) {
@@ -1160,7 +1160,7 @@
         * domain name server, ien name server, time server
         */
        vendp = (struct cmu_vend *) bp->bp_vend;
-       strcpy(vendp->v_magic, (char *)vm_cmu);
+       strlcpy(vendp->v_magic, (char *)vm_cmu, sizeof(vendp->v_magic));
        if (hp->flags.subnet_mask) {
                (vendp->v_smask).s_addr = hp->subnet_mask.s_addr;
                (vendp->v_flags) |= VF_SMASK;
diff -r 0e5eb765763c -r 42aa9417f97c usr.sbin/bootp/bootptest/bootptest.c
--- a/usr.sbin/bootp/bootptest/bootptest.c      Mon Jul 14 06:03:36 2003 +0000
+++ b/usr.sbin/bootp/bootptest/bootptest.c      Mon Jul 14 06:08:04 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootptest.c,v 1.12 2003/05/17 20:58:40 itojun Exp $    */
+/*     $NetBSD: bootptest.c,v 1.13 2003/07/14 06:08:04 itojun Exp $    */
 
 /*
  * bootptest.c - Test out a bootp server.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: bootptest.c,v 1.12 2003/05/17 20:58:40 itojun Exp $");
+__RCSID("$NetBSD: bootptest.c,v 1.13 2003/07/14 06:08:04 itojun Exp $");
 #endif
 
 char *usage = "bootptest [-h] server-name [vendor-data-template-file]";
@@ -487,7 +487,7 @@
        u_char *p;
 
        p = (u_char *) ina;
-       sprintf(b, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
+       snprintf(b, sizeof(b), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
        return (b);
 }
 
diff -r 0e5eb765763c -r 42aa9417f97c usr.sbin/bootp/common/hwaddr.c
--- a/usr.sbin/bootp/common/hwaddr.c    Mon Jul 14 06:03:36 2003 +0000
+++ b/usr.sbin/bootp/common/hwaddr.c    Mon Jul 14 06:08:04 2003 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: hwaddr.c,v 1.7 2002/07/14 00:30:02 wiz Exp $   */
+/*     $NetBSD: hwaddr.c,v 1.8 2003/07/14 06:08:05 itojun Exp $        */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: hwaddr.c,v 1.7 2002/07/14 00:30:02 wiz Exp $");
+__RCSID("$NetBSD: hwaddr.c,v 1.8 2003/07/14 06:08:05 itojun Exp $");
 #endif
 
 /*
@@ -138,8 +138,8 @@
        char *a;
 
        a = inet_ntoa(*ia);
-       sprintf(buf, "arp -d %s; arp -s %s %s temp",
-               a, a, haddrtoa(ha, len));
+       snprintf(buf, sizeof(buf), "arp -d %s; arp -s %s %s temp",
+           a, a, haddrtoa(ha, len));
        if (debug > 2)
                report(LOG_INFO, "%s", buf);
        status = system(buf);
@@ -164,7 +164,8 @@
 
        bufptr = haddrbuf;
        while (hlen > 0) {
-               sprintf(bufptr, "%02X:", (unsigned) (*haddr++ & 0xFF));
+               snprintf(bufptr, sizeof(haddrbuf) - (bufptr - haddrbuf),
+                   "%02X:", (unsigned) (*haddr++ & 0xFF));
                bufptr += 3;
                hlen--;
        }
diff -r 0e5eb765763c -r 42aa9417f97c usr.sbin/bootp/common/readfile.c
--- a/usr.sbin/bootp/common/readfile.c  Mon Jul 14 06:03:36 2003 +0000
+++ b/usr.sbin/bootp/common/readfile.c  Mon Jul 14 06:08:04 2003 +0000
@@ -22,7 +22,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: readfile.c,v 1.11 2003/01/28 22:19:30 wiz Exp $");
+__RCSID("$NetBSD: readfile.c,v 1.12 2003/07/14 06:08:05 itojun Exp $");
 #endif
 
 
@@ -337,7 +337,7 @@
 #ifdef DEBUG
        if (debug > 3) {
                char timestr[28];
-               strcpy(timestr, ctime(&(st.st_mtime)));
+               strlcpy(timestr, ctime(&(st.st_mtime)), sizeof(timestr));
                /* zap the newline */
                timestr[24] = '\0';
                report(LOG_INFO, "bootptab mtime: %s",
@@ -805,7 +805,8 @@
        if ((*symbol)[0] == 'T') {      /* generic symbol */
                (*symbol)++;
                value = get_u_long(symbol);
-               sprintf(current_tagname, "T%d", value);
+               snprintf(current_tagname, sizeof(current_tagname),
+                   "T%d", value);
                eat_whitespace(symbol);
                if ((*symbol)[0] != '=') {
                        return E_SYNTAX_ERROR;
@@ -1210,10 +1211,10 @@
        length = sizeof(retstring);
        (void) get_string(src, retstring, &length);
 
-       s = (struct shared_string *) smalloc(sizeof(struct shared_string)
-                                                                                + length);
+       s = (struct shared_string *) smalloc(sizeof(struct shared_string) +
+           length);
        s->linkcount = 1;
-       strcpy(s->string, retstring);
+       strlcpy(s->string, retstring, sizeof(retstring));
 
        return s;
 }



Home | Main Index | Thread Index | Old Index