mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Java: Add StringBuildingType
This commit is contained in:
@@ -13,12 +13,7 @@
|
||||
import java
|
||||
|
||||
class NewStringBufferOrBuilder extends ClassInstanceExpr {
|
||||
NewStringBufferOrBuilder() {
|
||||
exists(Class c | c = this.getConstructedType() |
|
||||
c.hasQualifiedName("java.lang", "StringBuilder") or
|
||||
c.hasQualifiedName("java.lang", "StringBuffer")
|
||||
)
|
||||
}
|
||||
NewStringBufferOrBuilder() { getConstructedType() instanceof StringBuildingType }
|
||||
|
||||
string getName() { result = this.getConstructedType().getName() }
|
||||
}
|
||||
|
||||
@@ -44,8 +44,7 @@ predicate objectToString(MethodAccess ma) {
|
||||
class StringContainer extends RefType {
|
||||
StringContainer() {
|
||||
this instanceof TypeString or
|
||||
this.hasQualifiedName("java.lang", "StringBuilder") or
|
||||
this.hasQualifiedName("java.lang", "StringBuffer") or
|
||||
this instanceof StringBuildingType or
|
||||
this.hasQualifiedName("java.util", "StringTokenizer") or
|
||||
this.(Array).getComponentType() instanceof StringContainer
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ class TypeStringBuilder extends Class {
|
||||
TypeStringBuilder() { this.hasQualifiedName("java.lang", "StringBuilder") }
|
||||
}
|
||||
|
||||
/** Class `java.lang.StringBuffer` or `java.lang.StringBuilder`. */
|
||||
class StringBuildingType extends Class {
|
||||
StringBuildingType() { this instanceof TypeStringBuffer or this instanceof TypeStringBuilder }
|
||||
}
|
||||
|
||||
/** The class `java.lang.System`. */
|
||||
class TypeSystem extends Class {
|
||||
TypeSystem() { this.hasQualifiedName("java.lang", "System") }
|
||||
|
||||
@@ -210,10 +210,7 @@ private predicate printMethod(Method m, int i) {
|
||||
(t.hasQualifiedName("java.io", "PrintWriter") or t.hasQualifiedName("java.io", "PrintStream")) and
|
||||
(m.hasName("print") or m.hasName("println"))
|
||||
or
|
||||
(
|
||||
t.hasQualifiedName("java.lang", "StringBuilder") or
|
||||
t.hasQualifiedName("java.lang", "StringBuffer")
|
||||
) and
|
||||
t instanceof StringBuildingType and
|
||||
(m.hasName("append") or m.hasName("insert"))
|
||||
or
|
||||
t instanceof TypeString and m.hasName("valueOf")
|
||||
|
||||
@@ -152,8 +152,7 @@ private class NumberTaintPreservingCallable extends TaintPreservingCallable {
|
||||
|
||||
/** Holds for the types `StringBuilder`, `StringBuffer`, and `StringWriter`. */
|
||||
private predicate stringBuilderType(RefType t) {
|
||||
t.hasQualifiedName("java.lang", "StringBuilder") or
|
||||
t.hasQualifiedName("java.lang", "StringBuffer") or
|
||||
t instanceof StringBuildingType or
|
||||
t.hasQualifiedName("java.io", "StringWriter")
|
||||
}
|
||||
|
||||
|
||||
@@ -552,10 +552,7 @@ module StringBuilderVarModule {
|
||||
* build up a query using string concatenation.
|
||||
*/
|
||||
class StringBuilderVar extends LocalVariableDecl {
|
||||
StringBuilderVar() {
|
||||
this.getType() instanceof TypeStringBuilder or
|
||||
this.getType() instanceof TypeStringBuffer
|
||||
}
|
||||
StringBuilderVar() { getType() instanceof StringBuildingType }
|
||||
|
||||
/**
|
||||
* Gets a call that adds something to this string builder, from the argument at the given index.
|
||||
|
||||
Reference in New Issue
Block a user