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

Skip to content

Commit caaf543

Browse files
committed
Attempt to restructuring ReMethods and RegexExecution's modules
1 parent 6d5a0f2 commit caaf543

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

python/ql/src/semmle/python/Concepts.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ class CompiledRegex extends DataFlow::Node {
654654
}
655655

656656
class RegexExecution extends DataFlow::Node {
657-
RegexExecution() { this instanceof DirectRegex or this instanceof CompiledRegex }
657+
RegexExecution() { this instanceof DirectRegex or this instanceof CompiledRegex } // How should this be cross-imported with Stdlib?
658658
}
659659

660660
class RegexEscape extends DataFlow::Node {

python/ql/src/semmle/python/frameworks/Stdlib.qll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,36 @@ private module Stdlib {
864864
class Sqlite3 extends PEP249ModuleApiNode {
865865
Sqlite3() { this = API::moduleImport("sqlite3") }
866866
}
867+
868+
// ---------------------------------------------------------------------------
869+
// re
870+
// ---------------------------------------------------------------------------
871+
/** List of re methods. */
872+
private class ReMethods extends string {
873+
ReMethods() { this in ["match", "fullmatch", "search", "split", "findall", "finditer"] }
874+
}
875+
876+
/** re.ReMethod(pattern, string) */
877+
private class DirectRegex extends DataFlow::Node {
878+
DirectRegex() {
879+
exists(ReMethods reMethod, DataFlow::CallCfgNode reCall |
880+
reCall = API::moduleImport("re").getMember(reMethod).getACall() and
881+
this = reCall.getArg(0)
882+
)
883+
}
884+
}
885+
886+
/** re.compile(pattern).ReMethod */
887+
class CompiledRegex extends DataFlow::Node {
888+
CompiledRegex() {
889+
exists(DataFlow::CallCfgNode patternCall, DataFlow::AttrRead reMethod |
890+
patternCall = API::moduleImport("re").getMember("compile").getACall() and
891+
patternCall = reMethod.getObject().getALocalSource() and
892+
reMethod.getAttributeName() instanceof ReMethods and
893+
this = patternCall.getArg(0)
894+
)
895+
}
896+
}
867897
}
868898

869899
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)