add all remaining explicit this

This commit is contained in:
Erik Krogh Kristensen
2021-11-26 13:50:10 +01:00
parent 00ee34c0a0
commit 6ff8d4de5c
104 changed files with 479 additions and 451 deletions

View File

@@ -103,11 +103,11 @@ class DiscardedMethodCall extends MethodCall {
string query() {
exists(Method m |
m = getTarget() and
m = this.getTarget() and
not whitelist(m) and
// Do not alert on "void wrapper methods", i.e., methods that are inserted
// to deliberately ignore the returned value
not getEnclosingCallable().getStatementBody().getNumberOfStmts() = 1
not this.getEnclosingCallable().getStatementBody().getNumberOfStmts() = 1
|
important(m) and result = "should always be checked"
or

View File

@@ -4,35 +4,35 @@ import csharp
private class WaitCall extends MethodCall {
WaitCall() {
getTarget().hasName("Wait") and
getTarget().getDeclaringType().hasQualifiedName("System.Threading.Monitor")
this.getTarget().hasName("Wait") and
this.getTarget().getDeclaringType().hasQualifiedName("System.Threading.Monitor")
}
Expr getExpr() { result = getArgument(0) }
Expr getExpr() { result = this.getArgument(0) }
}
/** An expression statement containing a `Wait` call. */
class WaitStmt extends ExprStmt {
WaitStmt() { getExpr() instanceof WaitCall }
WaitStmt() { this.getExpr() instanceof WaitCall }
/** Gets the expression that this wait call is waiting on. */
Expr getLock() { result = getExpr().(WaitCall).getExpr() }
Expr getLock() { result = this.getExpr().(WaitCall).getExpr() }
/** Gets the variable that this wait call is waiting on, if any. */
Variable getWaitVariable() { result.getAnAccess() = getLock() }
Variable getWaitVariable() { result.getAnAccess() = this.getLock() }
/** Holds if this wait call waits on `this`. */
predicate isWaitThis() { getLock() instanceof ThisAccess }
predicate isWaitThis() { this.getLock() instanceof ThisAccess }
/** Gets the type that this wait call waits on, if any. */
Type getWaitTypeObject() { result = getLock().(TypeofExpr).getTypeAccess().getTarget() }
Type getWaitTypeObject() { result = this.getLock().(TypeofExpr).getTypeAccess().getTarget() }
}
private class SynchronizedMethodAttribute extends Attribute {
SynchronizedMethodAttribute() {
getType().hasQualifiedName("System.Runtime.CompilerServices.MethodImplAttribute") and
this.getType().hasQualifiedName("System.Runtime.CompilerServices.MethodImplAttribute") and
exists(MemberConstantAccess a, MemberConstant mc |
a = getArgument(0) and
a = this.getArgument(0) and
a.getTarget() = mc and
mc.hasName("Synchronized") and
mc.getDeclaringType().hasQualifiedName("System.Runtime.CompilerServices.MethodImplOptions")
@@ -42,13 +42,13 @@ private class SynchronizedMethodAttribute extends Attribute {
/** A method with attribute `[MethodImpl(MethodImplOptions.Synchronized)]`. */
private class SynchronizedMethod extends Method {
SynchronizedMethod() { getAnAttribute() instanceof SynchronizedMethodAttribute }
SynchronizedMethod() { this.getAnAttribute() instanceof SynchronizedMethodAttribute }
/** Holds if this method locks `this`. */
predicate isLockThis() { not isStatic() }
predicate isLockThis() { not this.isStatic() }
/** Gets the type that is locked by this method, if any. */
Type getLockTypeObject() { isStatic() and result = getDeclaringType() }
Type getLockTypeObject() { this.isStatic() and result = this.getDeclaringType() }
}
/** A block that is locked by a `lock` statement. */
@@ -68,7 +68,7 @@ abstract class LockedBlock extends BlockStmt {
// delegates and lambdas
result.getParent() = this
or
exists(Stmt mid | mid = getALockedStmt() and result.getParent() = mid)
exists(Stmt mid | mid = this.getALockedStmt() and result.getParent() = mid)
}
}

View File

@@ -59,66 +59,66 @@ predicate isDocumentationNeeded(Modifiable decl) {
/** An XML comment containing a `<returns>` tag. */
class ReturnsXmlComment extends XmlComment {
ReturnsXmlComment() { getOpenTag(_) = "returns" }
ReturnsXmlComment() { this.getOpenTag(_) = "returns" }
/** Holds if the element in this comment has a body at offset `offset`. */
predicate hasBody(int offset) { hasBody("returns", offset) }
predicate hasBody(int offset) { this.hasBody("returns", offset) }
/** Holds if the element in this comment is an opening tag at offset `offset`. */
predicate isOpenTag(int offset) { "returns" = getOpenTag(offset) }
predicate isOpenTag(int offset) { "returns" = this.getOpenTag(offset) }
/** Holds if the element in this comment is an empty tag at offset `offset`. */
predicate isEmptyTag(int offset) { "returns" = getEmptyTag(offset) }
predicate isEmptyTag(int offset) { "returns" = this.getEmptyTag(offset) }
}
/** An XML comment containing an `<exception>` tag. */
class ExceptionXmlComment extends XmlComment {
ExceptionXmlComment() { getOpenTag(_) = "exception" }
ExceptionXmlComment() { this.getOpenTag(_) = "exception" }
/** Gets a `cref` attribute at offset `offset`, if any. */
string getCref(int offset) { result = getAttribute("exception", "cref", offset) }
string getCref(int offset) { result = this.getAttribute("exception", "cref", offset) }
/** Holds if the element in this comment has a body at offset `offset`. */
predicate hasBody(int offset) { hasBody("exception", offset) }
predicate hasBody(int offset) { this.hasBody("exception", offset) }
}
/** An XML comment containing a `<param>` tag. */
class ParamXmlComment extends XmlComment {
ParamXmlComment() { getOpenTag(_) = "param" }
ParamXmlComment() { this.getOpenTag(_) = "param" }
/** Gets the name of this parameter at offset `offset`. */
string getName(int offset) { getAttribute("param", "name", offset) = result }
string getName(int offset) { this.getAttribute("param", "name", offset) = result }
/** Holds if the element in this comment has a body at offset `offset`. */
predicate hasBody(int offset) { hasBody("param", offset) }
predicate hasBody(int offset) { this.hasBody("param", offset) }
}
/** An XML comment containing a `<typeparam>` tag. */
class TypeparamXmlComment extends XmlComment {
TypeparamXmlComment() { getOpenTag(_) = "typeparam" }
TypeparamXmlComment() { this.getOpenTag(_) = "typeparam" }
/** Gets the `name` attribute of this element at offset `offset`. */
string getName(int offset) { getAttribute("typeparam", "name", offset) = result }
string getName(int offset) { this.getAttribute("typeparam", "name", offset) = result }
/** Holds if the element in this comment has a body at offset `offset`. */
predicate hasBody(int offset) { hasBody("typeparam", offset) }
predicate hasBody(int offset) { this.hasBody("typeparam", offset) }
}
/** An XML comment containing a `<summary>` tag. */
class SummaryXmlComment extends XmlComment {
SummaryXmlComment() { getOpenTag(_) = "summary" }
SummaryXmlComment() { this.getOpenTag(_) = "summary" }
/** Holds if the element in this comment has a body at offset `offset`. */
predicate hasBody(int offset) { hasBody("summary", offset) }
predicate hasBody(int offset) { this.hasBody("summary", offset) }
/** Holds if the element in this comment has an open tag at offset `offset`. */
predicate isOpenTag(int offset) { "summary" = getOpenTag(offset) }
predicate isOpenTag(int offset) { "summary" = this.getOpenTag(offset) }
/** Holds if the element in this comment is empty at offset `offset`. */
predicate isEmptyTag(int offset) { "summary" = getEmptyTag(offset) }
predicate isEmptyTag(int offset) { "summary" = this.getEmptyTag(offset) }
}
/** An XML comment containing an `<inheritdoc>` tag. */
class InheritDocXmlComment extends XmlComment {
InheritDocXmlComment() { getOpenTag(_) = "inheritdoc" }
InheritDocXmlComment() { this.getOpenTag(_) = "inheritdoc" }
}

View File

@@ -62,7 +62,7 @@ class NestedForLoopSameVariable extends ForStmt {
private predicate haveSameCondition() {
exists(NestedForConditions config |
config.same(getInnerForStmt().getCondition(), getOuterForStmt().getCondition())
config.same(this.getInnerForStmt().getCondition(), this.getOuterForStmt().getCondition())
)
}
@@ -74,7 +74,7 @@ class NestedForLoopSameVariable extends ForStmt {
/** Holds if the logic is deemed to be correct in limited circumstances. */
predicate isSafe() {
haveSameUpdate() and haveSameCondition() and not exists(getAnUnguardedAccess())
this.haveSameUpdate() and this.haveSameCondition() and not exists(this.getAnUnguardedAccess())
}
/** Gets the result element. */
@@ -95,20 +95,20 @@ class NestedForLoopSameVariable extends ForStmt {
/** Finds elements inside the outer loop that are no longer guarded by the loop invariant. */
private ControlFlow::Node getAnUnguardedNode() {
hasChild(getOuterForStmt().getBody(), result.getElement()) and
hasChild(this.getOuterForStmt().getBody(), result.getElement()) and
(
result =
this.getCondition().(ControlFlowElement).getAControlFlowExitNode().getAFalseSuccessor()
or
exists(ControlFlow::Node mid | mid = getAnUnguardedNode() |
exists(ControlFlow::Node mid | mid = this.getAnUnguardedNode() |
mid.getASuccessor() = result and
not exists(getAComparisonTest(result.getElement()))
not exists(this.getAComparisonTest(result.getElement()))
)
)
}
private VariableAccess getAnUnguardedAccess() {
result = getAnUnguardedNode().getElement() and
result = this.getAnUnguardedNode().getElement() and
result.getTarget() = iteration
}
}

View File

@@ -34,10 +34,10 @@ class SystemWebSessionStateHttpSessionStateClass extends Class {
}
/** Gets the `Abandon` method. */
Method getAbandonMethod() { result = getAMethod("Abandon") }
Method getAbandonMethod() { result = this.getAMethod("Abandon") }
/** Gets the `Clear` method. */
Method getClearMethod() { result = getAMethod("Clear") }
Method getClearMethod() { result = this.getAMethod("Clear") }
}
/** A method that directly or indirectly clears `HttpSessionState`. */

View File

@@ -47,7 +47,7 @@ abstract class RequiresEncodingConfiguration extends TaintTracking2::Configurati
* to be encoded.
*/
predicate hasWrongEncoding(PathNode encodedValue, PathNode sink, string kind) {
hasFlowPath(encodedValue, sink) and
this.hasFlowPath(encodedValue, sink) and
kind = this.getKind()
}

View File

@@ -83,7 +83,9 @@ private class MethodUse extends Use, QualifiableExpr {
)
}
override Method getDefinition() { result = getQualifiedDeclaration().getUnboundDeclaration() }
override Method getDefinition() {
result = this.getQualifiedDeclaration().getUnboundDeclaration()
}
override string getUseType() { result = "M" }

View File

@@ -8,7 +8,7 @@ class ArrayInitWithMod extends ArrayInitializer {
predicate isInitialized(int entry) { entry in [0 .. this.getNumberOfElements() - 1] }
predicate isValueInitialized(int elementIndex) {
isInitialized(elementIndex) and
this.isInitialized(elementIndex) and
not exists(this.getElement(elementIndex))
}
}

View File

@@ -307,7 +307,7 @@ class NonPhiMemoryOperand extends NonPhiOperand, MemoryOperand, TNonPhiMemoryOpe
final override string toString() { result = tag.toString() }
final override Instruction getAnyDef() {
result = unique(Instruction defInstr | hasDefinition(defInstr, _))
result = unique(Instruction defInstr | this.hasDefinition(defInstr, _))
}
final override Overlap getDefinitionOverlap() { this.hasDefinition(_, result) }

View File

@@ -307,7 +307,7 @@ class NonPhiMemoryOperand extends NonPhiOperand, MemoryOperand, TNonPhiMemoryOpe
final override string toString() { result = tag.toString() }
final override Instruction getAnyDef() {
result = unique(Instruction defInstr | hasDefinition(defInstr, _))
result = unique(Instruction defInstr | this.hasDefinition(defInstr, _))
}
final override Overlap getDefinitionOverlap() { this.hasDefinition(_, result) }

View File

@@ -173,27 +173,29 @@ private class GuardConditionFromBinaryLogicalOperator extends GuardCondition {
private class GuardConditionFromShortCircuitNot extends GuardCondition, LogicalNotExpr {
GuardConditionFromShortCircuitNot() {
not exists(Instruction inst | this = inst.getAST()) and
exists(IRGuardCondition ir | getOperand() = ir.getAST())
exists(IRGuardCondition ir | this.getOperand() = ir.getAST())
}
override predicate controls(BasicBlock controlled, boolean testIsTrue) {
getOperand().(GuardCondition).controls(controlled, testIsTrue.booleanNot())
this.getOperand().(GuardCondition).controls(controlled, testIsTrue.booleanNot())
}
override predicate comparesLt(Expr left, Expr right, int k, boolean isLessThan, boolean testIsTrue) {
getOperand().(GuardCondition).comparesLt(left, right, k, isLessThan, testIsTrue.booleanNot())
this.getOperand()
.(GuardCondition)
.comparesLt(left, right, k, isLessThan, testIsTrue.booleanNot())
}
override predicate ensuresLt(Expr left, Expr right, int k, BasicBlock block, boolean isLessThan) {
getOperand().(GuardCondition).ensuresLt(left, right, k, block, isLessThan.booleanNot())
this.getOperand().(GuardCondition).ensuresLt(left, right, k, block, isLessThan.booleanNot())
}
override predicate comparesEq(Expr left, Expr right, int k, boolean areEqual, boolean testIsTrue) {
getOperand().(GuardCondition).comparesEq(left, right, k, areEqual, testIsTrue.booleanNot())
this.getOperand().(GuardCondition).comparesEq(left, right, k, areEqual, testIsTrue.booleanNot())
}
override predicate ensuresEq(Expr left, Expr right, int k, BasicBlock block, boolean areEqual) {
getOperand().(GuardCondition).ensuresEq(left, right, k, block, areEqual.booleanNot())
this.getOperand().(GuardCondition).ensuresEq(left, right, k, block, areEqual.booleanNot())
}
}

View File

@@ -2,7 +2,7 @@ import semmle.code.csharp.Conversion
// Avoid printing conversions for type parameters from library
class LibraryTypeParameter extends TypeParameter {
LibraryTypeParameter() { fromLibrary() }
LibraryTypeParameter() { this.fromLibrary() }
override string toString() { none() }
}

View File

@@ -2,7 +2,7 @@ import semmle.code.csharp.Conversion
// Avoid printing conversions for type parameters from library
class LibraryTypeParameter extends TypeParameter {
LibraryTypeParameter() { fromLibrary() }
LibraryTypeParameter() { this.fromLibrary() }
override string toString() { none() }
}