Java: Replace incorrect usage of Literal.getLiteral()

This commit is contained in:
Marcono1234
2021-09-04 21:09:36 +02:00
committed by Chris Smowton
parent 1c1c46591e
commit 58d2d5d14e
10 changed files with 47 additions and 51 deletions

View File

@@ -17,14 +17,14 @@ import DataFlow
import PathGraph
private class ShortStringLiteral extends StringLiteral {
ShortStringLiteral() { getLiteral().length() < 100 }
ShortStringLiteral() { getRepresentedString().length() < 100 }
}
class BrokenAlgoLiteral extends ShortStringLiteral {
BrokenAlgoLiteral() {
getValue().regexpMatch(getInsecureAlgorithmRegex()) and
getRepresentedString().regexpMatch(getInsecureAlgorithmRegex()) and
// Exclude German and French sentences.
not getValue().regexpMatch(".*\\p{IsLowercase} des \\p{IsLetter}.*")
not getRepresentedString().regexpMatch(".*\\p{IsLowercase} des \\p{IsLetter}.*")
}
}
@@ -48,4 +48,4 @@ where
source.getNode().asExpr() = s and
conf.hasFlowPath(source, sink)
select c, source, sink, "Cryptographic algorithm $@ is weak and should not be used.", s,
s.getLiteral()
s.getRepresentedString()

View File

@@ -18,14 +18,14 @@ import semmle.code.java.dispatch.VirtualDispatch
import PathGraph
private class ShortStringLiteral extends StringLiteral {
ShortStringLiteral() { getLiteral().length() < 100 }
ShortStringLiteral() { getRepresentedString().length() < 100 }
}
class InsecureAlgoLiteral extends ShortStringLiteral {
InsecureAlgoLiteral() {
// Algorithm identifiers should be at least two characters.
getValue().length() > 1 and
exists(string s | s = getLiteral() |
getRepresentedString().length() > 1 and
exists(string s | s = getRepresentedString() |
not s.regexpMatch(getSecureAlgorithmRegex()) and
// Exclude results covered by another query.
not s.regexpMatch(getInsecureAlgorithmRegex())
@@ -72,4 +72,4 @@ where
conf.hasFlowPath(source, sink)
select c, source, sink,
"Cryptographic algorithm $@ may not be secure, consider using a different algorithm.", s,
s.getLiteral()
s.getRepresentedString()