File tree 1 file changed +22
-5
lines changed
1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -170,20 +170,37 @@ func (a *Inet6Addr) marshal(b []byte) (int, error) {
170
170
171
171
// parseInetAddr parses b as an internet address for IPv4 or IPv6.
172
172
func parseInetAddr (af int , b []byte ) (Addr , error ) {
173
+ const (
174
+ off4 = 4 // offset of in_addr
175
+ off6 = 8 // offset of in6_addr
176
+ )
173
177
switch af {
174
178
case syscall .AF_INET :
175
- if len (b ) < sizeofSockaddrInet {
179
+ if len (b ) < ( off4 + 1 ) || len ( b ) < int ( b [ 0 ]) {
176
180
return nil , errInvalidAddr
177
181
}
182
+ sockAddrLen := int (b [0 ])
178
183
a := & Inet4Addr {}
179
- copy (a .IP [:], b [4 :8 ])
184
+ n := off4 + 4
185
+ if sockAddrLen < n {
186
+ n = sockAddrLen
187
+ }
188
+ copy (a .IP [:], b [off4 :n ])
180
189
return a , nil
181
190
case syscall .AF_INET6 :
182
- if len (b ) < sizeofSockaddrInet6 {
191
+ if len (b ) < ( off6 + 1 ) || len ( b ) < int ( b [ 0 ]) {
183
192
return nil , errInvalidAddr
184
193
}
185
- a := & Inet6Addr {ZoneID : int (nativeEndian .Uint32 (b [24 :28 ]))}
186
- copy (a .IP [:], b [8 :24 ])
194
+ sockAddrLen := int (b [0 ])
195
+ n := off6 + 16
196
+ if sockAddrLen < n {
197
+ n = sockAddrLen
198
+ }
199
+ a := & Inet6Addr {}
200
+ if sockAddrLen == sizeofSockaddrInet6 {
201
+ a .ZoneID = int (nativeEndian .Uint32 (b [24 :28 ]))
202
+ }
203
+ copy (a .IP [:], b [off6 :n ])
187
204
if a .IP [0 ] == 0xfe && a .IP [1 ]& 0xc0 == 0x80 || a .IP [0 ] == 0xff && (a .IP [1 ]& 0x0f == 0x01 || a .IP [1 ]& 0x0f == 0x02 ) {
188
205
// KAME based IPv6 protocol stack usually
189
206
// embeds the interface index in the
You can’t perform that action at this time.
0 commit comments