Skip to content

Audit winreg key queries before OS calls - #9593

Merged
youknowone merged 3 commits into
RustPython:mainfrom
youknowdot:fix/winreg-query-audits-20261103
Nov 5, 2026
Merged

youknowone merged 3 commits into
RustPython:mainfrom
youknowdot:fix/winreg-query-audits-20261103

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Emit CPython's winreg.QueryInfoKey and winreg.QueryValue audit events after argument conversion and before registry operations.
  • For QueryValue, convert the required str | None subkey through UTF-16 before auditing and before the performance-data check, preserving lone surrogates and rejecting trailing or embedded NULs.
  • Reconstruct the audit payload from UTF-16 as CPython does. Audit tuple/name objects are created only if audit hooks are active.

This does not address all winreg audit events or claim complete parity. Generic invalid-subkey type-error wording remains outside this change. The current-main reconciliation preserves the newer surrogate-safe PyStr return alongside the reviewed Wtf8Buf input and audit order. #9586 separately fixes the HKEY converter; #9589 addresses QueryValueEx.

Validation

  • Independently source-reviewed against CPython v3.15.0 PC/winreg.c and its generated Clinic code, including event arguments and conversion order.
  • prek hooks and git diff --check passed.
  • The current-main conflict resolution passed independent source review, focused host-env/VM/stdlib Linux threading cargo check, normal all-targets Clippy, and ordinary hooks. Clippy diagnostics match four unchanged-main warnings; none were suppressed.
  • These Linux checks do not type-check or execute the Windows-only registry code. Native RustPython execution and full workspace/C-API runtime suites were not run; hosted Windows CI remains required.

Emit CPython query events and preserve UTF-16 input semantics, including lone surrogates and NUL rejection.

Assisted-by: dot:frontier-intelligence
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codspeed

codspeed Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix/winreg-query-audits-20261103 (5ca85e4) with main (18fc82b)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread crates/vm/src/stdlib/winreg.rs Outdated
fn QueryValue(key: HKEYArg, sub_key: Option<String>, vm: &VirtualMachine) -> PyResult<String> {
fn QueryValue(
key: HKEYArg,
sub_key: Option<PyRef<PyStr>>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this better than below?

Suggested change
sub_key: Option<PyRef<PyStr>>,
sub_key: Option<Wtf8Buf>,

Apply maintainer review while preserving conversion and audit behavior.

Assisted-by: OpenAI Codex:model version unavailable
Keep the reviewed WTF-8 input and audit order while retaining surrogate-safe QueryValue output.

Assisted-by: OpenAI Codex:model version not exposed
@youknowone
youknowone marked this pull request as ready for review November 5, 2026 14:22
@youknowone
youknowone merged commit 2319229 into RustPython:main Nov 5, 2026
24 of 28 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-05T14:23:00.959913Z
We couldn’t complete this review. Comment @codex review to try again.
bc92a27 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants