-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pflua does not allow negative numbers; tcpdump does #82
Comments
Horrifyingly enough, for full compatibility we need to support an arbitrary number of '-'s. % tcpdump -d "len < 1 ----1" |
It gets sillier: |
For now, only test positive numbers, and math within the range where doubles can exactly represent all integers. This avoids triggering the following known issues: "Pflua does not allow negative numbers; tcpdump does" Igalia/pflua#82 and "Pflua: large multiplication uses floats, leading to different results" Igalia/pflua#83
It seems that tcpdump does not allow negative number literals (e.g. tcpdump -d 'port -1' gives syntax error), but it has unary minus operator (e.g. tcpdump -d '1 = -(-(1))' is valid). |
Yep, you're entirely right. The relevant bits of libpcap source define gen_neg and UMINUS, and it's a unary operator. |
Expected behavior: the behavior of tcpdump and pflua should match.
The fix: change the pflua parser.
Details:
% tcpdump -d "len < 2 * -5"
(000) ld #pktlen
(001) jge #0xfffffff6 jt 2 jf 3
(002) ret #0
(003) ret #65535
luajit: deps/pflua/src/pf/parse.lua:283:
Error: In expression "len < 2 * -5"
^
bad token while parsing arithmetic expression -
stack traceback:
[C]: in function 'primitive_error'
deps/pflua/src/pf/parse.lua:283: in function 'error'
deps/pflua/src/pf/parse.lua:660: in function 'parse_primary_arithmetic'
deps/pflua/src/pf/parse.lua:674: in function 'parse_arithmetic'
deps/pflua/src/pf/parse.lua:681: in function 'parse_arithmetic'
deps/pflua/src/pf/parse.lua:822: in function 'parse_logical_or_arithmetic'
deps/pflua/src/pf/parse.lua:846: in function 'parse_logical'
deps/pflua/src/pf/parse.lua:854: in function 'parse'
deps/pflua/src/pf.lua:30: in function 'compile_filter'
./pflangmatheval.lua:25: in function 'pflang_eval'
./pflua-quickcheck:148: in function 'property_pflua_and_tcpdump_arithmetic_match'
./pflua-quickcheck:191: in function 'main'
./pflua-quickcheck:196: in main chunk
[C]: at 0x00404bc0
The text was updated successfully, but these errors were encountered: