peass-ng/PEASS-ng · warning · ArgumentNullException
deviceName
Error message
deviceName
What it means
QueryDosDevice(string deviceName) throws ArgumentNullException with paramName "deviceName" when the argument is null, empty, or whitespace. It wraps the Win32 QueryDosDevice API to translate an MS-DOS device name (e.g. "C:") into its target device string, and validates input before the native call.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/Volume.QueryDosDevice.cs:52
/// <summary>[AlphaFS] Retrieves a sorted list of all existing MS-DOS device names.</summary>
/// <returns>An <see cref="IEnumerable{String}"/> sorted list of all existing MS-DOS device names.</returns>
[SecurityCritical]
public static IEnumerable<string> QueryAllDosDevices()
{
return QueryDosDeviceCore(null, true);
}
/// <summary>[AlphaFS] Retrieves the current mapping for a particular MS-DOS device name.</summary>
/// <returns>The current mapping for a particular MS-DOS device name.</returns>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="FileNotFoundException"/>
/// <param name="deviceName">An MS-DOS device name string specifying the target of the query, such as: "C:", "D:" or "\\?\Volume{GUID}".</param>
[SecurityCritical]
public static string QueryDosDevice(string deviceName)
{
if (Utils.IsNullOrWhiteSpace(deviceName))
throw new ArgumentNullException("deviceName");
var devName = QueryDosDeviceCore(deviceName, false).ToArray()[0];
return !Utils.IsNullOrWhiteSpace(devName) ? devName : null;
}
/// <summary>[AlphaFS] Retrieves the current mapping for a particular MS-DOS device name. The function can also obtain a list of all existing MS-DOS device names.</summary>
/// <returns>An <see cref="IEnumerable{String}"/> sorted list of all existing MS-DOS device names or the .</returns>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="FileNotFoundException"/>
/// <param name="deviceName">An MS-DOS device name string specifying the target of the query, such as: "C:", "D:" or "\\?\Volume{GUID}".</param>
/// <param name="sort"><c>true</c> to sort the list with MS-DOS device names.</param>
[SecurityCritical]
internal static IEnumerable<string> QueryDosDeviceCore(string deviceName, bool sort)View on GitHub (pinned to 53fb989abc)
Solutions
- Pass a valid MS-DOS device name such as "C:" or "\\?\Volume{GUID}\"
- Guard with string.IsNullOrWhiteSpace before calling
- Catch ArgumentNullException and treat blank device names as unresolved
Example fix
// before var target = Volume.QueryDosDevice(devName); // after var target = string.IsNullOrWhiteSpace(devName) ? null : Volume.QueryDosDevice(devName);
Defensive patterns
Strategy: validation
Validate before calling
var target = string.IsNullOrWhiteSpace(deviceName) ? null : Volume.QueryDosDevice(deviceName);
Type guard
static bool IsValidDosDeviceName(string s) => !string.IsNullOrWhiteSpace(s) && (Regex.IsMatch(s, @"^[A-Za-z]:$") || s.StartsWith(@"\\?\Volume{")); Try / catch
try { target = Volume.QueryDosDevice(devName); }
catch (ArgumentNullException) { Log.Warn($"Device name blank: {devName}"); } Prevention
- Validate drive-letter strings match "X:" before querying DOS devices
- Skip blank entries when bulk-resolving device names
- Remember the method may return null on valid-but-unresolved names — null-check the result too
When it happens
Trigger: Calling Volume.QueryDosDevice(null)/"" when looking up a drive mapping; GetVolumeDeviceName passing through an empty device name from a parsed volume entry.
Common situations: Resolving drive letters from a list where some entries are blank; a mount-point parse produced an empty device name; drive-letter variable not initialized.
Related errors
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/5110d73ea7be03c8.
Report an issue: GitHub.