Skip to content

Commit

Permalink
Merge pull request #103739 from rafiss/backport22.2-103645
Browse files Browse the repository at this point in the history
release-22.2: pgwire: adds bounds check for FormatCodes
  • Loading branch information
rafiss authored May 24, 2023
2 parents 939bbb5 + 09eacda commit fe91338
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/generated/redact_safe.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pkg/sql/catalog/descpb/structured.go | `DescriptorState`
pkg/sql/catalog/descpb/structured.go | `DescriptorVersion`
pkg/sql/catalog/descpb/structured.go | `IndexDescriptorVersion`
pkg/sql/catalog/descpb/structured.go | `MutationID`
pkg/sql/pgwire/pgwirebase/encoding.go | `FormatCode`
pkg/sql/schemachanger/scplan/internal/scgraph/graph.go | `RuleName`
pkg/sql/sem/catid/ids.go | `ColumnID`
pkg/sql/sem/catid/ids.go | `ConstraintID`
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/pgwire/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,9 @@ func (c *conn) bufferRow(ctx context.Context, row tree.Datums, r *commandResult)
for i, col := range row {
fmtCode := pgwirebase.FormatText
if r.formatCodes != nil {
if i >= len(r.formatCodes) {
return errors.AssertionFailedf("could not find format code for column %d in %v", i, r.formatCodes)
}
fmtCode = r.formatCodes[i]
}
switch fmtCode {
Expand Down Expand Up @@ -1414,6 +1417,9 @@ func (c *conn) bufferBatch(ctx context.Context, batch coldata.Batch, r *commandR
for vecIdx := 0; vecIdx < len(c.vecsScratch.Vecs); vecIdx++ {
fmtCode := pgwirebase.FormatText
if r.formatCodes != nil {
if vecIdx >= len(r.formatCodes) {
return errors.AssertionFailedf("could not find format code for column %d in %v", vecIdx, r.formatCodes)
}
fmtCode = r.formatCodes[vecIdx]
}
switch fmtCode {
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/pgwire/pgwirebase/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ go_library(
"//pkg/util/timeutil/pgdate",
"//pkg/util/uint128",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_redact//:redact",
"@com_github_dustin_go_humanize//:go-humanize",
"@com_github_lib_pq//oid",
],
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/pgwire/pgwirebase/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/timeutil/pgdate"
"github.com/cockroachdb/cockroach/pkg/util/uint128"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/redact"
"github.com/dustin/go-humanize"
"github.com/lib/pq/oid"
)
Expand Down Expand Up @@ -71,6 +72,11 @@ var ReadBufferMaxMessageSizeClusterSetting = settings.RegisterByteSizeSetting(
//go:generate stringer -type=FormatCode
type FormatCode uint16

var _ redact.SafeValue = FormatCode(0)

// SafeValue implements the redact.SafeValue interface.
func (i FormatCode) SafeValue() {}

const (
// FormatText is the default, text format.
FormatText FormatCode = 0
Expand Down

0 comments on commit fe91338

Please sign in to comment.