Skip to content
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

Open
kbara opened this issue Nov 12, 2014 · 4 comments
Open

Pflua does not allow negative numbers; tcpdump does #82

kbara opened this issue Nov 12, 2014 · 4 comments

Comments

@kbara
Copy link
Contributor

kbara commented Nov 12, 2014

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

@kbara
Copy link
Contributor Author

kbara commented Nov 12, 2014

Horrifyingly enough, for full compatibility we need to support an arbitrary number of '-'s.
% tcpdump -d "len < 1 ---1"
(000) ld #pktlen
(001) jge #0x0 jt 2 jf 3

% tcpdump -d "len < 1 ----1"
(000) ld #pktlen
(001) jge #0x2 jt 2 jf 3

@kbara
Copy link
Contributor Author

kbara commented Nov 12, 2014

It gets sillier:
% tcpdump -d "len < 1 - - -- 1"
(000) ld #pktlen
(001) jge #0x2 jt 2 jf 3
Arbitrary spaces seem to be allowed.

kbara pushed a commit to Igalia/pflua-test that referenced this issue Nov 25, 2014
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
@mpeterv
Copy link
Contributor

mpeterv commented May 14, 2015

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).

@kbara kbara added enhancement and removed bug labels May 19, 2015
@kbara
Copy link
Contributor Author

kbara commented May 19, 2015

Yep, you're entirely right. The relevant bits of libpcap source define gen_neg and UMINUS, and it's a unary operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants