]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap.c
Do the check for a valid direction value in pcap_setdirection().
[libpcap] / pcap.c
diff --git a/pcap.c b/pcap.c
index e4c0a1f3909790e2c9e57652c2e2442d69146ee5..363deb56ee44f794aacabfa71f1bbe290a378e81 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -3533,8 +3533,26 @@ pcap_setdirection(pcap_t *p, pcap_direction_t d)
                snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
                    "Setting direction is not supported on this device");
                return (-1);
-       } else
-               return (p->setdirection_op(p, d));
+       } else {
+               switch (d) {
+
+               case PCAP_D_IN:
+               case PCAP_D_OUT:
+               case PCAP_D_INOUT:
+                       /*
+                        * Valid direction.
+                        */
+                       return (p->setdirection_op(p, d));
+
+               default:
+                       /*
+                        * Invalid direction.
+                        */
+                       snprintf(p->errbuf, sizeof(p->errbuf),
+                           "Invalid direction");
+                       return (-1);
+               }
+       }       
 }
 
 int