Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: support grouped exceptions #11244

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

yoff
Copy link
Contributor

@yoff yoff commented Nov 14, 2022

@yoff yoff requested a review from a team as a code owner Nov 14, 2022
python/ql/lib/semmle/python/Stmts.qll Fixed Show fixed Hide fixed
Copy link
Member

@RasmusWL RasmusWL left a comment

Overall looks good, although I have some things that I would like changes

| 23 = @py_With
| 24 = @py_TemplateWrite
| 25 = @py_AnnAssign;
| 7 = @py_ExceptGroupStmt
Copy link
Member

@RasmusWL RasmusWL Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it would have been easier for update/downgrade scripts if this new kind was added in the end (as id=26)? (too late now, but something to consider for the future)

python/ql/lib/semmle/python/Stmts.qll Outdated Show resolved Hide resolved
python/ql/lib/semmle/python/essa/Essa.qll Outdated Show resolved Hide resolved
# This should cover all the syntactical constructs that we hope to support.
# Headings refer to https://docs.python.org/3/reference/expressions.html,
# and are selected whenever they incur dataflow.
# Intended sources should be the variable `SOURCE` and intended sinks should be
# arguments to the function `SINK` (see python/ql/test/experimental/dataflow/testConfig.qll).
#
# Functions whose name ends with "_with_local_flow" will also be tested for local flow.
#
# All functions starting with "test_" should run and execute `print("OK")` exactly once.
# This can be checked by running validTest.py.
Copy link
Member

@RasmusWL RasmusWL Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of this text is not valid, and should be removed. I would probably delete all of it, but I think it's also acceptable to have the last two lines... up to you 🤷

@@ -52,7 +52,7 @@ predicate iter_not_exhausted(EssaVariable iterator) {
predicate stop_iteration_handled(CallNode call) {
exists(Try t |
t.containsInScope(call.getNode()) and
t.getAHandler().getType() = stopIteration().getAValueReachableFromSource().asExpr()
t.getANormalHandler().getType() = stopIteration().getAValueReachableFromSource().asExpr()
Copy link
Member

@RasmusWL RasmusWL Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that you had to do these rewrites makes me wonder if other end-users are going to be affected in the same way, without the knowledge that they need to re-write their code? (at least this needs to be called out in the change note)

Overall I totally understand why you ended up doing it this way, and would probably have done the same if I were in your position... it just begs for us to support automatic rewrites based on qlpack versions 🤷

Copy link
Contributor Author

@yoff yoff Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it does seem the only reasonable way to do it, but it still annoys me that we get a user facing breakage here..

python/ql/lib/semmle/python/types/Exceptions.qll Outdated Show resolved Hide resolved
python/ql/lib/semmle/python/types/Exceptions.qll Outdated Show resolved Hide resolved
override Stmt getHandler(int i) { result = Try_.super.getHandler(i) }

Copy link
Member

@RasmusWL RasmusWL Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QL4QL suggests that you can also remove this override.

Suggested change
override Stmt getHandler(int i) { result = Try_.super.getHandler(i) }

Co-authored-by: Rasmus Wriedt Larsen <rasmuswl@github.com>
@@ -364,10 +386,13 @@
result = this.getAnOrelse()
}

override ExceptStmt getHandler(int i) { result = Try_.super.getHandler(i) }
override Stmt getHandler(int i) { result = Try_.super.getHandler(i) }

Check warning

Code scanning / CodeQL

Redundant override Warning

Redundant override of
this predicate
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants