Skip to content

fix: WMI DBNull crash in drive scan and uninstaller prefix bypass#817

Merged
laurentiu021 merged 1 commit into
mainfrom
fix/r3-p1-crash-safety
Jun 8, 2026
Merged

fix: WMI DBNull crash in drive scan and uninstaller prefix bypass#817
laurentiu021 merged 1 commit into
mainfrom
fix/r3-p1-crash-safety

Conversation

@laurentiu021

Copy link
Copy Markdown
Owner

Round 3 of the audit — P1 crash/security safety (the two highest-impact items in this round).

Drive enumeration crashed on missing WMI properties

FixedDriveService read MediaType/BusType via Convert.ToUInt32(value ?? 0u). WMI returns DBNull.Value (not null) for absent properties, so the ?? never fired and Convert.ToUInt32(DBNull.Value) threw — aborting the entire drive scan on hardware that doesn't report those fields. Reads now go through a ToUInt32Safe helper that maps both null and DBNull to 0.

Uninstaller trusted-directory check accepted sibling folders

IsUnderTrustedDirectory used a bare StartsWith, so C:\Program Files Evil\malware.exe passed the C:\Program Files check. It now compares on a normalized directory boundary (trailing separator + GetFullPath), so only genuine sub-paths of a trusted directory qualify.

Tests

Both methods made internal (InternalsVisibleTo already present) for direct unit testing:

  • ToUInt32Safe: DBNull → 0, null → 0, convertible values, unconvertible string → 0.
  • IsUnderTrustedDirectory: path inside Program Files trusted; Program Files Evil sibling rejected; unrelated temp path rejected.

Regression

Full-solution build clean (main + Tests + IntegrationTests + UITests). Version 1.20.3.

Remaining Round-3 items (PingMonitor CTS, LogsVM UI-thread COM, StartupVM cross-thread, Dashboard NVIDIA-only GPU) will follow in a separate PR.

Round 3 (P1 crash/security safety):

- FixedDriveService read MediaType/BusType with Convert.ToUInt32(value ?? 0u).
  WMI returns DBNull.Value (not null) for absent properties, so the ?? never
  fired and Convert.ToUInt32(DBNull.Value) threw, aborting the whole drive scan
  on some hardware. Reads now use a ToUInt32Safe helper (null and DBNull -> 0).
- UninstallerService.IsUnderTrustedDirectory used a bare StartsWith, letting
  'C:\Program Files Evil\x.exe' pass the 'C:\Program Files' check. It now
  compares on a normalized directory boundary so only real sub-paths qualify.

Both methods made internal for direct unit testing (InternalsVisibleTo already
present). Tests cover DBNull/null/convertible/unconvertible inputs and the
sibling-prefix bypass.
@laurentiu021 laurentiu021 merged commit 7199613 into main Jun 8, 2026
4 checks passed
@laurentiu021 laurentiu021 deleted the fix/r3-p1-crash-safety branch June 8, 2026 12:29
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.

1 participant