mirror of
https://github.com/github/codeql.git
synced 2026-01-29 22:32:58 +01:00
Merge pull request #31 from max-schaefer/string-break-source
Sharpen the sources for `StringBreak`.
This commit is contained in:
@@ -49,7 +49,8 @@ module StringBreak {
|
||||
class JsonMarshalAsSource extends Source {
|
||||
JsonMarshalAsSource() {
|
||||
exists(Function jsonMarshal | jsonMarshal.hasQualifiedName("encoding/json", "Marshal") |
|
||||
this = jsonMarshal.getACall()
|
||||
// we are only interested in the first result (the second result is an error)
|
||||
this = DataFlow::extractTupleElement(jsonMarshal.getACall(), 0)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
edges
|
||||
| StringBreak.go:10:20:10:40 | call to Marshal : tuple type | StringBreak.go:14:47:14:57 | versionJSON |
|
||||
| StringBreak.go:10:2:10:40 | ... := ...[0] : slice type | StringBreak.go:14:47:14:57 | versionJSON |
|
||||
nodes
|
||||
| StringBreak.go:10:20:10:40 | call to Marshal : tuple type | semmle.label | call to Marshal : tuple type |
|
||||
| StringBreak.go:10:2:10:40 | ... := ...[0] : slice type | semmle.label | ... := ...[0] : slice type |
|
||||
| StringBreak.go:14:47:14:57 | versionJSON | semmle.label | versionJSON |
|
||||
#select
|
||||
| StringBreak.go:14:47:14:57 | versionJSON | StringBreak.go:10:20:10:40 | call to Marshal : tuple type | StringBreak.go:14:47:14:57 | versionJSON | If this $@ contains a single quote, it could break out of the enclosing quotes. | StringBreak.go:10:20:10:40 | call to Marshal | JSON value |
|
||||
| StringBreak.go:14:47:14:57 | versionJSON | StringBreak.go:10:2:10:40 | ... := ...[0] : slice type | StringBreak.go:14:47:14:57 | versionJSON | If this $@ contains a single quote, it could break out of the enclosing quotes. | StringBreak.go:10:2:10:40 | ... := ...[0] | JSON value |
|
||||
|
||||
14
ql/test/query-tests/Security/CWE-089/tst.go
Normal file
14
ql/test/query-tests/Security/CWE-089/tst.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func marshal(version interface{}) string {
|
||||
versionJSON, err := json.Marshal(version)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("error: '%v'", err) // OK
|
||||
}
|
||||
return versionJSON
|
||||
}
|
||||
Reference in New Issue
Block a user