Skip to content

Commit

Permalink
Small fix for parse_ipv4
Browse files Browse the repository at this point in the history
Still problems on 32bit due to issues discussed in JuliaLang#3447
  • Loading branch information
Keno committed Jun 25, 2013
1 parent 402a9fd commit 2e6ac49
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ function parse_ipv4(str)
end
if f[1] == '0'
if length(f) >= 2 && f[2] == 'x'
if length(f) > 8 # 2+(3*2) - prevent parseint from overflowing on 32bit
error("IPv4 field too large")
end
r = parseint(f[3:end],16)
else
if length(f) > 9 # 1+8 - prevent parseint from overflowing on 32bit
error("IPv4 field too large")
end
r = parseint(f,8)
end
else
Expand All @@ -157,7 +163,7 @@ function parse_ipv4(str)
end
ret |= uint32(r) << ((4-i)*8)
else
if r > ((uint64(1)<<((5-length(f))*8))-1)
if r > ((uint64(1)<<((5-length(fields))*8))-1)
error("IPv4 field too large")
end
ret |= r
Expand Down

0 comments on commit 2e6ac49

Please sign in to comment.