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
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
85d43059
Commit
85d43059
authored
Jan 28, 2017
by
Guillaume Valadon
Committed by
GitHub
Jan 28, 2017
Browse files
Options
Downloads
Plain Diff
Merge pull request #492 from hdnivara/pr/ipv4-addr-check
Error out incorrect IPv4 format in IPv6 addresses in inet_pton
parents
a4ff0423
2e958455
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/pton_ntop.py
+10
-3
10 additions, 3 deletions
scapy/pton_ntop.py
test/regression.uts
+26
-0
26 additions, 0 deletions
test/regression.uts
with
36 additions
and
3 deletions
scapy/pton_ntop.py
+
10
−
3
View file @
85d43059
...
...
@@ -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.
test/regression.uts
+
26
−
0
View file @
85d43059
...
...
@@ -7464,6 +7464,32 @@ in6_getscope("ff05::2807") == IPV6_ADDR_SITELOCAL
in6_getscope("ff01::2807") == IPV6_ADDR_LOOPBACK
in6_getscope("::1") == IPV6_ADDR_LOOPBACK
= inet_pton()
import socket
ip6_bad_addrs = ["fe80::2e67:ef2d:7eca::ed8a",
"fe80:1234:abcd::192.168.40.12:abcd",
"fe80:1234:abcd::192.168.40",
"fe80:1234:abcd::192.168.400.12"]
for ip6 in ip6_bad_addrs:
rc = False
try:
inet_pton(socket.AF_INET6, ip6)
except Exception, e:
rc = True
assert rc
ip6_good_addrs = ["fe80:1234:abcd::192.168.40.12",
"fe80:1234:abcd::fe06",
"fe80::2e67:ef2d:7ece:ed8a"]
for ip6 in ip6_good_addrs:
rc = True
try:
inet_pton(socket.AF_INET6, ip6)
except Exception, e:
rc = False
assert rc
############
############
...
...
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