cloud/bmdb/reflection: copy byte slices

The pq driver doesn't allocate unique backing buffers for each slice
handed out as part of scanning, so we need to do a copy. Otherwise we
end up with junk being written to the reflected field data if another
SQL operation is performed later.

Change-Id: I8f5a135ef3c5a3bb365098e1727e26572ddedcce
Reviewed-on: https://review.monogon.dev/c/monogon/+/1537
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/cloud/bmaas/bmdb/reflection/reflection.go b/cloud/bmaas/bmdb/reflection/reflection.go
index 848c924..1e2a414 100644
--- a/cloud/bmaas/bmdb/reflection/reflection.go
+++ b/cloud/bmaas/bmdb/reflection/reflection.go
@@ -381,7 +381,10 @@
 		if !ok {
 			return fmt.Errorf("SQL type %q, but got %+v", r.Type.NativeType, src)
 		}
-		r.bytes = &src2
+		// Copy the bytes, as they are otherwise going to be reused by the pq library.
+		copied := make([]byte, len(src2))
+		copy(copied[:], src2)
+		r.bytes = &copied
 	case "USER-DEFINED":
 		switch r.Type.NativeUDTName {
 		case "provider":