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

latuan1987/hscodeadvisor_others: search_func/main.go; 46 LoC

Open
#12,622 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [latuan1987/hscodeadvisor_others](https://www.github.com/latuan1987/hscodeadvisor_others) at [search_func/main.go](https://github.com/latuan1987/hscodeadvisor_others/blob/744c411757323e9849bed492e4e13b2680d42808/search_func/main.go#L188-L233)

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.

>

[Click here to see the code in its original context.](https://github.com/latuan1987/hscodeadvisor_others/blob/744c411757323e9849bed492e4e13b2680d42808/search_func/main.go#L188-L233)

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

```go
for _, hit := range searchResult.Hits {
// Write JSON data to response body
c.JSON(http.StatusOK, &hit)
if id, err := strconv.ParseInt(hit.ID, 10, 64); err == nil {
// Query data
rows, err := db.Query("SELECT * FROM Products WHERE ID=$1", id)
if err != nil {
c.String(http.StatusInternalServerError, fmt.Sprintf("Query data: %q", err))
return
}

for rows.Next() {
var id int64
var date time.Time
var category string
var proddesc string
var picture string
var hscode string
var country string
var tariffcode string
var explain string
var vote string

if rows.Scan(&id, &date, &category, &proddesc, &picture, &hscode, &country, &tariffcode, &explain, &vote); err != nil {
c.String(http.StatusInternalServerError, fmt.Sprintf("Error scanning: %q", err))
} else {
resHs := &DataInfo{
ID: id,
DATE: date,
CATEGORY: category,
PRODDESC: proddesc,
PICTURE: picture,
HSCODE: hscode,
COUNTRY: country,
TARIFFCODE: tariffcode,
EXPLAIN: explain,
VOTE: vote}

// Write JSON data to response body
c.JSON(http.StatusOK, resHs)
}
}
// Close
rows.Close()
}
}

```

Click here to show extra information the analyzer produced.

```
No path was found through the callgraph that could lead to a function which writes a pointer argument.

No path was found through the callgraph that could lead to a function which passes a pointer to third-party code.

root signature {JSON 2} was not found in the callgraph; reference was passed directly to third-party code
```

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: 744c411757323e9849bed492e4e13b2680d42808

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with search_func/main.go lines 188-233 and inspect the range over searchResult.Hits, especially the calls passing hit to c.JSON. Trace how those responses are written and check whether the analyzer finding affects the returned data. Done means the finding is understood and the response behavior is verified without introducing a range-variable pointer issue.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.