diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/tcpdump/print-dhcp6.c | 6 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-icmp.c | 36 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-nfs.c | 4 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-ntp.c | 7 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-sunrpc.c | 12 | ||||
-rw-r--r-- | usr.sbin/tcpdump/smbutil.c | 14 |
6 files changed, 36 insertions, 43 deletions
diff --git a/usr.sbin/tcpdump/print-dhcp6.c b/usr.sbin/tcpdump/print-dhcp6.c index 7ee68eca948..aae8aac8fd7 100644 --- a/usr.sbin/tcpdump/print-dhcp6.c +++ b/usr.sbin/tcpdump/print-dhcp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-dhcp6.c,v 1.2 2000/05/05 12:32:09 jakob Exp $ */ +/* $OpenBSD: print-dhcp6.c,v 1.3 2001/11/07 18:48:16 deraadt Exp $ */ /* * Copyright (C) 1998 and 1999 WIDE Project. @@ -31,7 +31,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-dhcp6.c,v 1.2 2000/05/05 12:32:09 jakob Exp $"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-dhcp6.c,v 1.3 2001/11/07 18:48:16 deraadt Exp $"; #endif #ifdef INET6 @@ -208,7 +208,7 @@ dhcp6ext_print(u_char *cp, u_char *ep) break; case OT6_STR: memset(&buf, 0, sizeof(buf)); - strncpy(buf, &cp[4], len); + strlcpy(buf, &cp[4], len); printf("%s", buf); break; case OT6_NUM: diff --git a/usr.sbin/tcpdump/print-icmp.c b/usr.sbin/tcpdump/print-icmp.c index 13f4bfdf9bb..dbc1e32fc2e 100644 --- a/usr.sbin/tcpdump/print-icmp.c +++ b/usr.sbin/tcpdump/print-icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-icmp.c,v 1.12 2001/09/02 12:06:57 jakob Exp $ */ +/* $OpenBSD: print-icmp.c,v 1.13 2001/11/07 18:48:16 deraadt Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996 @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-icmp.c,v 1.12 2001/09/02 12:06:57 jakob Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-icmp.c,v 1.13 2001/11/07 18:48:16 deraadt Exp $ (LBL)"; #endif #include <sys/param.h> @@ -167,7 +167,6 @@ struct id_rdiscovery { void icmp_print(register const u_char *bp, register const u_char *bp2) { - register char *cp; register const struct icmp *dp; register const struct ip *ip; register const char *str, *fmt; @@ -175,6 +174,7 @@ icmp_print(register const u_char *bp, register const u_char *bp2) register const struct udphdr *ouh; register u_int hlen, dport, mtu; char buf[MAXHOSTNAMELEN+256]; + char buf2[MAXHOSTNAMELEN+256]; dp = (struct icmp *)bp; ip = (struct ip *)bp2; @@ -284,44 +284,40 @@ icmp_print(register const u_char *bp, register const u_char *bp2) register const struct id_rdiscovery *idp; u_int lifetime, num, size; - (void)strncpy(buf, "router advertisement", sizeof buf-1); - buf[sizeof buf-1] = '\0'; - cp = buf + strlen(buf); + (void)strlcpy(buf, "router advertisement", sizeof(buf)); ihp = (struct ih_rdiscovery *)&dp->icmp_void; TCHECK(*ihp); - (void)strcpy(cp, " lifetime "); - cp = buf + strlen(buf); + (void)strlcat(buf, " lifetime ", sizeof(buf)); lifetime = EXTRACT_16BITS(&ihp->ird_lifetime); if (lifetime < 60) - (void)snprintf(cp, buf + sizeof buf - cp, "%u", lifetime); + (void)snprintf(buf2, sizeof(buf2), "%u", lifetime); else if (lifetime < 60 * 60) - (void)snprintf(cp, buf + sizeof buf - cp, "%u:%02u", + (void)snprintf(buf2, sizeof(buf2), "%u:%02u", lifetime / 60, lifetime % 60); else - (void)snprintf(cp, buf + sizeof buf - cp, "%u:%02u:%02u", - lifetime / 3600, - (lifetime % 3600) / 60, + (void)snprintf(buf2, sizeof(buf2), "%u:%02u:%02u", + lifetime / 3600, (lifetime % 3600) / 60, lifetime % 60); - cp = buf + strlen(buf); + strlcat(buf, buf2, sizeof(buf)); num = ihp->ird_addrnum; - (void)snprintf(cp, buf + sizeof buf - cp, " %d:", num); - cp = buf + strlen(buf); + (void)snprintf(buf2, sizeof(buf2), " %d:", num); + strlcat(buf, buf2, sizeof(buf)); size = ihp->ird_addrsiz; if (size != 2) { - (void)snprintf(cp, buf - sizeof buf - cp, - " [size %d]", size); + (void)snprintf(buf2, sizeof(buf2), " [size %d]", size); + strlcat(buf, buf2, sizeof(buf)); break; } idp = (struct id_rdiscovery *)&dp->icmp_data; while (num-- > 0) { TCHECK(*idp); - (void)snprintf(cp, buf + sizeof buf - cp, " {%s %u}", + (void)snprintf(buf2, sizeof(buf2), " {%s %u}", ipaddr_string(&idp->ird_addr), EXTRACT_32BITS(&idp->ird_pref)); - cp = buf + strlen(buf); + strlcat(buf, buf2, sizeof(buf)); } } break; diff --git a/usr.sbin/tcpdump/print-nfs.c b/usr.sbin/tcpdump/print-nfs.c index 10eef79258d..d5632ae37e8 100644 --- a/usr.sbin/tcpdump/print-nfs.c +++ b/usr.sbin/tcpdump/print-nfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-nfs.c,v 1.9 2000/12/05 08:17:45 jakob Exp $ */ +/* $OpenBSD: print-nfs.c,v 1.10 2001/11/07 18:48:16 deraadt Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -377,7 +377,7 @@ nfs_printfh(register const u_int32_t *dp) static char temp[NFS_FHSIZE+1]; /* Make sure string is null-terminated */ - strncpy(temp, sfsname, NFS_FHSIZE); + strlcpy(temp, sfsname, sizeof(temp)); /* Remove trailing spaces */ sfsname = strchr(temp, ' '); if (sfsname) diff --git a/usr.sbin/tcpdump/print-ntp.c b/usr.sbin/tcpdump/print-ntp.c index 4949ea1b6ca..51a56c9fda6 100644 --- a/usr.sbin/tcpdump/print-ntp.c +++ b/usr.sbin/tcpdump/print-ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-ntp.c,v 1.9 2000/10/03 14:31:58 ho Exp $ */ +/* $OpenBSD: print-ntp.c,v 1.10 2001/11/07 18:48:16 deraadt Exp $ */ /* * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -27,7 +27,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ntp.c,v 1.9 2000/10/03 14:31:58 ho Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ntp.c,v 1.10 2001/11/07 18:48:16 deraadt Exp $ (LBL)"; #endif #include <sys/param.h> @@ -161,8 +161,7 @@ ntp_print(register const u_char *cp, u_int length) break; case PRIM_REF: - strncpy(rclock, (char *)&(bp->refid), 4); - rclock[4] = '\0'; + strlcpy(rclock, (char *)&(bp->refid), sizeof(rclock)); fputs(rclock, stdout); break; diff --git a/usr.sbin/tcpdump/print-sunrpc.c b/usr.sbin/tcpdump/print-sunrpc.c index 859f72c3eeb..51a539ad401 100644 --- a/usr.sbin/tcpdump/print-sunrpc.c +++ b/usr.sbin/tcpdump/print-sunrpc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-sunrpc.c,v 1.11 2001/11/06 03:11:40 deraadt Exp $ */ +/* $OpenBSD: print-sunrpc.c,v 1.12 2001/11/07 18:48:16 deraadt Exp $ */ /* * Copyright (c) 1992, 1993, 1994, 1995, 1996 @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-sunrpc.c,v 1.11 2001/11/06 03:11:40 deraadt Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-sunrpc.c,v 1.12 2001/11/07 18:48:16 deraadt Exp $ (LBL)"; #endif #include <sys/param.h> @@ -115,10 +115,8 @@ progstr(prog) return (buf); rp = getrpcbynumber(prog); if (rp == NULL) - (void) snprintf(buf, sizeof(buf), "#%u", prog); - else { - strncpy(buf, rp->r_name, sizeof buf-1); - buf[sizeof buf-1] = '\0'; - } + snprintf(buf, sizeof(buf), "#%u", prog); + else + strlcpy(buf, rp->r_name, sizeof(buf)); return (buf); } diff --git a/usr.sbin/tcpdump/smbutil.c b/usr.sbin/tcpdump/smbutil.c index 613bf1fbe21..fe2637cd9c1 100644 --- a/usr.sbin/tcpdump/smbutil.c +++ b/usr.sbin/tcpdump/smbutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smbutil.c,v 1.2 2001/01/03 18:41:00 mickey Exp $ */ +/* $OpenBSD: smbutil.c,v 1.3 2001/11/07 18:48:16 deraadt Exp $ */ /* Copyright (C) Andrew Tridgell 1995-1999 @@ -13,7 +13,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/smbutil.c,v 1.2 2001/01/03 18:41:00 mickey Exp $"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/smbutil.c,v 1.3 2001/11/07 18:48:16 deraadt Exp $"; #endif #include <sys/param.h> @@ -329,8 +329,7 @@ static const uchar *fdata1(const uchar *buf, const char *fmt, const uchar *maxbu char bitfmt[128]; char *p = strchr(++fmt,'}'); int l = PTR_DIFF(p,fmt); - strncpy(bitfmt,fmt,l); - bitfmt[l]=0; + strlcpy(bitfmt,fmt,sizeof(bitfmt)); fmt = p+1; write_bits(CVAL(buf,0),bitfmt); buf++; @@ -556,7 +555,7 @@ const uchar *fdata(const uchar *buf, const char *fmt, const uchar *maxbuf) if (buf>=maxbuf) return(buf); memset(s, 0, sizeof(s)); p = strchr(fmt,']'); - strncpy(s,fmt,p-fmt); + strncpy(s,fmt,p-fmt); /* XXX? */ fmt = p+1; buf = fdata1(buf,s,maxbuf); if (buf == NULL) @@ -713,8 +712,9 @@ char *smb_errstr(int class,int num) for (j=0;err[j].name;j++) if (num == err[j].code) { - snprintf(ret,sizeof(ret),"%s - %s (%s)",err_classes[i].class, - err[j].name,err[j].message); + snprintf(ret, sizeof(ret), "%s - %s (%s)", + err_classes[i].class, + err[j].name,err[j].message); return ret; } } |