diff --git a/ql/src/Security/CWE-601/BadRedirectCheck.ql b/ql/src/Security/CWE-601/BadRedirectCheck.ql index 1e20dfbd5f7..d42605bb86b 100644 --- a/ql/src/Security/CWE-601/BadRedirectCheck.ql +++ b/ql/src/Security/CWE-601/BadRedirectCheck.ql @@ -18,8 +18,6 @@ StringOps::HasPrefix checkForLeadingSlash(SsaWithFields v) { result.getBaseString() = v.getAUse() and result.getSubstring() = substr | substr.getStringValue() = "/" - or - substr.getIntValue() = 47 // ASCII value for '/' ) } @@ -31,7 +29,7 @@ DataFlow::Node checkForSecondSlash(SsaWithFields v) { exists(DataFlow::EqualityTestNode eq, DataFlow::Node slash, DataFlow::ElementReadNode er | result = eq | - slash.getIntValue() = 47 and // ASCII value for '/' + slash.getStringValue() = "/" and er.getBase() = v.getAUse() and er.getIndex().getIntValue() = 1 and eq.eq(_, er, slash) @@ -46,7 +44,7 @@ DataFlow::Node checkForSecondBackslash(SsaWithFields v) { exists(DataFlow::EqualityTestNode eq, DataFlow::Node slash, DataFlow::ElementReadNode er | result = eq | - slash.getIntValue() = 92 and // ASCII value for '\' + slash.getStringValue() = "\\" and er.getBase() = v.getAUse() and er.getIndex().getIntValue() = 1 and eq.eq(_, er, slash) diff --git a/ql/src/semmle/go/Expr.qll b/ql/src/semmle/go/Expr.qll index 857a7e487ef..b264d21d0db 100644 --- a/ql/src/semmle/go/Expr.qll +++ b/ql/src/semmle/go/Expr.qll @@ -220,7 +220,11 @@ class ImagLit extends @imaglit, BasicLit { } /** * A character literal. */ -class CharLit extends @charlit, BasicLit { } +class CharLit extends @charlit, BasicLit { + // use the constant value of the literal as the string value, as the value we get from the + // compiler is an integer, meaning we would not otherwise have a string value for rune literals + override string getStringValue() { result = this.getValue() } +} /** * A string literal. diff --git a/ql/test/library-tests/semmle/go/Expr/ConstantValues.expected b/ql/test/library-tests/semmle/go/Expr/ConstantValues.expected index 6960266950d..0526762289d 100644 --- a/ql/test/library-tests/semmle/go/Expr/ConstantValues.expected +++ b/ql/test/library-tests/semmle/go/Expr/ConstantValues.expected @@ -18,7 +18,9 @@ | consts.go:32:29:32:36 | ...-... | 2.3 - 9.7i | (2.3 + -9.7i), (2589569785738035/1125899906842624 + -2730307274093363/281474976710656i) | | consts.go:32:33:32:36 | 9.7i | 9.7i | (0 + 9.7i), (0 + 97/10i) | | consts.go:33:3:33:5 | 'a' | 'a' | 97, 97 | +| consts.go:33:3:33:5 | 'a' | 'a' | a | | consts.go:33:8:33:13 | '\\x8b' | '\\x8b' | 139, 139 | +| consts.go:33:8:33:13 | '\\x8b' | '\\x8b' | \ufffd | | consts.go:33:16:33:38 | 3.141592653589793238462 | 3.141592653589793238462 | 3.141593, 1570796326794896619231/500000000000000000000 | | consts.go:33:16:33:40 | ...*... | 3.141592653589793238462 * 8 | 25.132741, 884279719003555/35184372088832 | | consts.go:33:40:33:40 | 8 | 8 | 8, 8 |