Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/mopd use snprintf. inspired by openbsd change



details:   https://anonhg.NetBSD.org/src/rev/ff66f57c2ddc
branches:  trunk
changeset: 534018:ff66f57c2ddc
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sat Jul 13 11:35:35 2002 +0000

description:
use snprintf.  inspired by openbsd change

diffstat:

 usr.sbin/mopd/common/device.c |  10 +++++-----
 usr.sbin/mopd/common/pf.c     |   6 +++---
 usr.sbin/mopd/mopd/process.c  |  20 +++++++++++---------
 3 files changed, 19 insertions(+), 17 deletions(-)

diffs (131 lines):

diff -r 523f868fa2d9 -r ff66f57c2ddc usr.sbin/mopd/common/device.c
--- a/usr.sbin/mopd/common/device.c     Sat Jul 13 11:08:03 2002 +0000
+++ b/usr.sbin/mopd/common/device.c     Sat Jul 13 11:35:35 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: device.c,v 1.3 1997/10/16 23:24:28 lukem Exp $ */
+/*     $NetBSD: device.c,v 1.4 2002/07/13 11:35:35 itojun Exp $        */
 
 /*
  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: device.c,v 1.3 1997/10/16 23:24:28 lukem Exp $");
+__RCSID("$NetBSD: device.c,v 1.4 2002/07/13 11:35:35 itojun Exp $");
 #endif
 
 #include "os.h"
@@ -179,12 +179,12 @@
        if ((strlen(dev) == 2) &&
            (dev[0] == 'e') &&
            ((dev[1] == 'n') || (dev[1] == 't'))) {
-               sprintf(interface,"ent%d\0",unit);
+               snprintf(interface, sizeof(interface), "ent%d\0", unit);
        } else {
-               sprintf(interface,"%s%d\0",dev,unit);
+               snprintf(interface, sizeof(interface), "%s%d\0", dev, unit);
        }
 #else
-       sprintf(interface,"%s",ifname);
+       snprintf(interface, sizeof(interface), "%s", ifname);
 #endif /* _AIX */
 
        /* Ok, init it just once */
diff -r 523f868fa2d9 -r ff66f57c2ddc usr.sbin/mopd/common/pf.c
--- a/usr.sbin/mopd/common/pf.c Sat Jul 13 11:08:03 2002 +0000
+++ b/usr.sbin/mopd/common/pf.c Sat Jul 13 11:35:35 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pf.c,v 1.5 1998/05/24 20:30:55 thorpej Exp $   */
+/*     $NetBSD: pf.c,v 1.6 2002/07/13 11:35:35 itojun Exp $    */
 
 /*
  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: pf.c,v 1.5 1998/05/24 20:30:55 thorpej Exp $");
+__RCSID("$NetBSD: pf.c,v 1.6 2002/07/13 11:35:35 itojun Exp $");
 #endif
 
 #include "os.h"
@@ -99,7 +99,7 @@
        
        /* Go through all the minors and find one that isn't in use. */
        do {
-               (void) sprintf(device, "/dev/bpf%d", n++);
+               (void) snprintf(device, sizeof(device), "/dev/bpf%d", n++);
                fd = open(device, mode);
        } while (fd < 0 && errno == EBUSY);
 
diff -r 523f868fa2d9 -r ff66f57c2ddc usr.sbin/mopd/mopd/process.c
--- a/usr.sbin/mopd/mopd/process.c      Sat Jul 13 11:08:03 2002 +0000
+++ b/usr.sbin/mopd/mopd/process.c      Sat Jul 13 11:35:35 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: process.c,v 1.11 2002/02/18 22:00:37 thorpej Exp $     */
+/*     $NetBSD: process.c,v 1.12 2002/07/13 11:35:35 itojun Exp $      */
 
 /*
  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: process.c,v 1.11 2002/02/18 22:00:37 thorpej Exp $");
+__RCSID("$NetBSD: process.c,v 1.12 2002/07/13 11:35:35 itojun Exp $");
 #endif
 
 #include "os.h"
@@ -364,7 +364,7 @@
                close(dle->ldfd);
                dle->ldfd = -1;
                dle->status = DL_STATUS_FREE;
-               sprintf(line,
+               snprintf(line, sizeof(line),
                        "%x:%x:%x:%x:%x:%x Load completed",
                        dst[0],dst[1],dst[2],dst[3],dst[4],dst[5]);
                syslog(LOG_INFO, "%s", line);
@@ -518,8 +518,9 @@
                        /* to ask. My solution is to use the ethernet addr */
                        /* as filename. Implementing a database would be   */
                        /* overkill.                                       */
-                       sprintf(pfile,"%02x%02x%02x%02x%02x%02x%c",
-                               src[0],src[1],src[2],src[3],src[4],src[5],0);
+                       snprintf(pfile, sizeof(pfile),
+                           "%02x%02x%02x%02x%02x%02x%c",
+                           src[0],src[1],src[2],src[3],src[4],src[5],0);
                }
                
                tmpc = mopGetChar(pkt,index);           /* Processor */
@@ -531,17 +532,18 @@
                memmove((char *)(dl_rpr->eaddr), (char *)src, 6);
                mopProcessInfo(pkt,index,moplen,dl_rpr,trans);
 
-               sprintf(filename,"%s/%s.SYS", MOP_FILE_PATH, pfile);
+               snprintf(filename, sizeof(filename), "%s/%s.SYS",
+                   MOP_FILE_PATH, pfile);
                if ((mopCmpEAddr(dst,dl_mcst) == 0)) {
                        if ((nfd = open(filename, O_RDONLY, 0)) != -1) {
                                close(nfd);
                                mopSendASV(src, ii->eaddr, ii, trans);
-                               sprintf(line,
+                               snprintf(line, sizeof(line),
                                        "%x:%x:%x:%x:%x:%x (%d) Do you have %s? (Yes)",
                                        src[0],src[1],src[2],
                                        src[3],src[4],src[5],trans,pfile);
                        } else {
-                               sprintf(line,
+                               snprintf(line, sizeof(line),
                                        "%x:%x:%x:%x:%x:%x (%d) Do you have %s? (No)",
                                        src[0],src[1],src[2],
                                        src[3],src[4],src[5],trans,pfile);
@@ -551,7 +553,7 @@
                        if ((mopCmpEAddr(dst,ii->eaddr) == 0)) {
                                dl_rpr->ldfd = open(filename, O_RDONLY, 0);
                                mopStartLoad(src, ii->eaddr, dl_rpr, trans);
-                               sprintf(line,
+                               snprintf(line, sizeof(line),
                                        "%x:%x:%x:%x:%x:%x Send me %s",
                                        src[0],src[1],src[2],
                                        src[3],src[4],src[5],pfile);



Home | Main Index | Thread Index | Old Index