peass-ng/PEASS-ng · warning · ArgumentNullException

path

Error message

path

What it means

GetVolumePathName(string path) throws ArgumentNullException with paramName "path" when the argument is null, empty, or whitespace. This wraps the Win32 GetVolumePathName API and validates the input before calling Path.GetFullPathCore and the native function.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/Volume.GetVolumePathName.cs:42

using System.Security;
using System.Text;

namespace Alphaleonis.Win32.Filesystem
{
   public static partial class Volume
   {
      /// <summary>[AlphaFS] Retrieves the volume mount point where the specified path is mounted.</summary>
      /// <exception cref="ArgumentNullException"/>
      /// <param name="path">The path to the volume, for example: "C:\Windows".</param>
      /// <returns>
      ///   <para>Returns the nearest volume root path for a given directory.</para>
      ///   <para>The volume path name, for example: "C:\Windows" returns: "C:\".</para>
      /// </returns>
      [SecurityCritical]
      public static string GetVolumePathName(string path)
      {
         if (Utils.IsNullOrWhiteSpace(path))
            throw new ArgumentNullException("path");


         using (new NativeMethods.ChangeErrorMode(NativeMethods.ErrorMode.FailCriticalErrors))
         {
            var volumeRootPath = new StringBuilder(NativeMethods.MaxPathUnicode / 32);
            var pathLp = Path.GetFullPathCore(null, false, path, GetFullPathOptions.AsLongPath | GetFullPathOptions.FullCheck);


            // GetVolumePathName()
            // 2013-07-18: MSDN does not confirm LongPath usage but a Unicode version of this function exists.

            var success = NativeMethods.GetVolumePathName(pathLp, volumeRootPath, (uint) volumeRootPath.Capacity);

            var lastError = Marshal.GetLastWin32Error();

            if (success)
               return Path.GetRegularPathCore(volumeRootPath.ToString(), GetFullPathOptions.None, false);

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a non-empty absolute or relative path (e.g. "C:\Windows")
  2. Check string.IsNullOrWhiteSpace at the call site before resolving the volume
  3. Catch ArgumentNullException when paths originate from user input or external data

Example fix

// before
var root = Volume.GetVolumePathName(filePath);
// after
var root = string.IsNullOrWhiteSpace(filePath) ? null : Volume.GetVolumePathName(filePath);
Defensive patterns

Strategy: validation

Validate before calling

var root = string.IsNullOrWhiteSpace(path) ? null : Volume.GetVolumePathName(path);

Type guard

static bool HasPathValue(string p) => !string.IsNullOrWhiteSpace(p);

Try / catch

try { root = Volume.GetVolumePathName(path); }
catch (ArgumentNullException) { root = null; Log.Warn("Path was null/empty; no volume root"); }

Prevention

When it happens

Trigger: Calling Volume.GetVolumePathName(null)/"" — e.g. from volInfo1/volInfo2 helpers with an unset path, or from GetUniqueVolumeNameForPath after passing a blank string (which throws here first).

Common situations: Deriving the volume root of a file path that is null because a file-listing entry was empty; environment/config variables holding the path not set.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/9a3619b8997a443d. Report an issue: GitHub.