Check that off <= lenmsg
Defense in depth, this should happen, but it happens... So check for it and return an error. Maybe (there is no testcase) fixes #106
This commit is contained in:
parent
34f5a12bfc
commit
8fecf17714
5
msg.go
5
msg.go
|
@ -860,7 +860,7 @@ func packStructCompress(any interface{}, msg []byte, off int, compression map[st
|
||||||
return off, err
|
return off, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mg): Fix use of rdlength here
|
// TODO(miek): Fix use of rdlength here
|
||||||
|
|
||||||
// Unpack a reflect.StructValue from msg.
|
// Unpack a reflect.StructValue from msg.
|
||||||
// Same restrictions as packStructValue.
|
// Same restrictions as packStructValue.
|
||||||
|
@ -868,6 +868,9 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
|
||||||
var rdend int
|
var rdend int
|
||||||
lenmsg := len(msg)
|
lenmsg := len(msg)
|
||||||
for i := 0; i < val.NumField(); i++ {
|
for i := 0; i < val.NumField(); i++ {
|
||||||
|
if off > lenmsg {
|
||||||
|
return lenmsg, &Error{"bad offset unpacking"}
|
||||||
|
}
|
||||||
switch fv := val.Field(i); fv.Kind() {
|
switch fv := val.Field(i); fv.Kind() {
|
||||||
default:
|
default:
|
||||||
return lenmsg, &Error{err: "bad kind unpacking"}
|
return lenmsg, &Error{err: "bad kind unpacking"}
|
||||||
|
|
Loading…
Reference in New Issue