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

nullboundary/socialhardware: helpers.go; 52 LoC

Aperta
#13,653 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
fresh medium
Lingua principale
Nessun dato sulla lingua
Stelle
0
Fork
0
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Found a possible issue in [nullboundary/socialhardware](https://www.github.com/nullboundary/socialhardware) at [helpers.go](https://github.com/nullboundary/socialhardware/blob/fcd29718ded99ebc3ed42057aae744d0c909accd/helpers.go#L70-L121)

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.

> range-loop variable trigger used in defer or goroutine at line 78

[Click here to see the code in its original context.](https://github.com/nullboundary/socialhardware/blob/fcd29718ded99ebc3ed42057aae744d0c909accd/helpers.go#L70-L121)

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

```go
for _, trigger := range triggerList {

//log.Printf("ID: %s Trigger: if %s then %s \n", trigger.TriggerID, trigger.TriggerCondition, trigger.Triggerhook.URL)

if triggerMatch(trigger, data) {
//every client request in a seperate goroutine (some could be slow to return)
go func() {

u, err := url.Parse(trigger.URL)
if err != nil {
log.Printf("[ERROR] %s", err)
return
}
//TODO: maybe localhost shouldn't be allowed after deployment ?
if u.Scheme == "localhost" {
u.Scheme = "http://localhost"
}

log.Println("URL: ", u)

//if trigger.Body
bytesBody, err := trigger.Body.MarshalJSON()
if err != nil {
log.Printf("[ERROR] %s", err)
}
bodyReader := bytes.NewReader(bytesBody)

//var jsonStr = []byte(`{"title":"Buy cheese and bread for breakfast."}`)
req, err := http.NewRequest(trigger.Method, u.String(), bodyReader)
req.Header.Set("Authorization", "0e1766cb9a519d3")

header := strings.Split(trigger.Headers, ":")
headerKey := strings.TrimSpace(header[0])
headerValue := strings.TrimSpace(header[1])
req.Header.Add(headerKey, headerValue)

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Printf("[ERROR] %s", err)
return
}
defer resp.Body.Close()

log.Println("response Status:", resp.Status)
log.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
log.Println("response Body:", string(body))
}()
}

}

```

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: fcd29718ded99ebc3ed42057aae744d0c909accd

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia leggendo helpers.go alle righe 70-121, in particolare il ciclo range e la goroutine segnalata alla riga 78, quindi confronta il risultato dell’analizzatore con il dispatch dei trigger circostante. Conferma se il comportamento è un bug, è mitigato o è desiderabile, e lascia la reaction corrispondente; nell’issue non è indicato alcun file di test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
50/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.