mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-20 03:21:26 +00:00
dashboard/dashapi: always zero reply
json decoding behavior is somewhat surprising (see // https://github.com/golang/go/issues/21092). This behavior is especially easy to hit in tests that reuse reply objects. To avoid any surprises, we zero the reply.
This commit is contained in:
parent
4f5ad2aa53
commit
841aeb0303
@ -14,6 +14,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -157,6 +158,16 @@ type (
|
||||
)
|
||||
|
||||
func Query(client, addr, key, method string, ctor RequestCtor, doer RequestDoer, req, reply interface{}) error {
|
||||
if reply != nil {
|
||||
// json decoding behavior is somewhat surprising
|
||||
// (see // https://github.com/golang/go/issues/21092).
|
||||
// To avoid any surprises, we zero the reply.
|
||||
typ := reflect.TypeOf(reply)
|
||||
if typ.Kind() != reflect.Ptr {
|
||||
return fmt.Errorf("resp must be a pointer")
|
||||
}
|
||||
reflect.ValueOf(reply).Elem().Set(reflect.New(typ.Elem()).Elem())
|
||||
}
|
||||
values := make(url.Values)
|
||||
values.Add("client", client)
|
||||
values.Add("key", key)
|
||||
|
Loading…
x
Reference in New Issue
Block a user