Skip to content

Handle unnamed winreg values in QueryValueEx - #9589

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/winreg-query-value-none-20261103
Nov 3, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/winreg-query-value-none-20261103

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Let winreg.QueryValueEx(key, None) query the unnamed/default registry value, while keeping the name argument required.
  • Pass nullable names through both Windows API calls and preserve Python strings, including lone surrogates, through the UTF-16 conversion.
  • Emit CPython's winreg.QueryValue audit event after argument conversion and before the registry query; rebuild the audit name from the UTF-16 buffer as CPython does.
  • Return an initial registry failure immediately unless the result is ERROR_MORE_DATA, rather than retrying unrelated failures because the returned size is zero. Keep a nonzero buffer after a successful zero-length size query so a value that grows between calls can be retried.

The audit tuple and its name are only built when audit hooks are active. Invalid-name type-error wording remains a pre-existing difference; #9586 separately improves the HKEY conversion used here. This does not claim full winreg parity.

Validation

  • Independently source-reviewed against CPython v3.15.0 PC/winreg.c and PC/clinic/winreg.c.h, including conversion and audit order.
  • prek hooks and git diff --check passed.
  • No RustPython build or Windows execution was run locally; CI is needed.

Summary by CodeRabbit

  • New Features
    • winreg.QueryValueEx now accepts None as the value name, allowing queries of a registry key’s default value.
    • Registry value names that cannot be converted to Windows format are reported as errors before the query is performed.
    • Existing query results and error handling remain unchanged for valid value names.

Accept a required None value name, preserve UTF-16 strings, issue the CPython audit event, and return initial registry errors before retrying.

Assisted-by: dot:frontier-intelligence
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The registry query helper and Python QueryValueEx now accept an optional value name. The helper passes the optional name to both registry queries, and QueryValueEx converts a provided Python string to a Windows wide string.

Changes: Optional Registry Value Names

Layer / File(s) Summary
Optional name in registry queries
crates/host_env/src/winreg.rs
query_value_bytes accepts an optional value name and passes it to the size and data queries. The initial query error handling now returns nonzero errors before applying the zero-size buffer fallback.
Optional name in QueryValueEx
crates/vm/src/stdlib/winreg.rs
QueryValueEx accepts an optional Python string name, converts a provided name to a Windows wide string, and passes the optional name to the registry query. It emits the winreg.QueryValue audit event with the handle, a None subkey, and the optional name.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 0ae90

No actionable merge-blocking issue remains. The nullable registry-name change is mergeable subject to normal checks, including Windows CI.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Handle unnamed winreg values in QueryValueEx" matches the main change. The PR lets winreg.QueryValueEx(key, None) query the unnamed default registry value. The QueryValueEx signature now ta…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Handle unnamed winreg values in QueryValueEx" matches the main change. The PR lets winreg.QueryValueEx(key, None) query the unnamed default registry value. The QueryValueEx signature now takes an optional name, and query_value_bytes passes the nullable name to both registry calls. The title names the function and the feature, so it is specific and clear. It does not mention the secondary buffer-handling and error-ordering fixes, which is acceptable.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • 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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 18fc82b and 0ae903d.

Files selected for processing: 2
  • crates/host_env/src/winreg.rs
  • crates/vm/src/stdlib/winreg.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@youknowone
youknowone marked this pull request as ready for review November 3, 2026 18:54
@youknowone
youknowone enabled auto-merge (squash) November 3, 2026 18:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

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 ✅ Completed 2026-11-03T18:57:46.129007Z 0ae903d 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.

@youknowone
youknowone merged commit 0b081b0 into RustPython:main Nov 3, 2026
28 checks passed
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