Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d72b4f

Browse files
committed
Python: Limit pretty printing to relevant nodes
1 parent 16902c2 commit 6d72b4f

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

python/ql/src/Security/CWE-327/InsecureProtocol.ql

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,46 @@
1212
import python
1313
import FluentApiModel
1414

15-
string callName(AstNode call) {
15+
// Helper for pretty printer `configName`.
16+
// This is a consequence of missing pretty priting.
17+
// We do not want to evaluate our bespoke pretty printer
18+
// for all `DataFlow::Node`s so we define a sub class of interesting ones.
19+
class ProtocolConfiguration extends DataFlow::Node {
20+
ProtocolConfiguration() {
21+
unsafe_connection_creation_with_context(_, _, this, _)
22+
or
23+
unsafe_connection_creation_without_context(this, _)
24+
or
25+
unsafe_context_creation(this, _)
26+
}
27+
}
28+
29+
// Helper for pretty printer `callName`.
30+
// This is a consequence of missing pretty priting.
31+
// We do not want to evaluate our bespoke pretty printer
32+
// for all `AstNode`s so we define a sub class of interesting ones.
33+
//
34+
// Note that AstNode is abstract and AstNode_ is a library class, so
35+
// we have to extend @py_ast_node.
36+
class Namable extends @py_ast_node {
37+
Namable() {
38+
exists(ProtocolConfiguration protocolConfiguration |
39+
this = protocolConfiguration.asCfgNode().(CallNode).getFunction().getNode()
40+
)
41+
or
42+
exists(Namable attr | this = attr.(Attribute).getObject())
43+
}
44+
45+
string toString() { result = "AstNode" }
46+
}
47+
48+
string callName(Namable call) {
1649
result = call.(Name).getId()
1750
or
1851
exists(Attribute a | a = call | result = callName(a.getObject()) + "." + a.getName())
1952
}
2053

21-
string configName(DataFlow::Node protocolConfiguration) {
54+
string configName(ProtocolConfiguration protocolConfiguration) {
2255
result =
2356
"call to " + callName(protocolConfiguration.asCfgNode().(CallNode).getFunction().getNode())
2457
or

0 commit comments

Comments
 (0)