aboutsummaryrefslogtreecommitdiff
path: root/pcap-linux.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-04-04 12:43:48 -0700
committerGuy Harris <guy@alum.mit.edu>2014-04-04 12:43:48 -0700
commit10990507adc0c8e29de41f110d1263c4c2667c87 (patch)
tree17b9eb0c978f4e4fb49a32187fd1cae7acf38f5b /pcap-linux.c
parent39ec2e4012ae5f585ac231dc1db47361df200670 (diff)
Make sure the device name we're handed will fit into an ioctl.
If not, the device presumably doesn't exist, as the Linux kernel shouldn't support creating such a device; make sure we don't just use a truncated version of the name in ioctls.
Diffstat (limited to 'pcap-linux.c')
-rw-r--r--pcap-linux.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/pcap-linux.c b/pcap-linux.c
index 8ab8d5ab..21943453 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -1229,10 +1229,27 @@ pcap_activate_linux(pcap_t *handle)
{
struct pcap_linux *handlep = handle->priv;
const char *device;
+ struct ifreq ifr;
int status = 0;
device = handle->opt.source;
+ /*
+ * Make sure the name we were handed will fit into the ioctls we
+ * might perform on the device; if not, return a "No such device"
+ * indication, as the Linux kernel shouldn't support creating
+ * a device whose name won't fit into those ioctls.
+ *
+ * "Will fit" means "will fit, complete with a null terminator",
+ * so if the length, which does *not* include the null terminator,
+ * is greater than *or equal to* the size of the field into which
+ * we'll be copying it, that won't fit.
+ */
+ if (strlen(device) >= sizeof(ifr.ifr_name)) {
+ status = PCAP_ERROR_NO_SUCH_DEVICE;
+ goto fail;
+ }
+
handle->inject_op = pcap_inject_linux;
handle->setfilter_op = pcap_setfilter_linux;
handle->setdirection_op = pcap_setdirection_linux;