|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `strconv` package. |
| 3 | + */ |
| 4 | + |
| 5 | +import go |
| 6 | + |
| 7 | +/** Provides models of commonly used functions in the `strconv` package. */ |
| 8 | +module Strconv { |
| 9 | + /** The `Atoi` function. */ |
| 10 | + class Atoi extends IntegerParser::Range { |
| 11 | + Atoi() { this.hasQualifiedName("strconv", "Atoi") } |
| 12 | + |
| 13 | + override int getTargetBitSize() { result = 0 } |
| 14 | + } |
| 15 | + |
| 16 | + /** The `ParseInt` function. */ |
| 17 | + class ParseInt extends IntegerParser::Range { |
| 18 | + ParseInt() { this.hasQualifiedName("strconv", "ParseInt") } |
| 19 | + |
| 20 | + override FunctionInput getTargetBitSizeInput() { result.isParameter(2) } |
| 21 | + } |
| 22 | + |
| 23 | + /** The `ParseUint` function. */ |
| 24 | + class ParseUint extends IntegerParser::Range { |
| 25 | + ParseUint() { this.hasQualifiedName("strconv", "ParseUint") } |
| 26 | + |
| 27 | + override FunctionInput getTargetBitSizeInput() { result.isParameter(2) } |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * The `IntSize` constant, that gives the size in bits of an `int` or |
| 32 | + * `uint` value on the current architecture (32 or 64). |
| 33 | + */ |
| 34 | + class IntSize extends DeclaredConstant { |
| 35 | + IntSize() { this.hasQualifiedName("strconv", "IntSize") } |
| 36 | + } |
| 37 | + |
| 38 | + private class FunctionModels extends TaintTracking::FunctionModel { |
| 39 | + FunctionInput inp; |
| 40 | + FunctionOutput outp; |
| 41 | + |
| 42 | + FunctionModels() { |
| 43 | + // signature: func AppendQuote(dst []byte, s string) []byte |
| 44 | + hasQualifiedName("strconv", "AppendQuote") and |
| 45 | + ( |
| 46 | + inp.isParameter(_) and outp.isResult() |
| 47 | + or |
| 48 | + inp.isParameter(1) and |
| 49 | + (outp.isParameter(0) or outp.isResult()) |
| 50 | + ) |
| 51 | + or |
| 52 | + // signature: func AppendQuoteToASCII(dst []byte, s string) []byte |
| 53 | + hasQualifiedName("strconv", "AppendQuoteToASCII") and |
| 54 | + ( |
| 55 | + inp.isParameter(_) and outp.isResult() |
| 56 | + or |
| 57 | + inp.isParameter(1) and |
| 58 | + (outp.isParameter(0) or outp.isResult()) |
| 59 | + ) |
| 60 | + or |
| 61 | + // signature: func AppendQuoteToGraphic(dst []byte, s string) []byte |
| 62 | + hasQualifiedName("strconv", "AppendQuoteToGraphic") and |
| 63 | + ( |
| 64 | + inp.isParameter(_) and outp.isResult() |
| 65 | + or |
| 66 | + inp.isParameter(1) and |
| 67 | + (outp.isParameter(0) or outp.isResult()) |
| 68 | + ) |
| 69 | + or |
| 70 | + // signature: func Quote(s string) string |
| 71 | + hasQualifiedName("strconv", "Quote") and |
| 72 | + (inp.isParameter(0) and outp.isResult()) |
| 73 | + or |
| 74 | + // signature: func QuoteRune(r rune) string |
| 75 | + hasQualifiedName("strconv", "QuoteRune") and |
| 76 | + (inp.isParameter(0) and outp.isResult()) |
| 77 | + or |
| 78 | + // signature: func QuoteRuneToASCII(r rune) string |
| 79 | + hasQualifiedName("strconv", "QuoteRuneToASCII") and |
| 80 | + (inp.isParameter(0) and outp.isResult()) |
| 81 | + or |
| 82 | + // signature: func QuoteRuneToGraphic(r rune) string |
| 83 | + hasQualifiedName("strconv", "QuoteRuneToGraphic") and |
| 84 | + (inp.isParameter(0) and outp.isResult()) |
| 85 | + or |
| 86 | + // signature: func QuoteToASCII(s string) string |
| 87 | + hasQualifiedName("strconv", "QuoteToASCII") and |
| 88 | + (inp.isParameter(0) and outp.isResult()) |
| 89 | + or |
| 90 | + // signature: func QuoteToGraphic(s string) string |
| 91 | + hasQualifiedName("strconv", "QuoteToGraphic") and |
| 92 | + (inp.isParameter(0) and outp.isResult()) |
| 93 | + or |
| 94 | + // signature: func Unquote(s string) (string, error) |
| 95 | + hasQualifiedName("strconv", "Unquote") and |
| 96 | + (inp.isParameter(0) and outp.isResult(0)) |
| 97 | + or |
| 98 | + // signature: func UnquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, err error) |
| 99 | + hasQualifiedName("strconv", "UnquoteChar") and |
| 100 | + (inp.isParameter(0) and outp.isResult([0, 2])) |
| 101 | + } |
| 102 | + |
| 103 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 104 | + input = inp and output = outp |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments