mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
C++: rename and add description to hasFlowSource
This commit is contained in:
@@ -13,7 +13,8 @@ class Fread extends AliasFunction, RemoteFlowFunction {
|
||||
|
||||
override predicate parameterIsAlwaysReturned(int n) { none() }
|
||||
|
||||
override predicate hasFlowSource(FunctionOutput output) {
|
||||
output.isParameterDeref(0)
|
||||
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
|
||||
output.isParameterDeref(0) and
|
||||
description = "String read by " + this.getName()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunction, Alias
|
||||
mustWrite = true
|
||||
}
|
||||
|
||||
override predicate hasFlowSource(FunctionOutput output) {
|
||||
output.isParameterDeref(0)
|
||||
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
|
||||
output.isParameterDeref(0) and
|
||||
description = "String read by " + this.getName()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,8 @@ import semmle.code.cpp.models.Models
|
||||
* A library function which returns data read from a network connection.
|
||||
*/
|
||||
abstract class RemoteFlowFunction extends Function {
|
||||
abstract predicate hasFlowSource(FunctionOutput output);
|
||||
/**
|
||||
* Holds if remote data described by `description` flows from `output` of a call to this function.
|
||||
*/
|
||||
abstract predicate hasRemoteFlowSource(FunctionOutput output, string description);
|
||||
}
|
||||
|
||||
@@ -9,26 +9,38 @@ import semmle.code.cpp.models.interfaces.FlowSource
|
||||
|
||||
/** A data flow source of remote user input. */
|
||||
abstract class RemoteFlowSource extends DataFlow::Node {
|
||||
/** Gets a string that describes the type of this remote flow source. */
|
||||
abstract string getSourceType();
|
||||
}
|
||||
|
||||
private class TaintedReturnSource extends RemoteFlowSource {
|
||||
string sourceType;
|
||||
TaintedReturnSource() {
|
||||
exists(RemoteFlowFunction func, CallInstruction instr, FunctionOutput output |
|
||||
asInstruction() = instr and
|
||||
instr.getStaticCallTarget() = func and
|
||||
func.hasFlowSource(output) and
|
||||
func.hasRemoteFlowSource(output, sourceType) and
|
||||
output.isReturnValue()
|
||||
)
|
||||
}
|
||||
|
||||
override string getSourceType() {
|
||||
result = sourceType
|
||||
}
|
||||
}
|
||||
|
||||
private class TaintedParameterSource extends RemoteFlowSource {
|
||||
string sourceType;
|
||||
TaintedParameterSource() {
|
||||
exists(RemoteFlowFunction func, WriteSideEffectInstruction instr, FunctionOutput output |
|
||||
asInstruction() = instr and
|
||||
instr.getPrimaryInstruction().(CallInstruction).getStaticCallTarget() = func and
|
||||
func.hasFlowSource(output) and
|
||||
func.hasRemoteFlowSource(output, sourceType) and
|
||||
output.isParameterDeref(instr.getIndex())
|
||||
)
|
||||
}
|
||||
|
||||
override string getSourceType() {
|
||||
result = sourceType
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user