mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
gob: make robust when decoding a struct with non-struct data.
The decoder was crashing when handling an rpc that expected a struct but was delivered something else. This diagnoses the problem. The other direction (expecting non-struct but getting one) was already handled. R=rsc CC=golang-dev https://golang.org/cl/2246041
This commit is contained in:
parent
42a61b920e
commit
c8b3d02939
3 changed files with 47 additions and 4 deletions
|
|
@ -843,12 +843,17 @@ func (dec *Decoder) compileDec(remoteId typeId, rt reflect.Type) (engine *decEng
|
|||
return dec.compileSingle(remoteId, rt)
|
||||
}
|
||||
var wireStruct *structType
|
||||
// Builtin types can come from global pool; the rest must be defined by the decoder
|
||||
// Builtin types can come from global pool; the rest must be defined by the decoder.
|
||||
// Also we know we're decoding a struct now, so the client must have sent one.
|
||||
if t, ok := builtinIdToType[remoteId]; ok {
|
||||
wireStruct = t.(*structType)
|
||||
wireStruct, _ = t.(*structType)
|
||||
} else {
|
||||
wireStruct = dec.wireType[remoteId].structT
|
||||
}
|
||||
if wireStruct == nil {
|
||||
return nil, os.ErrorString("gob: type mismatch in decoder: want struct type " +
|
||||
rt.String() + "; got non-struct")
|
||||
}
|
||||
engine = new(decEngine)
|
||||
engine.instr = make([]decInstr, len(wireStruct.field))
|
||||
// Loop over the fields of the wire type.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue