-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Ensure that packet is set to p param to type of bytes. In certain sit… #3909
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
base: master
Are you sure you want to change the base?
Conversation
…uations where bgp fields for open messages where being set, this function was initializing packet variable to a str and returning. Fix bgp path_attrib length field. Should be type byte, not int. Adding fuzz() support to bgp open and update. Allow for BGPFieldLenField len to be fuzzed, but fixed when recalled.
@@ -633,7 +660,7 @@ class _BGPCapability_metaclass(_BGPCap_metaclass, Packet_metaclass): | |||
pass | |||
|
|||
|
|||
class BGPCapability(Packet, metaclass=_BGPCapability_metaclass): | |||
class BGPCapability(six.with_metaclass(_BGPCapability_metaclass, Packet)): # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just dropped Python 2 support so you shouldn't need to use six
return enum.get(i, i) | ||
if self.enum_from: | ||
enum = self.enum_from(pkt) | ||
return enum.get(i, i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else?
subpacklen = lambda p: len(p) | ||
packet = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. Could you add a unit test?
https://github.com/secdev/scapy/tree/master/test/contrib/bgp.uts
@@ -449,7 +476,7 @@ class BGPHeader(Packet): | |||
0xffffffffffffffffffffffffffffffff, | |||
0x80 | |||
), | |||
ShortField("len", None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very not scapy-like. Don't do that. It is commonly understood that len=None
-> auto-computed.
You can always set this to 0 before calling fuzz
:param int min: Minimum range for random value. | ||
:param int max: Maximum range for random value. | ||
""" | ||
RandNum.__init__(self, min, max) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use super
@@ -117,25 +119,50 @@ def i2m(self, pkt, i): | |||
""""Internal" (IP as bytes, mask as int) to "machine" | |||
representation.""" | |||
mask, ip = i | |||
ip = socket.inet_aton(ip) | |||
ip = socket.inet_aton(str(ip)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? (add a comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inet_aton expects a string representation of an ip address.
I'm ensuring that is the case, and any errors will make this obvious.
"withdrawn_routes_len", | ||
None, | ||
0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. Leave None
here
"path_attr_len", | ||
None, | ||
0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
subpacklen = lambda p: len(p) | ||
packet = "" | ||
packet = p | ||
|
||
if self.withdrawn_routes_len is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave None here...
...otherwise this won't work
Co-authored-by: gpotter2 <[email protected]>
Removed extra double quote comments
Checklist:
cd test && ./run_tests
ortox
)Ensure that params that representing packets are set to type bytes. In certain situations where bgp fields for open messages were being set, this function was initializing packet variable to a str and returning.
Fix bgp path_attrib length field. Should be type byte, not int.
Adding fuzz() support to bgp open and update.
Allow for BGPFieldLenField len to be fuzzed, but fixed when recalled.