зеркало из https://github.com/github/codeql.git
C++: Rewrite `cpp/path-injection` to not use `DefaultTaintTracking`
This commit is contained in:
Родитель
f3dca95958
Коммит
63334764d7
|
@ -17,8 +17,9 @@
|
||||||
import cpp
|
import cpp
|
||||||
import semmle.code.cpp.security.FunctionWithWrappers
|
import semmle.code.cpp.security.FunctionWithWrappers
|
||||||
import semmle.code.cpp.security.Security
|
import semmle.code.cpp.security.Security
|
||||||
import semmle.code.cpp.security.TaintTracking
|
import semmle.code.cpp.ir.IR
|
||||||
import TaintedWithPath
|
import semmle.code.cpp.ir.dataflow.TaintTracking
|
||||||
|
import DataFlow::PathGraph
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function for opening a file.
|
* A function for opening a file.
|
||||||
|
@ -46,18 +47,42 @@ class FileFunction extends FunctionWithWrappers {
|
||||||
override predicate interestingArg(int arg) { arg = 0 }
|
override predicate interestingArg(int arg) { arg = 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
class TaintedPathConfiguration extends TaintTrackingConfiguration {
|
Expr asSourceExpr(DataFlow::Node node) {
|
||||||
override predicate isSink(Element tainted) {
|
result in [node.asConvertedExpr(), node.asDefiningArgument()]
|
||||||
exists(FileFunction fileFunction | fileFunction.outermostWrapperFunctionCall(tainted, _))
|
}
|
||||||
|
|
||||||
|
Expr asSinkExpr(DataFlow::Node node) {
|
||||||
|
result = node.asConvertedExpr()
|
||||||
|
or
|
||||||
|
result =
|
||||||
|
node.asOperand()
|
||||||
|
.(SideEffectOperand)
|
||||||
|
.getUse()
|
||||||
|
.(ReadSideEffectInstruction)
|
||||||
|
.getArgumentDef()
|
||||||
|
.getUnconvertedResultExpression()
|
||||||
|
}
|
||||||
|
|
||||||
|
class TaintedPathConfiguration extends TaintTracking::Configuration {
|
||||||
|
TaintedPathConfiguration() { this = "TaintedPathConfiguration" }
|
||||||
|
|
||||||
|
override predicate isSource(DataFlow::Node node) { isUserInput(asSourceExpr(node), _) }
|
||||||
|
|
||||||
|
override predicate isSink(DataFlow::Node node) {
|
||||||
|
exists(FileFunction fileFunction |
|
||||||
|
fileFunction.outermostWrapperFunctionCall(asSinkExpr(node), _)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from
|
from
|
||||||
FileFunction fileFunction, Expr taintedArg, Expr taintSource, PathNode sourceNode,
|
FileFunction fileFunction, Expr taintedArg, Expr taintSource, TaintedPathConfiguration cfg,
|
||||||
PathNode sinkNode, string taintCause, string callChain
|
DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode, string taintCause, string callChain
|
||||||
where
|
where
|
||||||
|
taintedArg = asSinkExpr(sinkNode.getNode()) and
|
||||||
fileFunction.outermostWrapperFunctionCall(taintedArg, callChain) and
|
fileFunction.outermostWrapperFunctionCall(taintedArg, callChain) and
|
||||||
taintedWithPath(taintSource, taintedArg, sourceNode, sinkNode) and
|
cfg.hasFlowPath(sourceNode, sinkNode) and
|
||||||
|
taintSource = asSourceExpr(sourceNode.getNode()) and
|
||||||
isUserInput(taintSource, taintCause)
|
isUserInput(taintSource, taintCause)
|
||||||
select taintedArg, sourceNode, sinkNode,
|
select taintedArg, sourceNode, sinkNode,
|
||||||
"This argument to a file access function is derived from $@ and then passed to " + callChain + ".",
|
"This argument to a file access function is derived from $@ and then passed to " + callChain + ".",
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
edges
|
edges
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | (const char *)... |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | (const char *)... |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data |
|
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data |
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection |
|
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection |
|
||||||
subpaths
|
|
||||||
nodes
|
nodes
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | semmle.label | ... + ... |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | semmle.label | fgets output argument |
|
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | semmle.label | fgets output argument |
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | (const char *)... | semmle.label | (const char *)... |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | semmle.label | data |
|
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | semmle.label | data |
|
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | semmle.label | data |
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection | semmle.label | data indirection |
|
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection | semmle.label | data indirection |
|
||||||
|
subpaths
|
||||||
#select
|
#select
|
||||||
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | This argument to a file access function is derived from $@ and then passed to fopen(filename). | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | user input (fgets) |
|
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | This argument to a file access function is derived from $@ and then passed to fopen(filename). | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | user input (fgets) |
|
||||||
|
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | user input (fgets) |
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
edges
|
edges
|
||||||
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | (const char *)... |
|
|
||||||
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | (const char *)... |
|
|
||||||
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName |
|
|
||||||
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName |
|
|
||||||
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName |
|
|
||||||
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName |
|
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName |
|
||||||
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection |
|
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection |
|
||||||
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection |
|
|
||||||
subpaths
|
|
||||||
nodes
|
nodes
|
||||||
| test.c:9:23:9:26 | argv | semmle.label | argv |
|
| test.c:9:23:9:26 | argv | semmle.label | argv |
|
||||||
| test.c:9:23:9:26 | argv | semmle.label | argv |
|
|
||||||
| test.c:17:11:17:18 | (const char *)... | semmle.label | (const char *)... |
|
|
||||||
| test.c:17:11:17:18 | fileName | semmle.label | fileName |
|
|
||||||
| test.c:17:11:17:18 | fileName | semmle.label | fileName |
|
| test.c:17:11:17:18 | fileName | semmle.label | fileName |
|
||||||
| test.c:17:11:17:18 | fileName indirection | semmle.label | fileName indirection |
|
| test.c:17:11:17:18 | fileName indirection | semmle.label | fileName indirection |
|
||||||
|
subpaths
|
||||||
#select
|
#select
|
||||||
| test.c:17:11:17:18 | fileName | test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:9:23:9:26 | argv | user input (argv) |
|
| test.c:17:11:17:18 | fileName | test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:9:23:9:26 | argv | user input (argv) |
|
||||||
|
| test.c:17:11:17:18 | fileName | test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:9:23:9:26 | argv | user input (argv) |
|
||||||
|
|
Загрузка…
Ссылка в новой задаче