← 输入框|github.com|刷新
Skip to content

Rust: Do not treat the early return of ? as returning the unwrapped value - #22903

Open
LucaCappelletti94 wants to merge 2 commits into
github:mainfrom
LucaCappelletti94:upstream/rust-cleartext-logging-redacted-debug
Open

LucaCappelletti94 wants to merge 2 commits into
github:mainfrom
LucaCappelletti94:upstream/rust-cleartext-logging-redacted-debug

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

ExprReturnNode treats any expression with a control-flow edge into the function exit as a returned value. The ? operator has such an edge for its early return, so every x? became a return node, and the unwrapped Ok or Some value flowed out of the enclosing function as though it were the function's result. A function that reads a value with ? and then returns something unrelated therefore passed that value on to its callers.

This surfaced as rust/cleartext-logging false positives on real code, where a helper read a secret with ? and the alert followed it through several callers to an assert! that printed an unrelated struct. The ? expression now stays a return node only along its normal edge, which keeps x? in tail position. The early return itself, the Err or None held by x, was not modelled as returned data before and still is not, so no existing flow is lost.

I am not too familiar with editing CodeQL so I relied on Opus for parts of the PR + testing the hell out of the changes, I hope all looks decent.

@LucaCappelletti94
LucaCappelletti94 requested a review from a team as a code owner October 27, 2026 14:56
Copilot AI max review requested due to automatic review settings October 27, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions github-actions Bot added documentation Rust Pull requests that update Rust code external-contribution labels Oct 27, 2026
@paldepind paldepind self-assigned this Oct 27, 2026
@paldepind
paldepind requested a max review from Copilot October 27, 2026 15:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The core Rust return-flow change needs maintainer validation, particularly for consistency with callback-return modeling.

1 open issue

Review effort: Max

exists(SuccessorType t | n.getACfgNode().getASuccessor(t) instanceof AnnotatedExitCfgNode |
// The early return of `x?` returns the `Err` or `None` held by `x`, which is
// a different value from the one `x?` evaluates to
not (n instanceof TryExpr and t instanceof ReturnSuccessor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both sites now use a shared isReturnedValue predicate, with a callback test in dataflow/models.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation external-contribution Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants