Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 669ed91

Browse files
committed
Move EncodingJson to stdlib; add Escape class.
1 parent 24c23ba commit 669ed91

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

ql/src/semmle/go/frameworks/Stdlib.qll

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -707,41 +707,6 @@ module Log {
707707
}
708708
}
709709

710-
/** Provides models of some functions in the `encoding/json` package. */
711-
module EncodingJson {
712-
/** The `Marshal` or `MarshalIndent` function in the `encoding/json` package. */
713-
class MarshalFunction extends TaintTracking::FunctionModel, MarshalingFunction::Range {
714-
MarshalFunction() {
715-
this.hasQualifiedName("encoding/json", "Marshal") or
716-
this.hasQualifiedName("encoding/json", "MarshalIndent")
717-
}
718-
719-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
720-
inp = getAnInput() and outp = getOutput()
721-
}
722-
723-
override FunctionInput getAnInput() { result.isParameter(0) }
724-
725-
override FunctionOutput getOutput() { result.isResult(0) }
726-
727-
override string getFormat() { result = "JSON" }
728-
}
729-
730-
private class UnmarshalFunction extends TaintTracking::FunctionModel, UnmarshalingFunction::Range {
731-
UnmarshalFunction() { this.hasQualifiedName("encoding/json", "Unmarshal") }
732-
733-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
734-
inp = getAnInput() and outp = getOutput()
735-
}
736-
737-
override FunctionInput getAnInput() { result.isParameter(0) }
738-
739-
override FunctionOutput getOutput() { result.isParameter(1) }
740-
741-
override string getFormat() { result = "JSON" }
742-
}
743-
}
744-
745710
/** Provides models of some functions in the `crypto/cipher` package. */
746711
module CryptoCipher {
747712
private class AeadOpenFunction extends TaintTracking::FunctionModel, Method {

ql/src/semmle/go/frameworks/stdlib/EncodingJson.qll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@ import go
66

77
/** Provides models of commonly used functions in the `encoding/json` package. */
88
module EncodingJson {
9+
private class Escape extends EscapeFunction::Range {
10+
Escape() { hasQualifiedName("encoding/json", "HTMLEscape") }
11+
12+
override string kind() { result = "html" }
13+
}
14+
15+
/** The `Marshal` or `MarshalIndent` function in the `encoding/json` package. */
16+
class MarshalFunction extends TaintTracking::FunctionModel, MarshalingFunction::Range {
17+
MarshalFunction() {
18+
this.hasQualifiedName("encoding/json", "Marshal") or
19+
this.hasQualifiedName("encoding/json", "MarshalIndent")
20+
}
21+
22+
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
23+
inp = getAnInput() and outp = getOutput()
24+
}
25+
26+
override FunctionInput getAnInput() { result.isParameter(0) }
27+
28+
override FunctionOutput getOutput() { result.isResult(0) }
29+
30+
override string getFormat() { result = "JSON" }
31+
}
32+
33+
private class UnmarshalFunction extends TaintTracking::FunctionModel, UnmarshalingFunction::Range {
34+
UnmarshalFunction() { this.hasQualifiedName("encoding/json", "Unmarshal") }
35+
36+
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
37+
inp = getAnInput() and outp = getOutput()
38+
}
39+
40+
override FunctionInput getAnInput() { result.isParameter(0) }
41+
42+
override FunctionOutput getOutput() { result.isParameter(1) }
43+
44+
override string getFormat() { result = "JSON" }
45+
}
46+
947
private class FunctionModels extends TaintTracking::FunctionModel {
1048
FunctionInput inp;
1149
FunctionOutput outp;

0 commit comments

Comments
 (0)