You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This was reported via the feedback tool and was hand ported to GitHub
Summary
System.Management provides managed access to Windows Management Instrumentation (WMI). A common usage pattern is:
Create a ManagementScope pointing to a local or remote WMI namespace.
Execute a query with ManagementObjectSearcher.Get().
Enumerate the returned ManagementObjectCollection.
The relevant query entry point is ManagementObjectSearcher.Get(), which executes the WMI query and returns a ManagementObjectCollection backed by an IEnumWbemClassObject COM enumerator:
this method can still return true even when no valid object has been written into cachedObjects[cacheIndex]. In other words, the code assumes that a non-negative return status implies a valid current object, but that assumption is not enforced before the cached object is later used.
Once Current is accessed, the cached entry is used without a null check:
If wbemObject is null at this point, the process terminates with an unhandled System.NullReferenceException.
An observed crash looks like this:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at System.Management.ManagementBaseObject._IsClass(IWbemClassObjectFreeThreaded wbemObject)
at System.Management.ManagementBaseObject.GetBaseObject(IWbemClassObjectFreeThreaded wbemObject, ManagementScope scope)
at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.get_Current()
at Program.Main(String[] args)
The managed code assumes that the native enumerator result is internally consistent and does not validate the cached object before use.
For comparison, ManagementEventWatcher contains a stricter guard and throws when cachedCount == 0 after a successful fetch path:
Note
This was reported via the feedback tool and was hand ported to GitHub
Summary
System.Managementprovides managed access to Windows Management Instrumentation (WMI). A common usage pattern is:ManagementScopepointing to a local or remote WMI namespace.ManagementObjectSearcher.Get().ManagementObjectCollection.The relevant query entry point is
ManagementObjectSearcher.Get(), which executes the WMI query and returns aManagementObjectCollectionbacked by anIEnumWbemClassObjectCOM enumerator:The returned collection is evaluated lazily. The actual WMI objects are only pulled later by
ManagementObjectEnumerator.MoveNext():this method can still return
trueeven when no valid object has been written intocachedObjects[cacheIndex]. In other words, the code assumes that a non-negative return status implies a valid current object, but that assumption is not enforced before the cached object is later used.Once
Currentis accessed, the cached entry is used without a null check:ManagementBaseObject.GetBaseObject()in turn immediately calls_IsClass():Finally,
_IsClass()dereferences the object:If
wbemObjectis null at this point, the process terminates with an unhandledSystem.NullReferenceException.An observed crash looks like this:
The managed code assumes that the native enumerator result is internally consistent and does not validate the cached object before use.
For comparison,
ManagementEventWatchercontains a stricter guard and throws whencachedCount == 0after a successful fetch path:This suggests that the collection enumerator should also reject an empty successful batch instead of proceeding to dereference the cached entry.