Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
114792: sqlsmith: don't lose type for generated REFCURSOR constant r=DrewKimball a=DrewKimball

The sqlsmith random syntax generator contains some logic to test that PII is properly redacted. This works by adding a "PII" prefix to randomly generated string values. Previously, this logic incorrectly converted REFCURSOR datums to STRING datums, which could cause a panic because REFCURSOR is not compatible for comparison with other types. This patch converts the "PII" string back to a REFCURSOR when necessary.

Fixes cockroachdb#114789

Release note: None

Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
  • Loading branch information
craig[bot] and DrewKimball committed Nov 22, 2023
2 parents a1f6852 + 81434a8 commit a94dbaf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/internal/sqlsmith/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ func makeConstDatum(s *Smither, typ *types.T) tree.Datum {
if typ.Width() > 0 {
sv = util.TruncateString(sv, int(typ.Width()))
}
datum = tree.NewDString(sv)
if typ.Family() == types.RefCursorFamily {
// REFCURSOR is not compatible with the other string-like types, so make
// sure not to lose the type of the datum.
datum = tree.NewDRefCursor(sv)
} else {
datum = tree.NewDString(sv)
}
}
return datum
}
Expand Down

0 comments on commit a94dbaf

Please sign in to comment.