Source-Changes-HG archive

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

[src/netbsd-1-4]: src/usr.sbin/tcpdump Pull up revision 1.7 (requested by he):



details:   https://anonhg.NetBSD.org/src/rev/96f477211be0
branches:  netbsd-1-4
changeset: 471198:96f477211be0
user:      he <he%NetBSD.org@localhost>
date:      Tue Oct 31 13:53:50 2000 +0000

description:
Pull up revision 1.7 (requested by he):
  Change from sprintf() to snprintf() where we may print externally
  supplied data of unknown length.

diffstat:

 usr.sbin/tcpdump/print-icmp.c |  52 ++++++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 22 deletions(-)

diffs (169 lines):

diff -r 0a77df1b1944 -r 96f477211be0 usr.sbin/tcpdump/print-icmp.c
--- a/usr.sbin/tcpdump/print-icmp.c     Tue Oct 31 13:53:26 2000 +0000
+++ b/usr.sbin/tcpdump/print-icmp.c     Tue Oct 31 13:53:50 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print-icmp.c,v 1.5 1997/10/03 19:55:15 christos Exp $  */
+/*     $NetBSD: print-icmp.c,v 1.5.4.1 2000/10/31 13:53:50 he Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
@@ -27,7 +27,7 @@
 static const char rcsid[] =
     "@(#) Header: print-icmp.c,v 1.38 96/09/26 23:36:44 leres Exp  (LBL)";
 #else
-__RCSID("$NetBSD: print-icmp.c,v 1.5 1997/10/03 19:55:15 christos Exp $");
+__RCSID("$NetBSD: print-icmp.c,v 1.5.4.1 2000/10/31 13:53:50 he Exp $");
 #endif
 #endif
 
@@ -183,7 +183,7 @@
        register const struct ip *oip;
        register const struct udphdr *ouh;
        register u_int hlen, dport, mtu;
-       char buf[256];
+       char buf[MAXHOSTNAMELEN + 100];
 
        dp = (struct icmp *)bp;
        ip = (struct ip *)bp2;
@@ -202,7 +202,8 @@
 
                case ICMP_UNREACH_PROTOCOL:
                        TCHECK(dp->icmp_ip.ip_p);
-                       (void)sprintf(buf, "%s protocol %d unreachable",
+                       (void)snprintf(buf, sizeof(buf),
+                                      "%s protocol %d unreachable",
                                       ipaddr_string(&dp->icmp_ip.ip_dst),
                                       dp->icmp_ip.ip_p);
                        break;
@@ -216,21 +217,21 @@
                        switch (oip->ip_p) {
 
                        case IPPROTO_TCP:
-                               (void)sprintf(buf,
+                               (void)snprintf(buf, sizeof(buf),
                                        "%s tcp port %s unreachable",
                                        ipaddr_string(&oip->ip_dst),
                                        tcpport_string(dport));
                                break;
 
                        case IPPROTO_UDP:
-                               (void)sprintf(buf,
+                               (void)snprintf(buf, sizeof(buf),
                                        "%s udp port %s unreachable",
                                        ipaddr_string(&oip->ip_dst),
                                        udpport_string(dport));
                                break;
 
                        default:
-                               (void)sprintf(buf,
+                               (void)snprintf(buf, sizeof(buf),
                                        "%s protocol %d port %d unreachable",
                                        ipaddr_string(&oip->ip_dst),
                                        oip->ip_p, dport);
@@ -245,11 +246,11 @@
                        mp = (struct mtu_discovery *)&dp->icmp_void;
                         mtu = EXTRACT_16BITS(&mp->nexthopmtu);
                         if (mtu)
-                           (void)sprintf(buf,
+                           (void)snprintf(buf, sizeof(buf),
                                "%s unreachable - need to frag (mtu %d)",
                                ipaddr_string(&dp->icmp_ip.ip_dst), mtu);
                         else
-                           (void)sprintf(buf,
+                           (void)snprintf(buf, sizeof(buf),
                                "%s unreachable - need to frag",
                                ipaddr_string(&dp->icmp_ip.ip_dst));
                        }
@@ -258,7 +259,7 @@
                default:
                        fmt = tok2str(unreach2str, "#%d %%s unreachable",
                            dp->icmp_code);
-                       (void)sprintf(buf, fmt,
+                       (void)snprintf(buf, sizeof(buf), fmt,
                            ipaddr_string(&dp->icmp_ip.ip_dst));
                        break;
                }
@@ -268,7 +269,7 @@
                TCHECK(dp->icmp_ip.ip_dst);
                fmt = tok2str(type2str, "redirect-#%d %%s to net %%s",
                    dp->icmp_code);
-               (void)sprintf(buf, fmt,
+               (void)snprintf(buf, sizeof(buf), fmt,
                    ipaddr_string(&dp->icmp_ip.ip_dst),
                    ipaddr_string(&dp->icmp_gwaddr));
                break;
@@ -288,30 +289,34 @@
                cp = buf + strlen(buf);
                lifetime = EXTRACT_16BITS(&ihp->ird_lifetime);
                if (lifetime < 60)
-                       (void)sprintf(cp, "%u", lifetime);
+                       (void)snprintf(cp, sizeof(buf) - strlen(buf),
+                                      "%u", lifetime);
                else if (lifetime < 60 * 60)
-                       (void)sprintf(cp, "%u:%02u",
-                           lifetime / 60, lifetime % 60);
+                       (void)snprintf(cp, sizeof(buf) - strlen(buf),
+                           "%u:%02u", lifetime / 60, lifetime % 60);
                else
-                       (void)sprintf(cp, "%u:%02u:%02u",
+                       (void)snprintf(cp, sizeof(buf) - strlen(buf),
+                           "%u:%02u:%02u",
                            lifetime / 3600,
                            (lifetime % 3600) / 60,
                            lifetime % 60);
                cp = buf + strlen(buf);
 
                num = ihp->ird_addrnum;
-               (void)sprintf(cp, " %d:", num);
+               (void)snprintf(cp, sizeof(buf) - strlen(buf), " %d:", num);
                cp = buf + strlen(buf);
 
                size = ihp->ird_addrsiz;
                if (size != 2) {
-                       (void)sprintf(cp, " [size %d]", size);
+                       (void)snprintf(cp, sizeof(buf) - strlen(buf),
+                                      " [size %d]", size);
                        break;
                }
                idp = (struct id_rdiscovery *)&dp->icmp_data;
                while (num-- > 0) {
                        TCHECK(*idp);
-                       (void)sprintf(cp, " {%s %u}",
+                       (void)snprintf(cp, sizeof(buf) - strlen(buf),
+                           " {%s %u}",
                            ipaddr_string(&idp->ird_addr),
                            EXTRACT_32BITS(&idp->ird_pref));
                        cp = buf + strlen(buf);
@@ -332,25 +337,28 @@
                        break;
 
                default:
-                       (void)sprintf(buf, "time exceeded-#%d", dp->icmp_code);
+                       (void)snprintf(buf, sizeof(buf),
+                                       "time exceeded-#%d", dp->icmp_code);
                        break;
                }
                break;
 
        case ICMP_PARAMPROB:
                if (dp->icmp_code)
-                       (void)sprintf(buf, "parameter problem - code %d",
+                       (void)snprintf(buf, sizeof(buf),
+                                       "parameter problem - code %d",
                                        dp->icmp_code);
                else {
                        TCHECK(dp->icmp_pptr);
-                       (void)sprintf(buf, "parameter problem - octet %d",
+                       (void)snprintf(buf, sizeof(buf),
+                                       "parameter problem - octet %d",
                                        dp->icmp_pptr);
                }
                break;
 
        case ICMP_MASKREPLY:
                TCHECK(dp->icmp_mask);
-               (void)sprintf(buf, "address mask is 0x%08x",
+               (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x",
                    (u_int32_t)ntohl(dp->icmp_mask));
                break;
 



Home | Main Index | Thread Index | Old Index