From bb8d0b4881aae0b20f0c7c4f99bcb6c70e845c84 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Tue, 19 Nov 2024 10:24:08 +0100 Subject: [PATCH] Rust: Handle early returns in `async` blocks in CFG --- rust/ql/lib/codeql/rust/controlflow/internal/Scope.qll | 3 +++ rust/ql/test/library-tests/controlflow/Cfg.expected | 1 + 2 files changed, 4 insertions(+) diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/Scope.qll b/rust/ql/lib/codeql/rust/controlflow/internal/Scope.qll index 5a752abf4b9a..7b3367690ec6 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/Scope.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/Scope.qll @@ -22,6 +22,9 @@ final class AsyncBlockScope extends CfgScopeImpl, AsyncBlockExpr instanceof Expr override predicate scopeLast(AstNode last, Completion c) { last(super.getLastChildElement(), last, c) + or + last(super.getChildNode(_), last, c) and + not c instanceof NormalCompletion } } diff --git a/rust/ql/test/library-tests/controlflow/Cfg.expected b/rust/ql/test/library-tests/controlflow/Cfg.expected index 9b112133edd9..620837abc826 100644 --- a/rust/ql/test/library-tests/controlflow/Cfg.expected +++ b/rust/ql/test/library-tests/controlflow/Cfg.expected @@ -892,6 +892,7 @@ edges | test.rs:403:13:405:14 | ExprStmt | test.rs:403:16:403:16 | b | | | test.rs:403:16:403:16 | b | test.rs:403:13:405:13 | IfExpr | false | | test.rs:403:16:403:16 | b | test.rs:404:17:404:41 | ExprStmt | true | +| test.rs:404:17:404:40 | ReturnExpr | test.rs:402:28:407:9 | exit BlockExpr (normal) | return | | test.rs:404:17:404:41 | ExprStmt | test.rs:404:24:404:34 | async_block | | | test.rs:404:24:404:34 | async_block | test.rs:404:36:404:39 | true | | | test.rs:404:24:404:40 | CallExpr | test.rs:404:17:404:40 | ReturnExpr | |