Details
-
Bug
-
Resolution: Fixed
-
Unknown
-
None
-
None
-
None
-
Not Needed
-
Description
readconcern.ReadConcern and writeconcern.WriteConcern marshalers do not handle the nil case and so the following code will result in a runtime error:
type Foo struct {
|
ReadConcern *readconcern.ReadConcern
|
}
|
|
|
func main() {
|
foo := &Foo{}
|
|
|
_, err := bson.Marshal(foo)
|
if err != nil {
|
panic(err)
|
}
|
}
|
panic: runtime error: invalid memory address or nil pointer dereference
|
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1195d78]goroutine 1 [running]: |
go.mongodb.org/mongo-driver/mongo/readconcern.(*ReadConcern).MarshalBSONValue(0x3?) |
/Users/preston.vasquez/Developer/mongo-go-driver/mongo/readconcern/readconcern.go:73 +0x18 |
reflect.Value.call({0x11b7b40?, 0xc000014690?, 0x0?}, {0x11d831c, 0x4}, {0x0, 0x0, 0x121bce0?}) |
/usr/local/go/src/reflect/value.go:586 +0xb07 |
reflect.Value.Call({0x11b7b40?, 0xc000014690?, 0x11b7b40?}, {0x0?, 0x11b7b40?, 0x1059b65?}) |
/usr/local/go/src/reflect/value.go:370 +0xbc |
go.mongodb.org/mongo-driver/bson/bsoncodec.DefaultValueEncoders.ValueMarshalerEncodeValue({}, {0xc0000061a0?, 0x50?}, {0x121b3f0, 0xc000036140}, {0x11b5f60?, 0xc000012048?, 0x11b5f60?}) |
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/default_value_encoders.go:557 +0x2d1 |
go.mongodb.org/mongo-driver/bson/bsoncodec.ValueEncoderFunc.EncodeValue(0xc000036140?, {0xc00011cc40?, 0xb?}, {0x121b3f0?, 0xc000036140?}, {0x11b5f60?, 0xc000012048?, 0xc00000d2e0?}) |
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/bsoncodec.go:178 +0x4a |
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).EncodeValue(0x11a33a0?, {0xc00011cc40?, 0xc0?}, {0x121b3f0, 0xc000036140}, {0x11ba3c0?, 0xc000012048?, 0x500?}) |
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/struct_codec.go:181 +0x5f6 |
go.mongodb.org/mongo-driver/bson/bsoncodec.(*PointerCodec).EncodeValue(0xc00007a750, {0xc00011cc40?, 0xa0?}, {0x121b3f0, 0xc000036140}, {0x11a33a0?, 0xc000012048?, 0x107a4f9?}) |
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/pointer_codec.go:67 +0x53b |
go.mongodb.org/mongo-driver/bson.(*Encoder).Encode(0xc00006e1e0, {0x11a33a0?, 0xc000012048}) |
/Users/preston.vasquez/Developer/mongo-go-driver/bson/encoder.go:79 +0x174 |
go.mongodb.org/mongo-driver/bson.MarshalAppendWithContext({0xc00011cc40?, 0x48?}, {0x136ac80, 0x0, 0x0}, {0x11a33a0, 0xc000012048}) |
/Users/preston.vasquez/Developer/mongo-go-driver/bson/marshal.go:103 +0x21d |
go.mongodb.org/mongo-driver/bson.MarshalAppendWithRegistry(...)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/marshal.go:79 |
go.mongodb.org/mongo-driver/bson.MarshalWithRegistry(0xc0000061a0?, {0x11a33a0, 0xc000012048}) |
/Users/preston.vasquez/Developer/mongo-go-driver/bson/marshal.go:65 +0x52 |
go.mongodb.org/mongo-driver/bson.Marshal(...)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/marshal.go:51 |
main.main()
|
/Users/preston.vasquez/Developer/technical/workshop/mongo/bson/marshal-client-options/main.go:17 +0x45 |
exit status 2 |