peass-ng/PEASS-ng · error · ArgumentNullException

volumeName

Error message

volumeName

What it means

Volume.SetCurrentVolumeLabel sets the label of the current volume via NativeMethods.SetVolumeLabel(null, volumeName). It validates volumeName with Utils.IsNullOrWhiteSpace and throws ArgumentNullException naming volumeName when the desired label is null, empty, or whitespace, because the native API cannot be given an empty label through this overload.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/Volume.VolumeLabel.cs:71

      /// <param name="volumePath">
      ///   A path to a volume. For example: "C:\", "\\server\share", or "\\?\Volume{c0580d5e-2ad6-11dc-9924-806e6f6e6963}\".
      /// </param>
      /// <returns>The the label of the file system volume. This function can return <c>string.Empty</c> since a volume label is generally not mandatory.</returns>
      [SecurityCritical]
      public static string GetVolumeLabel(string volumePath)
      {
         return new VolumeInfo(volumePath, true, true).Name;
      }


      /// <summary>[AlphaFS] Sets the label of the file system volume that is the root of the current directory.</summary>
      /// <exception cref="ArgumentNullException"/>
      /// <param name="volumeName">A name for the volume.</param>
      [SecurityCritical]
      public static void SetCurrentVolumeLabel(string volumeName)
      {
         if (Utils.IsNullOrWhiteSpace(volumeName))
            throw new ArgumentNullException("volumeName");


         var success = NativeMethods.SetVolumeLabel(null, volumeName);

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


      /// <summary>[AlphaFS] Sets the label of a file system volume.</summary>
      /// <param name="volumePath">
      ///   <para>A path to a volume. For example: "C:\", "\\server\share", or "\\?\Volume{c0580d5e-2ad6-11dc-9924-806e6f6e6963}\"</para>
      ///   <para>If this parameter is <c>null</c>, the function uses the current drive.</para>
      /// </param>
      /// <param name="volumeName">
      ///   <para>A name for the volume.</para>
      ///   <para>If this parameter is <c>null</c>, the function deletes any existing label</para>

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a non-empty label string, e.g. Volume.SetCurrentVolumeLabel("BACKUP").
  2. To remove a label, call Volume.DeleteVolumeLabel(rootPathName) instead of passing null/empty here.
  3. Trim and validate user-supplied labels before calling; retry with a placeholder label if clearing was the intent.

Example fix

// before
string label = userInput; // may be ""
Volume.SetCurrentVolumeLabel(label);
// after
string label = userInput;
if (string.IsNullOrWhiteSpace(label))
    Volume.DeleteVolumeLabel(Directory.GetCurrentDirectory().Substring(0, 3));
else
    Volume.SetCurrentVolumeLabel(label.Trim());
Defensive patterns

Strategy: validation

Validate before calling

if (!string.IsNullOrWhiteSpace(volumeName))
{
    Volume.SetCurrentVolumeLabel(volumeName.Trim());
}

Type guard

static bool IsValidLabel(string s) => !string.IsNullOrWhiteSpace(s) && s.Length <= 32;

Try / catch

try { Volume.SetCurrentVolumeLabel(label); }
catch (ArgumentNullException ex) when (ex.ParamName == "volumeName")
{
    // empty label supplied; fall back to DeleteVolumeLabel or prompt user
}

Prevention

When it happens

Trigger: Calling Volume.SetCurrentVolumeLabel(null), SetCurrentVolumeLabel(""), or whitespace; assigning a label sourced from an empty TextBox, missing config key, or an unset environment variable.

Common situations: Clearing a volume label by passing an empty string (use DeleteVolumeLabel or SetVolumeLabel with null instead); UI form submitted without input; serialization produced an empty string property.

Related errors


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