github-vet / github-vet/rangeloop-pointer-findings

zwdong1994/cockroach-old: pkg/sql/pg_catalog.go; 98 LoC

Open
#15,639 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [zwdong1994/cockroach-old](https://www.github.com/zwdong1994/cockroach-old) at [pkg/sql/pg_catalog.go](https://github.com/zwdong1994/cockroach-old/blob/b0652329251811da42582bd405a0ce8f329c962c/pkg/sql/pg_catalog.go#L1319-L1416)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to builtin was used in a composite literal at line 1382

[Click here to see the code in its original context.](https://github.com/zwdong1994/cockroach-old/blob/b0652329251811da42582bd405a0ce8f329c962c/pkg/sql/pg_catalog.go#L1319-L1416)

Click here to show the 98 line(s) of Go which triggered the analyzer.

```go
for _, builtin := range overloads {
dName := tree.NewDName(name)
dSrc := tree.NewDString(name)

var retType tree.Datum
isRetSet := false
if fixedRetType := builtin.FixedReturnType(); fixedRetType != nil {
var retOid oid.Oid
if t, ok := fixedRetType.(types.TTuple); ok && builtin.Generator != nil {
isRetSet = true
// Functions returning tables with zero, or more than one
// columns are marked to return "anyelement"
// (e.g. `unnest`)
retOid = oid.T_anyelement
if len(t.Types) == 1 {
// Functions returning tables with exactly one column
// are marked to return the type of that column
// (e.g. `generate_series`).
retOid = t.Types[0].Oid()
}
} else {
retOid = fixedRetType.Oid()
}
retType = tree.NewDOid(tree.DInt(retOid))
}

argTypes := builtin.Types
dArgTypes := tree.NewDArray(types.Oid)
for _, argType := range argTypes.Types() {
if err := dArgTypes.Append(tree.NewDOid(tree.DInt(argType.Oid()))); err != nil {
return err
}
}

var argmodes tree.Datum
var variadicType tree.Datum
switch v := argTypes.(type) {
case tree.VariadicType:
if len(v.FixedTypes) == 0 {
argmodes = proArgModeVariadic
} else {
ary := tree.NewDArray(types.String)
for range v.FixedTypes {
if err := ary.Append(tree.NewDString("i")); err != nil {
return err
}
}
if err := ary.Append(tree.NewDString("v")); err != nil {
return err
}
argmodes = ary
}
variadicType = tree.NewDOid(tree.DInt(v.VarType.Oid()))
case tree.HomogeneousType:
argmodes = proArgModeVariadic
argType := types.Any
oid := argType.Oid()
variadicType = tree.NewDOid(tree.DInt(oid))
default:
argmodes = tree.DNull
variadicType = oidZero
}
err := addRow(
h.BuiltinOid(name, &builtin), // oid
dName, // proname
nspOid, // pronamespace
tree.DNull, // proowner
oidZero, // prolang
tree.DNull, // procost
tree.DNull, // prorows
variadicType, // provariadic
tree.DNull, // protransform
tree.MakeDBool(tree.DBool(isAggregate)), // proisagg
tree.MakeDBool(tree.DBool(isWindow)), // proiswindow
tree.DBoolFalse, // prosecdef
tree.MakeDBool(tree.DBool(!props.Impure)), // proleakproof
tree.DBoolFalse, // proisstrict
tree.MakeDBool(tree.DBool(isRetSet)), // proretset
tree.DNull, // provolatile
tree.DNull, // proparallel
tree.NewDInt(tree.DInt(builtin.Types.Length())), // pronargs
tree.NewDInt(tree.DInt(0)), // pronargdefaults
retType, // prorettype
tree.NewDOidVectorFromDArray(dArgTypes), // proargtypes
tree.DNull, // proallargtypes
argmodes, // proargmodes
tree.DNull, // proargnames
tree.DNull, // proargdefaults
tree.DNull, // protrftypes
dSrc, // prosrc
tree.DNull, // probin
tree.DNull, // proconfig
tree.DNull, // proacl
)
if err != nil {
return err
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: b0652329251811da42582bd405a0ce8f329c962c

Contributor guide

No contributing guide indexed for this repository

Research direction

Read pkg/sql/pg_catalog.go lines 1319-1416, focusing on h.BuiltinOid(name, &builtin) inside the range over overloads. Determine whether the referenced range variable can escape or cause incorrect metadata, then use the requested issue reaction to mark Bug, Mitigated, or Desirable Behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.