aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/convert.go
diff options
context:
space:
mode:
authorKevin Burke <kev@inburke.com>2016-04-23 11:00:05 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2016-04-30 18:40:36 +0000
commit4e0cd1eeef419b221fda3dd3966be71095f0b4ce (patch)
treea3895de98305efe10e4ccb76b45c7d4132148284 /src/database/sql/convert.go
parenta20fd1f6ba668ec0bd8c432d26def2b65cc6609a (diff)
downloadgo-4e0cd1eeef419b221fda3dd3966be71095f0b4ce.tar.xz
database/sql: clone data for named []byte types
Previously named byte types like json.RawMessage could get dirty database memory from a call to Scan. These types would activate a code path that didn't clone the byte data coming from the database before assigning it. Another thread could then overwrite the byte array in src, which has unexpected consequences. Originally reported by Jason Moiron; the patch and test are his suggestions. Fixes #13905. Change-Id: Iacfef61cbc9dd51c8fccef9b2b9d9544c77dd0e0 Reviewed-on: https://go-review.googlesource.com/22393 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/database/sql/convert.go')
-rw-r--r--src/database/sql/convert.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/database/sql/convert.go b/src/database/sql/convert.go
index 92c3b689c1..99aed2398e 100644
--- a/src/database/sql/convert.go
+++ b/src/database/sql/convert.go
@@ -217,7 +217,12 @@ func convertAssign(dest, src interface{}) error {
dv := reflect.Indirect(dpv)
if sv.IsValid() && sv.Type().AssignableTo(dv.Type()) {
- dv.Set(sv)
+ switch b := src.(type) {
+ case []byte:
+ dv.Set(reflect.ValueOf(cloneBytes(b)))
+ default:
+ dv.Set(sv)
+ }
return nil
}