|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `encoding/xml` package. |
| 3 | + */ |
| 4 | + |
| 5 | +import go |
| 6 | + |
| 7 | +/** Provides models of commonly used functions in the `encoding/xml` package. */ |
| 8 | +module EncodingXml { |
| 9 | + private class FunctionModels extends TaintTracking::FunctionModel { |
| 10 | + FunctionInput inp; |
| 11 | + FunctionOutput outp; |
| 12 | + |
| 13 | + FunctionModels() { |
| 14 | + // signature: func CopyToken(t Token) Token |
| 15 | + hasQualifiedName("encoding/xml", "CopyToken") and |
| 16 | + (inp.isParameter(0) and outp.isResult()) |
| 17 | + or |
| 18 | + // signature: func Escape(w io.Writer, s []byte) |
| 19 | + hasQualifiedName("encoding/xml", "Escape") and |
| 20 | + (inp.isParameter(1) and outp.isParameter(0)) |
| 21 | + or |
| 22 | + // signature: func EscapeText(w io.Writer, s []byte) error |
| 23 | + hasQualifiedName("encoding/xml", "EscapeText") and |
| 24 | + (inp.isParameter(1) and outp.isParameter(0)) |
| 25 | + or |
| 26 | + // signature: func Marshal(v interface{}) ([]byte, error) |
| 27 | + hasQualifiedName("encoding/xml", "Marshal") and |
| 28 | + (inp.isParameter(0) and outp.isResult(0)) |
| 29 | + or |
| 30 | + // signature: func MarshalIndent(v interface{}, prefix string, indent string) ([]byte, error) |
| 31 | + hasQualifiedName("encoding/xml", "MarshalIndent") and |
| 32 | + (inp.isParameter(_) and outp.isResult(0)) |
| 33 | + or |
| 34 | + // signature: func NewDecoder(r io.Reader) *Decoder |
| 35 | + hasQualifiedName("encoding/xml", "NewDecoder") and |
| 36 | + (inp.isParameter(0) and outp.isResult()) |
| 37 | + or |
| 38 | + // signature: func NewEncoder(w io.Writer) *Encoder |
| 39 | + hasQualifiedName("encoding/xml", "NewEncoder") and |
| 40 | + (inp.isResult() and outp.isParameter(0)) |
| 41 | + or |
| 42 | + // signature: func NewTokenDecoder(t TokenReader) *Decoder |
| 43 | + hasQualifiedName("encoding/xml", "NewTokenDecoder") and |
| 44 | + (inp.isParameter(0) and outp.isResult()) |
| 45 | + or |
| 46 | + // signature: func Unmarshal(data []byte, v interface{}) error |
| 47 | + hasQualifiedName("encoding/xml", "Unmarshal") and |
| 48 | + (inp.isParameter(0) and outp.isParameter(1)) |
| 49 | + } |
| 50 | + |
| 51 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 52 | + input = inp and output = outp |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + private class MethodModels extends TaintTracking::FunctionModel, Method { |
| 57 | + FunctionInput inp; |
| 58 | + FunctionOutput outp; |
| 59 | + |
| 60 | + MethodModels() { |
| 61 | + // signature: func (CharData).Copy() CharData |
| 62 | + this.hasQualifiedName("encoding/xml", "CharData", "Copy") and |
| 63 | + (inp.isReceiver() and outp.isResult()) |
| 64 | + or |
| 65 | + // signature: func (Comment).Copy() Comment |
| 66 | + this.hasQualifiedName("encoding/xml", "Comment", "Copy") and |
| 67 | + (inp.isReceiver() and outp.isResult()) |
| 68 | + or |
| 69 | + // signature: func (*Decoder).Decode(v interface{}) error |
| 70 | + this.hasQualifiedName("encoding/xml", "Decoder", "Decode") and |
| 71 | + (inp.isReceiver() and outp.isParameter(0)) |
| 72 | + or |
| 73 | + // signature: func (*Decoder).DecodeElement(v interface{}, start *StartElement) error |
| 74 | + this.hasQualifiedName("encoding/xml", "Decoder", "DecodeElement") and |
| 75 | + (inp.isReceiver() and outp.isParameter(0)) |
| 76 | + or |
| 77 | + // signature: func (*Decoder).RawToken() (Token, error) |
| 78 | + this.hasQualifiedName("encoding/xml", "Decoder", "RawToken") and |
| 79 | + (inp.isReceiver() and outp.isResult(0)) |
| 80 | + or |
| 81 | + // signature: func (*Decoder).Token() (Token, error) |
| 82 | + this.hasQualifiedName("encoding/xml", "Decoder", "Token") and |
| 83 | + (inp.isReceiver() and outp.isResult(0)) |
| 84 | + or |
| 85 | + // signature: func (Directive).Copy() Directive |
| 86 | + this.hasQualifiedName("encoding/xml", "Directive", "Copy") and |
| 87 | + (inp.isReceiver() and outp.isResult()) |
| 88 | + or |
| 89 | + // signature: func (*Encoder).Encode(v interface{}) error |
| 90 | + this.hasQualifiedName("encoding/xml", "Encoder", "Encode") and |
| 91 | + (inp.isParameter(0) and outp.isReceiver()) |
| 92 | + or |
| 93 | + // signature: func (*Encoder).EncodeElement(v interface{}, start StartElement) error |
| 94 | + this.hasQualifiedName("encoding/xml", "Encoder", "EncodeElement") and |
| 95 | + (inp.isParameter(0) and outp.isReceiver()) |
| 96 | + or |
| 97 | + // signature: func (*Encoder).EncodeToken(t Token) error |
| 98 | + this.hasQualifiedName("encoding/xml", "Encoder", "EncodeToken") and |
| 99 | + (inp.isParameter(0) and outp.isReceiver()) |
| 100 | + or |
| 101 | + // signature: func (*Encoder).Indent(prefix string, indent string) |
| 102 | + this.hasQualifiedName("encoding/xml", "Encoder", "Indent") and |
| 103 | + (inp.isParameter(_) and outp.isReceiver()) |
| 104 | + or |
| 105 | + // signature: func (ProcInst).Copy() ProcInst |
| 106 | + this.hasQualifiedName("encoding/xml", "ProcInst", "Copy") and |
| 107 | + (inp.isReceiver() and outp.isResult()) |
| 108 | + or |
| 109 | + // signature: func (StartElement).Copy() StartElement |
| 110 | + this.hasQualifiedName("encoding/xml", "StartElement", "Copy") and |
| 111 | + (inp.isReceiver() and outp.isResult()) |
| 112 | + or |
| 113 | + // signature: func (Marshaler).MarshalXML(e *Encoder, start StartElement) error |
| 114 | + this.implements("encoding/xml", "Marshaler", "MarshalXML") and |
| 115 | + (inp.isReceiver() and outp.isParameter(0)) |
| 116 | + or |
| 117 | + // signature: func (TokenReader).Token() (Token, error) |
| 118 | + this.implements("encoding/xml", "TokenReader", "Token") and |
| 119 | + (inp.isReceiver() and outp.isResult(0)) |
| 120 | + or |
| 121 | + // signature: func (Unmarshaler).UnmarshalXML(d *Decoder, start StartElement) error |
| 122 | + this.implements("encoding/xml", "Unmarshaler", "UnmarshalXML") and |
| 123 | + (inp.isParameter(0) and outp.isReceiver()) |
| 124 | + } |
| 125 | + |
| 126 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 127 | + input = inp and output = outp |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments