rspec/rules/S2077/go/rule.adoc

56 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
[source,go,diff-id=1,diff-type=noncompliant]
----
func getName(db *sql.DB, id string) (string, error) {
var name string
row := db.QueryRow("SELECT name FROM users WHERE id = " + id) // Sensitive
if err := row.Scan(&name); err != nil {
if err == sql.ErrNoRows {
return name, fmt.Errorf("No name found for id %s", id)
}
}
return name, nil
}
----
== Compliant Solution
[source,go,diff-id=1,diff-type=compliant]
----
func getName(db *sql.DB, id string) (string, error) {
var name string
row := db.QueryRow("SELECT name FROM users WHERE id = ?", id)
if err := row.Scan(&name); err != nil {
if err == sql.ErrNoRows {
return name, fmt.Errorf("No name found for id %s", id)
}
}
return name, nil
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]