Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
dc9041b5
Commit
dc9041b5
authored
8 years ago
by
Aravindhan Dhanasekaran
Browse files
Options
Downloads
Patches
Plain Diff
Error out incorrect IPv4 format in IPv6 addresses in inet_pton
parent
fd150e77
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scapy/pton_ntop.py
+10
-3
10 additions, 3 deletions
scapy/pton_ntop.py
with
10 additions
and
3 deletions
scapy/pton_ntop.py
+
10
−
3
View file @
dc9041b5
...
...
@@ -13,6 +13,7 @@ without IPv6 support, on Windows for instance.
import
socket
import
re
_IP4_FORMAT
=
re
.
compile
(
"
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
"
)
_IP6_ZEROS
=
re
.
compile
(
'
(?::|^)(0(?::0)+)(?::|$)
'
)
def
inet_pton
(
af
,
addr
):
...
...
@@ -34,9 +35,16 @@ def inet_pton(af, addr):
joker_pos
=
None
# The last part of an IPv6 address can be an IPv4 address
ipv4_bin
=
None
ipv4_addr
=
None
if
"
.
"
in
addr
:
ipv4_addr
=
addr
.
split
(
"
:
"
)[
-
1
]
if
_IP4_FORMAT
.
match
(
ipv4_addr
)
is
None
:
raise
Exception
(
"
Illegal syntax for IP address
"
)
try
:
ipv4_bin
=
socket
.
inet_aton
(
ipv4_addr
)
except
socket
.
error
:
raise
Exception
(
"
Illegal syntax for IP address
"
)
result
=
""
parts
=
addr
.
split
(
"
:
"
)
...
...
@@ -47,9 +55,8 @@ def inet_pton(af, addr):
joker_pos
=
len
(
result
)
else
:
raise
Exception
(
"
Illegal syntax for IP address
"
)
elif
part
==
ipv4_addr
:
# FIXME: Make sure IPv4 can only be last part
# FIXME: inet_aton allows IPv4 addresses with less than 4 octets
result
+=
socket
.
inet_aton
(
ipv4_addr
)
elif
part
==
ipv4_addr
:
result
+=
ipv4_bin
else
:
# Each part must be 16bit. Add missing zeroes before decoding.
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment