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

Skip to content

Commit b207929

Browse files
committed
RegexExecution restructuring
1 parent 3daec8e commit b207929

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,21 @@ class CompiledRegex extends DataFlow::Node {
656656
class RegexExecution extends DataFlow::Node {
657657
RegexExecution() { this instanceof DirectRegex or this instanceof CompiledRegex } // How should this be cross-imported with Stdlib?
658658
}
659+
/*
660+
*/
659661

660-
class RegexEscape extends DataFlow::Node {
661-
RegexEscape() {
662-
this = API::moduleImport("re").getMember("escape").getACall().(DataFlow::CallCfgNode).getArg(0)
662+
module RegexExecution {
663+
abstract class Range extends DataFlow::Node {
664+
DataFlow::Node getRegexNode() {
665+
result instanceof DirectRegex or result instanceof CompiledRegex
666+
}
663667
}
664668
}
669+
670+
class RegexExecution extends DataFlow::Node {
671+
override RegexExecution::Range range;
672+
673+
RegexExecution() { this = range }
674+
675+
DataFlow::Node getRegexNode() { result = range.getRegexNode() }
676+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ private module Stdlib {
885885
}
886886

887887
/** re.compile(pattern).ReMethod */
888-
class CompiledRegex extends DataFlow::Node {
888+
private class CompiledRegex extends DataFlow::Node {
889889
CompiledRegex() {
890890
exists(DataFlow::CallCfgNode patternCall, DataFlow::AttrRead reMethod |
891891
patternCall = API::moduleImport("re").getMember("compile").getACall() and
@@ -895,6 +895,13 @@ private module Stdlib {
895895
)
896896
}
897897
}
898+
899+
private class RegexEscape extends Concepts::RegexExecution {
900+
RegexEscape() {
901+
this =
902+
API::moduleImport("re").getMember("escape").getACall().(DataFlow::CallCfgNode).getArg(0)
903+
}
904+
}
898905
}
899906
}
900907

0 commit comments

Comments
 (0)