Skip to content

Commit d14b733

Browse files
Kenostaticfloat
authored andcommitted
Small fix for parse_ipv4
Still problems on 32bit due to issues discussed in #3447
1 parent 73fae13 commit d14b733

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

base/socket.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ function parse_ipv4(str)
144144
end
145145
if f[1] == '0'
146146
if length(f) >= 2 && f[2] == 'x'
147+
if length(f) > 8 # 2+(3*2) - prevent parseint from overflowing on 32bit
148+
error("IPv4 field too large")
149+
end
147150
r = parseint(f[3:end],16)
148151
else
152+
if length(f) > 9 # 1+8 - prevent parseint from overflowing on 32bit
153+
error("IPv4 field too large")
154+
end
149155
r = parseint(f,8)
150156
end
151157
else
@@ -157,7 +163,7 @@ function parse_ipv4(str)
157163
end
158164
ret |= uint32(r) << ((4-i)*8)
159165
else
160-
if r > ((uint64(1)<<((5-length(f))*8))-1)
166+
if r > ((uint64(1)<<((5-length(fields))*8))-1)
161167
error("IPv4 field too large")
162168
end
163169
ret |= r

0 commit comments

Comments
 (0)