peass-ng/PEASS-ng · error · ArgumentNullException

Value cannot be null. Parameter name: path

Error message

Value cannot be null.
Parameter name: path

What it means

An ArgumentNullException guard on the 'path' parameter of SetCurrentDirectory: the argument validation rejects a null string before the Win32 SetCurrentDirectory call is made. It fires only when the caller supplies null as the target directory path.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory.SetCurrentDirectory.cs:69

      /// <summary>
      /// Sets the application's current working directory to the specified directory.
      /// <para>
      ///   MSDN: Multithreaded applications and shared library code should not use the GetCurrentDirectory function and should avoid using relative path names.
      ///   The current directory state written by the SetCurrentDirectory function is stored as a global variable in each process,
      ///   therefore multithreaded applications cannot reliably use this value without possible data corruption from other threads that may also be reading or setting this value.
      ///   <para>This limitation also applies to the SetCurrentDirectory and GetFullPathName functions. The exception being when the application is guaranteed to be running in a single thread,
      ///   for example parsing file names from the command line argument string in the main thread prior to creating any additional threads.</para>
      ///   <para>Using relative path names in multithreaded applications or shared library code can yield unpredictable results and is not supported.</para>
      /// </para>
      /// </summary>
      /// <param name="path">The path to which the current working directory is set.</param>
      /// <param name="pathFormat">Indicates the format of the path parameter.</param>
      [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Utils.IsNullOrWhiteSpace validates arguments.")]
      [SecurityCritical]
      public static void SetCurrentDirectory(string path, PathFormat pathFormat)
      {
         if (Utils.IsNullOrWhiteSpace(path))
            throw new ArgumentNullException("path");

         var fullCheck = pathFormat == PathFormat.RelativePath;
         Path.CheckSupportedPathFormat(path, fullCheck, fullCheck);
         var pathLp = Path.GetExtendedLengthPathCore(null, path, pathFormat, GetFullPathOptions.AddTrailingDirectorySeparator);

         if (pathFormat == PathFormat.FullPath)
            pathLp = Path.GetRegularPathCore(pathLp, GetFullPathOptions.None, false);


         // SetCurrentDirectory()
         // 2016-09-29: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
         // 2017-05-30: MSDN confirms LongPath usage: Starting with Windows 10, version 1607

         var success = NativeMethods.SetCurrentDirectory(pathLp);

         var lastError = Marshal.GetLastWin32Error();
         if (!success)
            NativeError.ThrowException(lastError, pathLp);

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Supply a non-null directory path to SetCurrentDirectory
  2. Validate the path (null/empty check and Directory.Exists) before changing the current directory
  3. Build the path from a known-good constant or validated configuration value
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory.SetCurrentDirectory.cs:69 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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