summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libpcap/bpf_image.c4
-rw-r--r--lib/libpcap/gencode.c5
-rw-r--r--lib/libpcap/inet.c20
-rw-r--r--lib/libpcap/pcap-bpf.c43
-rw-r--r--lib/libpcap/pcap.c4
-rw-r--r--lib/libpcap/savefile.c24
6 files changed, 60 insertions, 40 deletions
diff --git a/lib/libpcap/bpf_image.c b/lib/libpcap/bpf_image.c
index 272859a57a4..d46a77da092 100644
--- a/lib/libpcap/bpf_image.c
+++ b/lib/libpcap/bpf_image.c
@@ -281,8 +281,8 @@ bpf_image(p, n)
fmt = "";
break;
}
- (void)sprintf(operand, fmt, v);
- (void)sprintf(image,
+ (void)snprintf(operand, sizeof operand, fmt, v);
+ (void)snprintf(image, sizeof image,
(BPF_CLASS(p->code) == BPF_JMP &&
BPF_OP(p->code) != BPF_JA) ?
"(%03d) %-8s %-16s jt %d\tjf %d"
diff --git a/lib/libpcap/gencode.c b/lib/libpcap/gencode.c
index 91cce624b12..16d9c3edcc1 100644
--- a/lib/libpcap/gencode.c
+++ b/lib/libpcap/gencode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gencode.c,v 1.8 1998/06/11 00:01:18 provos Exp $ */
+/* $OpenBSD: gencode.c,v 1.9 1998/07/14 00:14:00 deraadt Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@@ -106,7 +106,8 @@ bpf_error(fmt, va_alist)
va_start(ap);
#endif
if (bpf_pcap != NULL)
- (void)vsprintf(pcap_geterr(bpf_pcap), fmt, ap);
+ (void)vsnprintf(pcap_geterr(bpf_pcap), PCAP_ERRBUF_SIZE,
+ fmt, ap);
va_end(ap);
longjmp(top_ctx, 1);
/* NOTREACHED */
diff --git a/lib/libpcap/inet.c b/lib/libpcap/inet.c
index 6ba34ea73e4..6f55b9d4a7b 100644
--- a/lib/libpcap/inet.c
+++ b/lib/libpcap/inet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inet.c,v 1.7 1997/07/25 20:30:19 mickey Exp $ */
+/* $OpenBSD: inet.c,v 1.8 1998/07/14 00:14:01 deraadt Exp $ */
/*
* Copyright (c) 1994, 1995, 1996
@@ -95,7 +95,8 @@ pcap_lookupdev(errbuf)
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
- (void)sprintf(errbuf, "socket: %s", pcap_strerror(errno));
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
+ pcap_strerror(errno));
return (NULL);
}
while (1) {
@@ -140,8 +141,8 @@ pcap_lookupdev(errbuf)
*/
strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) {
- (void)sprintf(errbuf, "SIOCGIFFLAGS: %s",
- pcap_strerror(errno));
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "SIOCGIFFLAGS: %s", pcap_strerror(errno));
(void)close(fd);
free(ibuf);
return (NULL);
@@ -183,7 +184,8 @@ pcap_lookupnet(device, netp, maskp, errbuf)
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
- (void)sprintf(errbuf, "socket: %s", pcap_strerror(errno));
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
+ pcap_strerror(errno));
return (-1);
}
memset(&ifr, 0, sizeof(ifr));
@@ -193,7 +195,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
#endif
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
- (void)sprintf(errbuf, "SIOCGIFADDR: %s: %s",
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE, "SIOCGIFADDR: %s: %s",
device, pcap_strerror(errno));
(void)close(fd);
return (-1);
@@ -201,7 +203,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
sin = (struct sockaddr_in *)&ifr.ifr_addr;
*netp = sin->sin_addr.s_addr;
if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
- (void)sprintf(errbuf, "SIOCGIFNETMASK: %s: %s",
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE, "SIOCGIFNETMASK: %s: %s",
device, pcap_strerror(errno));
(void)close(fd);
return (-1);
@@ -216,8 +218,8 @@ pcap_lookupnet(device, netp, maskp, errbuf)
else if (IN_CLASSC(*netp))
*maskp = IN_CLASSC_NET;
else {
- (void)sprintf(errbuf, "inet class for 0x%x unknown",
- *netp);
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "inet class for 0x%x unknown", *netp);
return (-1);
}
}
diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c
index d656a50e94f..b0499163992 100644
--- a/lib/libpcap/pcap-bpf.c
+++ b/lib/libpcap/pcap-bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcap-bpf.c,v 1.8 1997/08/13 20:29:41 dm Exp $ */
+/* $OpenBSD: pcap-bpf.c,v 1.9 1998/07/14 00:14:03 deraadt Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996
@@ -55,7 +55,8 @@ pcap_stats(pcap_t *p, struct pcap_stat *ps)
struct bpf_stat s;
if (ioctl(p->fd, BIOCGSTATS, (caddr_t)&s) < 0) {
- sprintf(p->errbuf, "BIOCGSTATS: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCGSTATS: %s",
+ pcap_strerror(errno));
return (-1);
}
@@ -99,7 +100,8 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/* fall through */
#endif
}
- sprintf(p->errbuf, "read: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read: %s",
+ pcap_strerror(errno));
return (-1);
}
bp = p->buffer;
@@ -142,13 +144,13 @@ bpf_open(pcap_t *p, char *errbuf)
{
int fd;
int n = 0;
- char device[sizeof "/dev/bpf000"];
+ char device[sizeof "/dev/bpf0000000000"];
/*
* 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, O_RDWR);
if (fd < 0 && errno == EACCES)
fd = open(device, O_RDONLY);
@@ -158,7 +160,8 @@ bpf_open(pcap_t *p, char *errbuf)
* XXX better message for all minors used
*/
if (fd < 0)
- sprintf(errbuf, "%s: %s", device, pcap_strerror(errno));
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
+ device, pcap_strerror(errno));
return (fd);
}
@@ -174,7 +177,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p = (pcap_t *)malloc(sizeof(*p));
if (p == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
+ pcap_strerror(errno));
return (NULL);
}
bzero(p, sizeof(*p));
@@ -186,22 +190,26 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p->snapshot = snaplen;
if (ioctl(fd, BIOCVERSION, (caddr_t)&bv) < 0) {
- sprintf(ebuf, "BIOCVERSION: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCVERSION: %s",
+ pcap_strerror(errno));
goto bad;
}
if (bv.bv_major != BPF_MAJOR_VERSION ||
bv.bv_minor < BPF_MINOR_VERSION) {
- sprintf(ebuf, "kernel bpf filter out of date");
+ snprintf(ebuf, PCAP_ERRBUF_SIZE,
+ "kernel bpf filter out of date");
goto bad;
}
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
- sprintf(ebuf, "%s: %s", device, pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s: %s",
+ device, pcap_strerror(errno));
goto bad;
}
/* Get the data link layer type. */
if (ioctl(fd, BIOCGDLT, (caddr_t)&v) < 0) {
- sprintf(ebuf, "BIOCGDLT: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGDLT: %s",
+ pcap_strerror(errno));
goto bad;
}
p->linktype = v;
@@ -212,8 +220,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
to.tv_sec = to_ms / 1000;
to.tv_usec = (to_ms * 1000) % 1000000;
if (ioctl(p->fd, BIOCSRTIMEOUT, (caddr_t)&to) < 0) {
- sprintf(ebuf, "BIOCSRTIMEOUT: %s",
- pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCSRTIMEOUT: %s",
+ pcap_strerror(errno));
goto bad;
}
}
@@ -222,13 +230,15 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
(void)ioctl(p->fd, BIOCPROMISC, NULL);
if (ioctl(fd, BIOCGBLEN, (caddr_t)&v) < 0) {
- sprintf(ebuf, "BIOCGBLEN: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGBLEN: %s",
+ pcap_strerror(errno));
goto bad;
}
p->bufsize = v;
p->buffer = (u_char *)malloc(p->bufsize);
if (p->buffer == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
+ pcap_strerror(errno));
goto bad;
}
@@ -245,7 +255,8 @@ pcap_setfilter(pcap_t *p, struct bpf_program *fp)
if (p->sf.rfile != NULL)
p->fcode = *fp;
else if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
- sprintf(p->errbuf, "BIOCSETF: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETF: %s",
+ pcap_strerror(errno));
return (-1);
}
return (0);
diff --git a/lib/libpcap/pcap.c b/lib/libpcap/pcap.c
index ee14262af6d..05eb2ee4861 100644
--- a/lib/libpcap/pcap.c
+++ b/lib/libpcap/pcap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcap.c,v 1.4 1996/07/12 13:19:12 mickey Exp $ */
+/* $OpenBSD: pcap.c,v 1.5 1998/07/14 00:14:04 deraadt Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996
@@ -174,7 +174,7 @@ pcap_strerror(int errnum)
if ((unsigned int)errnum < sys_nerr)
return ((char *)sys_errlist[errnum]);
- (void)sprintf(ebuf, "Unknown error: %d", errnum);
+ (void)snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum);
return(ebuf);
#endif
}
diff --git a/lib/libpcap/savefile.c b/lib/libpcap/savefile.c
index 7713291e0d1..2e70b05a577 100644
--- a/lib/libpcap/savefile.c
+++ b/lib/libpcap/savefile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: savefile.c,v 1.4 1996/07/12 13:19:13 mickey Exp $ */
+/* $OpenBSD: savefile.c,v 1.5 1998/07/14 00:14:05 deraadt Exp $ */
/*
* Copyright (c) 1993, 1994, 1995
@@ -131,24 +131,27 @@ pcap_open_offline(char *fname, char *errbuf)
else {
fp = fopen(fname, "r");
if (fp == NULL) {
- sprintf(errbuf, "%s: %s", fname, pcap_strerror(errno));
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", fname,
+ pcap_strerror(errno));
goto bad;
}
}
if (fread((char *)&hdr, sizeof(hdr), 1, fp) != 1) {
- sprintf(errbuf, "fread: %s", pcap_strerror(errno));
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "fread: %s",
+ pcap_strerror(errno));
goto bad;
}
if (hdr.magic != TCPDUMP_MAGIC) {
if (SWAPLONG(hdr.magic) != TCPDUMP_MAGIC) {
- sprintf(errbuf, "bad dump file format");
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bad dump file format");
goto bad;
}
p->sf.swapped = 1;
swap_hdr(&hdr);
}
if (hdr.version_major < PCAP_VERSION_MAJOR) {
- sprintf(errbuf, "archaic file format");
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "archaic file format");
goto bad;
}
p->tzoff = hdr.thiszone;
@@ -238,12 +241,14 @@ sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
free((u_char *)tp);
tp = (u_char *)malloc(tsize);
if (tp == NULL) {
- sprintf(p->errbuf, "BUFMOD hack malloc");
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "BUFMOD hack malloc");
return (-1);
}
}
if (fread((char *)tp, hdr->caplen, 1, fp) != 1) {
- sprintf(p->errbuf, "truncated dump file");
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "truncated dump file");
return (-1);
}
memcpy((char *)buf, (char *)tp, buflen);
@@ -252,7 +257,8 @@ sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
/* read the packet itself */
if (fread((char *)buf, hdr->caplen, 1, fp) != 1) {
- sprintf(p->errbuf, "truncated dump file");
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "truncated dump file");
return (-1);
}
}
@@ -317,7 +323,7 @@ pcap_dump_open(pcap_t *p, char *fname)
else {
f = fopen(fname, "w");
if (f == NULL) {
- sprintf(p->errbuf, "%s: %s",
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
fname, pcap_strerror(errno));
return (NULL);
}