Skip to content

Guard empty successful WMI enumeration batches - #132381

Open
jeffhandley with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-potential-null-deref
Open

Guard empty successful WMI enumeration batches#132381
jeffhandley with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-potential-null-deref

Conversation

Copilot AI commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

A malformed remote WMI enumerator can report success without returning an object, causing Current to dereference a null cache entry.

  • Enumeration guard: throw a ManagementException for zero-result successful batches after preserving timeout and normal end-of-enumeration handling.
if (cachedCount == 0)
    ManagementException.ThrowWithExtendedInfo(ManagementStatus.Timedout);

Note

This PR description was generated by AI/Copilot.

Copilot AI lite review requested due to automatic review settings August 17, 2026 02:52

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 wasn't able to review any files in this pull request.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 17, 2026 03:11
Copilot AI changed the title [WIP] Fix potential null-deref in remote WMI enumeration Guard empty successful WMI enumeration batches Aug 17, 2026
Copilot AI requested a review from jeffhandley August 17, 2026 03:12

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/libraries/System.Management/src/System/Management/ManagementObjectCollection.cs:586

  • This change adds a new exception-throwing path for malformed WMI enumerators (success status with cachedCount == 0), but there’s no regression test exercising this behavior. Without a test, it’s easy for future refactors to remove or change this guard and reintroduce the original null-deref scenario.
                        if (cachedCount == 0)
                            ManagementException.ThrowWithExtendedInfo(ManagementStatus.Timedout);

This comment was marked as resolved.

Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 17, 2026 03:54
Copilot AI requested a review from jeffhandley August 17, 2026 03:55

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/libraries/System.Management/src/System/Management/ManagementObjectCollection.cs:588

  • The PR description (and the existing pattern in ManagementEventWatcher.cs:436-437) indicates this guard should throw a Timedout ManagementException for a successful fetch that returns 0 objects, but the implementation throws ManagementStatus.Failed here. Please reconcile (either update the PR description / issue rationale, or align the code with the Timedout behavior used elsewhere).
                        //A malformed enumerator can report success without returning any objects; treat this as a failure
                        //rather than silently proceeding with an empty cache.
                        if (cachedCount == 0)
                            ManagementException.ThrowWithExtendedInfo(ManagementStatus.Failed);

@jeffhandley
jeffhandley marked this pull request as ready for review August 17, 2026 04:02
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jeffhandley
jeffhandley enabled auto-merge (squash) August 17, 2026 04:03
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-management
See info in area-owners.md if you want to be subscribed.

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.

Potential null-deref in remote WMI enumeration

3 participants