fix/net-traffic-validate-remote-ip - #153
Merged
xu-lang merged 1 commit intoSep 17, 2026
Merged
Conversation
PR Reviewer Guide 🔍(Review updated until commit b091fe0)Here are some key observations to aid the review process:
|
Signed-off-by: Wang Yu <wangyu6@uniontech.com>
yuKing123-king
force-pushed
the
fix/net-traffic-validate-remote-ip
branch
from
September 17, 2026 11:41
3558129 to
b091fe0
Compare
|
Persistent review updated to latest commit b091fe0 |
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.
修复的 Bug
net-traffic的-r/--remote参数未校验inet_addr()返回值。当传入非法 IP(如1.2.3.999、空串、拼写错误)时,inet_addr返回INADDR_NONE = 0xFFFFFFFF,经ntohl后仍为0xFFFFFFFF,被原样写入 filter map。随后在 BPF 侧过滤逻辑(
bpf/observe/net-traffic.bpf.c:96):0xFFFFFFFF非零为真,且不等于任何真实流量 IP,导致该判断恒成立,屏蔽全部可观测流量。工具表面正常运行实际无任何输出,形成监控盲区——对常驻观测工具而言,这种静默失效比报错退出更危险。-r一旦写错,工具完全失明且无任何错误提示改了哪些地方
仅修改
observe/net-traffic.cpp中parse_args()的case 'r'分支(3 行 → 9 行),不涉及 BPF 侧、Rule结构、其他参数分支。为什么这样修复
parse_args校验是职责最清晰的拦截点,避免无效规则污染内核态过滤逻辑。default分支(Usage + exit(-1))的错误处理风格保持一致,让用户立即看到原因并纠正,而不是静默运行却无输出。inet_addrAPI(本文件已使用,无需新增 include),仅在写入rule.remote_ip前加一层INADDR_NONE校验,不改动 BPF 侧、Rule结构或其它参数分支,回归风险最低。fprintf(stderr, "Invalid remote ip: %s\n", optarg)比单纯Usage更便于定位用户输入错误。验证方式