s/sprintf/snprintf/.
authoritojun <itojun>
Mon, 17 Jan 2000 06:24:23 +0000 (06:24 +0000)
committeritojun <itojun>
Mon, 17 Jan 2000 06:24:23 +0000 (06:24 +0000)
there seem to be couple of unsafe use of strcat and strcpy - we should
bring in strl{cat,cpy}.

17 files changed:
addrtoname.c
machdep.c
machdep.h
print-ascii.c
print-atalk.c
print-bgp.c
print-decnet.c
print-icmp.c
print-ipx.c
print-isakmp.c
print-ppp.c
print-snmp.c
print-sunrpc.c
print-telnet.c
smbutil.c
tcpdump.c
util.c

index 0eba77374541a91d2d8a761eb01af19fd7c2ea26..b0ab0059369bcece917167b1b0fadf5fa75f5f14 100644 (file)
@@ -23,7 +23,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.64 1999-11-21 09:36:44 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.65 2000-01-17 06:24:23 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -556,7 +556,7 @@ tcpport_string(u_short port)
        tp->addr = i;
        tp->nxt = newhnamemem();
 
-       (void)sprintf(buf, "%u", i);
+       (void)snprintf(buf, sizeof(buf), "%u", i);
        tp->name = savestr(buf);
        return (tp->name);
 }
@@ -575,7 +575,7 @@ udpport_string(register u_short port)
        tp->addr = i;
        tp->nxt = newhnamemem();
 
-       (void)sprintf(buf, "%u", i);
+       (void)snprintf(buf, sizeof(buf), "%u", i);
        tp->name = savestr(buf);
        return (tp->name);
 }
@@ -601,7 +601,7 @@ init_servarray(void)
                while (table->name)
                        table = table->nxt;
                if (nflag) {
-                       (void)sprintf(buf, "%d", port);
+                       (void)snprintf(buf, sizeof(buf), "%d", port);
                        table->name = savestr(buf);
                } else
                        table->name = savestr(sv->s_name);
index 6211930d7861890a540f14f7a05a28f2d4d40931..8c7c4a5b0cda842ca24410d3af148b55a2dbf9c4 100644 (file)
--- a/machdep.c
+++ b/machdep.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/machdep.c,v 1.5 1999-11-21 09:36:47 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/machdep.c,v 1.6 2000-01-17 06:24:23 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -37,13 +37,13 @@ static const char rcsid[] =
 #include "machdep.h"
 
 int
-abort_on_misalignment(char *ebuf)
+abort_on_misalignment(char *ebuf, size_t ebufsiz)
 {
 #ifdef __osf__
        static int buf[2] = { SSIN_UACPROC, UAC_SIGBUS };
 
        if (setsysinfo(SSI_NVPAIRS, (caddr_t)buf, 1, 0, 0) < 0) {
-               (void)sprintf(ebuf, "setsysinfo: errno %d", errno);
+               (void)snprintf(ebuf, ebufsiz, "setsysinfo: errno %d", errno);
                return (-1);
        }
 #endif
index f648103598f1b1c877d317a368ccf2174635b11c..6328c8265947159a4753236a3c8c4f26846a27e5 100644 (file)
--- a/machdep.h
+++ b/machdep.h
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/machdep.h,v 1.1 1999-10-07 23:47:10 mcr Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/machdep.h,v 1.2 2000-01-17 06:24:24 itojun Exp $ (LBL)
  */
 #ifndef tcpdump_machdep_h
 #define tcpdump_machdep_h
 
-int abort_on_misalignment(char *);
+int abort_on_misalignment(char *, size_t);
 #endif
index 882f24742dacce431fdddd2e843af743852e703e..a97faf7767c2f713839a8a3c93a92ff7d4e2d8b9 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.4 2000-01-09 21:34:16 fenner Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.5 2000-01-17 06:24:24 itojun Exp $";
 #endif
 #include <stdio.h>
 #include <sys/types.h>
@@ -72,7 +72,7 @@ ascii_print_with_offset(register const u_char *cp, register u_int length,
        while (--nshorts >= 0) {
                s1 = *cp++;
                s2 = *cp++;
-               (void)sprintf(hsp, " %02x%02x", s1, s2);
+               (void)snprintf(hsp, sizeof(hsp), " %02x%02x", s1, s2);
                hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
                *(asp++) = (isgraph(s1) ? s1 : '.');
                *(asp++) = (isgraph(s2) ? s2 : '.');
@@ -87,7 +87,7 @@ ascii_print_with_offset(register const u_char *cp, register u_int length,
        }
        if (length & 1) {
                s1 = *cp++;
-               (void)sprintf(hsp, " %02x", s1);
+               (void)snprintf(hsp, sizeof(hsp), " %02x", s1);
                hsp += 3;
                *(asp++) = (isgraph(s1) ? s1 : '.');
                ++i;
index 5134ebc19933234e3f7f5290ebc6dc0906e94fb9..f4df1482f55f1ec8a48f458904355589446a6a46 100644 (file)
@@ -23,7 +23,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.51 1999-11-21 09:36:48 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.52 2000-01-17 06:24:24 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -538,7 +538,8 @@ ataddr_string(u_short atnet, u_char athost)
                if (tp2->addr == i) {
                        tp->addr = (atnet << 8) | athost;
                        tp->nxt = newhnamemem();
-                       (void)sprintf(nambuf, "%s.%d", tp2->name, athost);
+                       (void)snprintf(nambuf, sizeof(nambuf), "%s.%d",
+                           tp2->name, athost);
                        tp->name = savestr(nambuf);
                        return (tp->name);
                }
@@ -546,10 +547,11 @@ ataddr_string(u_short atnet, u_char athost)
        tp->addr = (atnet << 8) | athost;
        tp->nxt = newhnamemem();
        if (athost != 255)
-               (void)sprintf(nambuf, "%d.%d.%d",
+               (void)snprintf(nambuf, sizeof(nambuf), "%d.%d.%d",
                    atnet >> 8, atnet & 0xff, athost);
        else
-               (void)sprintf(nambuf, "%d.%d", atnet >> 8, atnet & 0xff);
+               (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8,
+                   atnet & 0xff);
        tp->name = savestr(nambuf);
 
        return (tp->name);
@@ -569,7 +571,7 @@ ddpskt_string(register int skt)
        static char buf[8];
 
        if (nflag) {
-               (void)sprintf(buf, "%d", skt);
+               (void)snprintf(buf, sizeof(buf), "%d", skt);
                return (buf);
        }
        return (tok2str(skt2str, "%d", skt));
index bc4cc4ad3f145e7c315b8c7d374185dcbd747526..e7ecfa4c33bc0ba4eabd21adf1835cb4591ef562 100644 (file)
@@ -33,7 +33,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.10 2000-01-09 21:34:17 fenner Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.11 2000-01-17 06:24:24 itojun Exp $";
 #endif
 
 #include <sys/param.h>
@@ -240,7 +240,7 @@ num_or_str(const char **table, size_t siz, int value)
 {
        static char buf[20];
        if (value < 0 || siz <= value || table[value] == NULL) {
-               sprintf(buf, "#%d", value);
+               snprintf(buf, sizeof(buf), "#%d", value);
                return buf;
        } else
                return table[value];
@@ -266,7 +266,7 @@ bgp_notify_minor(int major, int minor)
        } else
                p = NULL;
        if (p == NULL) {
-               sprintf(buf, "#%d", minor);
+               snprintf(buf, sizeof(buf), "#%d", minor);
                return buf;
        } else
                return p;
@@ -288,7 +288,7 @@ decode_prefix4(const u_char *pd, char *buf, int buflen)
                ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
                        ((0xff00 >> (plen % 8)) & 0xff);
        }
-       sprintf(buf, "%s/%d", getname((char *)&addr), plen);
+       snprintf(buf, buflen, "%s/%d", getname((char *)&addr), plen);
        return 1 + (plen + 7) / 8;
 }
 
@@ -309,7 +309,7 @@ decode_prefix6(const u_char *pd, char *buf, int buflen)
                addr.s6_addr[(plen + 7) / 8 - 1] &=
                        ((0xff00 >> (plen % 8)) & 0xff);
        }
-       sprintf(buf, "%s/%d", getname6((char *)&addr), plen);
+       snprintf(buf, buflen, "%s/%d", getname6((char *)&addr), plen);
        return 1 + (plen + 7) / 8;
 }
 #endif
index aefca10a0beb7615650b769510e18cf9cc7d7659..4c290f9ef8552e96b28015e7a41aa4ab8338dbb8 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.27 1999-11-21 09:36:50 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.28 2000-01-17 06:24:24 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -740,13 +740,14 @@ char *
 dnnum_string(u_short dnaddr)
 {
        char *str;
+       size_t siz;
        int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
        int node = dnaddr & NODEMASK;
 
-       str = (char *)malloc(sizeof("00.0000"));
+       str = (char *)malloc(siz = sizeof("00.0000"));
        if (str == NULL)
                error("dnnum_string: malloc");
-       sprintf(str, "%d.%d", area, node);
+       snprintf(str, siz, "%d.%d", area, node);
        return(str);
 }
 
index 5895ce983d383b267db0a43f5687541832a83c59..38c1fa8f58520f19c692fffdb364e607127830a1 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.43 1999-11-22 04:28:21 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.44 2000-01-17 06:24:25 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -196,9 +196,10 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
 
                case ICMP_UNREACH_PROTOCOL:
                        TCHECK(dp->icmp_ip.ip_p);
-                       (void)sprintf(buf, "%s protocol %d unreachable",
-                                      ipaddr_string(&dp->icmp_ip.ip_dst),
-                                      dp->icmp_ip.ip_p);
+                       (void)snprintf(buf, sizeof(buf),
+                           "%s protocol %d unreachable",
+                           ipaddr_string(&dp->icmp_ip.ip_dst),
+                           dp->icmp_ip.ip_p);
                        break;
 
                case ICMP_UNREACH_PORT:
@@ -210,21 +211,21 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
                        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);
@@ -239,11 +240,11 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
                        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));
                        }
@@ -252,7 +253,7 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
                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;
                }
@@ -262,7 +263,7 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
                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;
@@ -278,34 +279,37 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
 
                ihp = (struct ih_rdiscovery *)&dp->icmp_void;
                TCHECK(*ihp);
-               (void)strcpy(cp, " lifetime ");
+               (void)strncpy(cp, " lifetime ", sizeof(buf) - (cp - buf));
                cp = buf + strlen(buf);
                lifetime = EXTRACT_16BITS(&ihp->ird_lifetime);
                if (lifetime < 60)
-                       (void)sprintf(cp, "%u", lifetime);
+                       (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u",
+                           lifetime);
                else if (lifetime < 60 * 60)
-                       (void)sprintf(cp, "%u:%02u",
+                       (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u:%02u",
                            lifetime / 60, lifetime % 60);
                else
-                       (void)sprintf(cp, "%u:%02u:%02u",
+                       (void)snprintf(cp, sizeof(buf) - (cp - 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) - (cp - 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) - (cp - 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) - (cp - buf), " {%s %u}",
                            ipaddr_string(&idp->ird_addr),
                            EXTRACT_32BITS(&idp->ird_pref));
                        cp = buf + strlen(buf);
@@ -326,25 +330,26 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
                        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",
-                                       dp->icmp_code);
+                       (void)snprintf(buf, sizeof(buf),
+                           "parameter problem - code %d", dp->icmp_code);
                else {
                        TCHECK(dp->icmp_pptr);
-                       (void)sprintf(buf, "parameter problem - octet %d",
-                                       dp->icmp_pptr);
+                       (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;
 
index 83b8330a1f7687c9b585164ca116a931a5808b72..a5decb4a7b2b20fe1d004920d3d98b576e36afb0 100644 (file)
@@ -24,7 +24,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.22 1999-11-21 09:36:54 fenner Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.23 2000-01-17 06:24:25 itojun Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -92,7 +92,7 @@ ipxaddr_string(u_int32_t net, const u_char *node)
 {
     static char line[256];
 
-    sprintf(line, "%x.%02x:%02x:%02x:%02x:%02x:%02x",
+    snprintf(line, sizeof(line), "%x.%02x:%02x:%02x:%02x:%02x:%02x",
            net, node[0], node[1], node[2], node[3], node[4], node[5]);
 
     return line;
index 8d19c3a8357d888d5ff31517c5c795a700e197f3..5f4abc00aa1e5dda5b2c0b4abdccf26cf73de1ec 100644 (file)
@@ -30,7 +30,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.9 2000-01-07 14:09:02 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.10 2000-01-17 06:24:25 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -989,7 +989,7 @@ static char *
 numstr(int x)
 {
        static char buf[20];
-       sprintf(buf, "#%d", x);
+       snprintf(buf, sizeof(buf), "#%d", x);
        return buf;
 }
 
index 1d242efc26259ca462ee41a55928a121a1562e38..55404ec5f7f8c0023862b0e243acfc71671a876c 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.33 1999-12-22 06:27:22 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.34 2000-01-17 06:24:26 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -221,7 +221,7 @@ ppp_protoname(int proto)
        case PPP_CHAP:  return "CHAP";
 #endif
        default:
-               sprintf(buf, "unknown-0x%04x\n", proto);
+               snprintf(buf, sizeof(buf), "unknown-0x%04x\n", proto);
                return buf;
        }
 }
index b5835dc1033c06f5e29d73242a73ea8950582163..503fc96799fed38ca386331c13aaccd97d6084ff 100644 (file)
@@ -45,7 +45,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.39 1999-12-22 06:27:22 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.40 2000-01-17 06:24:26 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -188,7 +188,8 @@ char *ErrorStatus[] = {
 };
 #define DECODE_ErrorStatus(e) \
        ( e >= 0 && e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \
-       ? ErrorStatus[e] : (sprintf(errbuf, "err=%u", e), errbuf))
+               ? ErrorStatus[e] \
+               : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf))
 
 /*
  * generic-trap values in the SNMP Trap-PDU
@@ -205,7 +206,8 @@ char *GenericTrap[] = {
 };
 #define DECODE_GenericTrap(t) \
        ( t >= 0 && t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \
-       ? GenericTrap[t] : (sprintf(buf, "gt=%d", t), buf))
+               ? GenericTrap[t] \
+               : (snprintf(buf, sizeof(buf), "gt=%d", t), buf))
 
 /*
  * ASN.1 type class table
@@ -730,11 +732,12 @@ asn1_print(struct be *elem)
                }
                d += (elem->data.uns64.low & 0xfffff000);
 #if 0 /*is looks illegal, but what is the intention???*/
-               sprintf(first, "%.f", d);
+               snprintf(first, sizeof(first), "%.f", d);
 #else
-               sprintf(first, "%f", d);
+               snprintf(first, sizeof(first), "%f", d);
 #endif
-               sprintf(last, "%5.5d", elem->data.uns64.low & 0xfff);
+               snprintf(last, sizeof(last), "%5.5d",
+                   elem->data.uns64.low & 0xfff);
                for (carry = 0, cpf = first+strlen(first)-1, cpl = last+4;
                     cpl >= last;
                     cpf--, cpl--) {
index bc4dc5c536336d2b7b1c9b9b645ee8340432c37e..529bf36ab37d5c9124428848ab7e1e34ad49660c 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-sunrpc.c,v 1.29 1999-11-21 09:37:02 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-sunrpc.c,v 1.30 2000-01-17 06:24:26 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -129,7 +129,7 @@ progstr(prog)
                return (buf);
        rp = getrpcbynumber(prog);
        if (rp == NULL)
-               (void) sprintf(buf, "#%u", prog);
+               (void) snprintf(buf, sizeof(buf), "#%u", prog);
        else
                strcpy(buf, rp->r_name);
        return (buf);
index beb6be9105cc747c7902744f59d70cc701f7cf36..cdce8398c2009f86e14dac72f717c77030867bd6 100644 (file)
@@ -51,7 +51,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.5 2000-01-09 21:34:20 fenner Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.6 2000-01-17 06:24:26 itojun Exp $";
 #endif
 
 #include <sys/param.h>
@@ -127,15 +127,16 @@ telnet_print(register const u_char *sp, u_int length)
                                x = *sp++; /* option */
                                length--;
                                if (x >= 0 && x < NTELOPTS) {
-                                       (void)sprintf(tnet, "%s %s",
-                                                     telcmds[i], telopts[x]);
+                                       (void)snprintf(tnet, sizeof(tnet),
+                                           "%s %s", telcmds[i], telopts[x]);
                                } else {
-                                       (void)sprintf(tnet, "%s %#x",
-                                                     telcmds[i], x);
+                                       (void)snprintf(tnet, sizeof(tnet),
+                                           "%s %#x", telcmds[i], x);
                                }
                                break;
                        default:
-                               (void)strcpy(tnet, telcmds[i]);
+                               (void)snprintf(tnet, sizeof(tnet), "%s",
+                                   telcmds[i]);
                        }
                        if (c == SB) {
                                c = *sp++;
index 14e5c1db6206473fdbfc5f22eaccdef31a9c821c..c822d72dd173ac0181a9b40342237af05fea5c28 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -11,7 +11,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.5 2000-01-09 21:34:20 fenner Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.6 2000-01-17 06:24:27 itojun Exp $";
 #endif
 
 #include <sys/param.h>
@@ -680,17 +680,17 @@ char *smb_errstr(int class,int num)
            for (j=0;err[j].name;j++)
              if (num == err[j].code)
                {
-                 sprintf(ret,"%s - %s (%s)",err_classes[i].class,
+                 snprintf(ret,sizeof(ret),"%s - %s (%s)",err_classes[i].class,
                          err[j].name,err[j].message);
                  return ret;
                }
          }
 
-       sprintf(ret,"%s - %d",err_classes[i].class,num);
+       snprintf(ret,sizeof(ret),"%s - %d",err_classes[i].class,num);
        return ret;
       }
   
-  sprintf(ret,"ERROR: Unknown error (%d,%d)",class,num);
+  snprintf(ret,sizeof(ret),"ERROR: Unknown error (%d,%d)",class,num);
   return(ret);
 }
 
index b3dd9e7bbaba4a432cf9aff2c4f6bc1fb4a0bb29..8384218dccb04fb73f23ffdb7691b6b99d14a45c 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -24,7 +24,7 @@ static const char copyright[] =
     "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\
 The Regents of the University of California.  All rights reserved.\n";
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.141 2000-01-15 07:42:32 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.142 2000-01-17 06:24:27 itojun Exp $ (LBL)";
 #endif
 
 /*
@@ -166,7 +166,7 @@ main(int argc, char **argv)
        else
                program_name = argv[0];
 
-       if (abort_on_misalignment(ebuf) < 0)
+       if (abort_on_misalignment(ebuf, sizeof(ebuf)) < 0)
                error("%s", ebuf);
 
 #ifdef LIBSMI
diff --git a/util.c b/util.c
index 951004d66db93790da41693f90f8f1ee2ceca69e..9e611ae52ffe08970e4bbe1203c3fa75545b7df8 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.62 1999-12-15 06:58:03 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.63 2000-01-17 06:24:27 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -205,7 +205,7 @@ tok2str(register const struct tok *lp, register const char *fmt,
        }
        if (fmt == NULL)
                fmt = "#%d";
-       (void)sprintf(buf, fmt, v);
+       (void)snprintf(buf, sizeof(buf), fmt, v);
        return (buf);
 }