Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix pcap_[gs]etnonblock() to fill in the supplied errbuf.

In some cases, it was setting the pcap_t's errbuf instead.  In the
wrapper, make sure *both* of them get the error message, just in case
somebody assumed (contrary to the documentation) that p->errbuf was set
(which it was, in most cases).
  • Loading branch information...
commit 10c8ce6ba0ecb1e492025ecce7e0d5f18308b764 1 parent c267205
@guyharris guyharris authored
Showing with 28 additions and 6 deletions.
  1. +1 −1  pcap-win32.c
  2. +27 −5 pcap.c
View
2  pcap-win32.c
@@ -836,7 +836,7 @@ pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
newtimeout = p->md.timeout;
}
if (!PacketSetReadTimeout(p->adapter, newtimeout)) {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
"PacketSetReadTimeout: %s", pcap_win32strerror());
return (-1);
}
View
32 pcap.c
@@ -1218,7 +1218,18 @@ pcap_geterr(pcap_t *p)
int
pcap_getnonblock(pcap_t *p, char *errbuf)
{
- return (p->getnonblock_op(p, errbuf));
+ int ret;
+
+ ret = p->getnonblock_op(p, errbuf);
+ if (ret == -1) {
+ /*
+ * In case somebody depended on the bug wherein
+ * the error message was put into p->errbuf
+ * by pcap_getnonblock_fd().
+ */
+ strlcpy(p->errbuf, errbuf, PCAP_ERRBUF_SIZE);
+ }
+ return (ret);
}
/*
@@ -1236,7 +1247,7 @@ pcap_getnonblock_fd(pcap_t *p, char *errbuf)
fdflags = fcntl(p->fd, F_GETFL, 0);
if (fdflags == -1) {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
pcap_strerror(errno));
return (-1);
}
@@ -1250,7 +1261,18 @@ pcap_getnonblock_fd(pcap_t *p, char *errbuf)
int
pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
{
- return (p->setnonblock_op(p, nonblock, errbuf));
+ int ret;
+
+ ret = p->setnonblock_op(p, nonblock, errbuf);
+ if (ret == -1) {
+ /*
+ * In case somebody depended on the bug wherein
+ * the error message was put into p->errbuf
+ * by pcap_setnonblock_fd().
+ */
+ strlcpy(p->errbuf, errbuf, PCAP_ERRBUF_SIZE);
+ }
+ return (ret);
}
#if !defined(WIN32) && !defined(MSDOS)
@@ -1267,7 +1289,7 @@ pcap_setnonblock_fd(pcap_t *p, int nonblock, char *errbuf)
fdflags = fcntl(p->fd, F_GETFL, 0);
if (fdflags == -1) {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "F_GETFL: %s",
pcap_strerror(errno));
return (-1);
}
@@ -1276,7 +1298,7 @@ pcap_setnonblock_fd(pcap_t *p, int nonblock, char *errbuf)
else
fdflags &= ~O_NONBLOCK;
if (fcntl(p->fd, F_SETFL, fdflags) == -1) {
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "F_SETFL: %s",
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "F_SETFL: %s",
pcap_strerror(errno));
return (-1);
}
Please sign in to comment.
Something went wrong with that request. Please try again.