Show the libpcap error when a BPF filter fails to compile#5022
Merged
gpotter2 merged 1 commit intoJun 22, 2026
Conversation
Closes secdev#4587. compile_filter() reported "Failed to compile filter expression X (-1)", giving no hint why the filter was rejected: a syntax error, or a filter incompatible with the link-layer type (for example a wlan filter on an Ethernet interface). Compile through a pcap handle in both the linktype and interface paths (pcap_open_dead needs neither an interface nor root) and, on failure, retrieve the message from pcap_geterr(). The exception now reads e.g. "... (802.11 link-layer types supported only on 802.11)" or "... (can't parse filter expression: syntax error)". Adds a regression test in test/regression.uts. AI-Assisted: yes (Claude Opus 4.8)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5022 +/- ##
=======================================
Coverage 80.34% 80.34%
=======================================
Files 386 386
Lines 96012 96015 +3
=======================================
+ Hits 77137 77140 +3
Misses 18875 18875
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
compile_filter()reportedFailed to compile filter expression <filter> (-1), which gave no indication of why the filter was rejected: a syntax error (such as thenot arpand not port 22typo from the issue), or a filter incompatible with the interface link-layer type (such as awlanfilter on an Ethernet link).Both compilation paths now go through a pcap handle and, on failure, retrieve the underlying libpcap message via
pcap_geterr(). The linktype path usespcap_open_dead(), so it still needs neither an interface nor root privileges. The exception now reads, for example:Failed to compile filter expression 'wlan type mgt subtype deauth' (802.11 link-layer types supported only on 802.11)Failed to compile filter expression 'not arpand not port 22' (can't parse filter expression: syntax error)A regression test is added in
test/regression.uts.fixes #4587