Skip to content

Commit 0b8240f

Browse files
authored
contrib/gocql/gocql: avoid panics (#641)
We shouldn't make assumptions about slice lengths when the length doesn't depend on us. One innocent change in the gocql library could cause havoc.
1 parent 3f45f6d commit 0b8240f

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

contrib/gocql/gocql/gocql.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,9 @@ func WrapQuery(q *gocql.Query, opts ...WrapOption) *Query {
5656
fn(cfg)
5757
}
5858
if cfg.resourceName == "" {
59-
q := `"` + strings.SplitN(q.String(), "\"", 3)[1] + `"`
60-
q, err := strconv.Unquote(q)
61-
if err != nil {
62-
// avoid having an empty resource as it will cause the trace
63-
// to be dropped.
64-
q = "_"
59+
if parts := strings.SplitN(q.String(), "\"", 3); len(parts) == 3 {
60+
cfg.resourceName = parts[1]
6561
}
66-
cfg.resourceName = q
6762
}
6863
tq := &Query{q, &params{config: cfg}, context.Background()}
6964
return tq

0 commit comments

Comments
 (0)