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

Skip to content

Commit 53fbf51

Browse files
committed
Python: Fix handling of enum members in python/ql/src/Expressions/IsComparisons.qll.
1 parent 5da209f commit 53fbf51

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

python/ql/src/Expressions/IsComparisons.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ predicate invalid_portable_is_comparison(Compare comp, Cmpop op, ClassObject cls
107107
left.refersTo(obj) and right.refersTo(obj) and
108108
exists(ImmutableLiteral il | il.getLiteralObject() = obj)
109109
)
110+
and
111+
/* OK to use 'is' when comparing with a member of an enum */
112+
not exists(Expr left, Expr right, AstNode origin |
113+
comp.compares(left, op, right) and
114+
enum_member(origin) |
115+
left.refersTo(_, origin) or right.refersTo(_, origin)
116+
)
110117
}
111118

119+
private predicate enum_member(AstNode obj) {
120+
exists(ClassObject cls, AssignStmt asgn |
121+
cls.getASuperType().getName() = "Enum" |
122+
cls.getPyClass() = asgn.getScope() and
123+
asgn.getValue() = obj
124+
)
125+
}
112126

0 commit comments

Comments
 (0)