{"record":{"id":"249749a3907ba895","repo":"peass-ng/PEASS-ng","slug":"volumename","errorCode":null,"errorMessage":"volumeName","messagePattern":"volumeName","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/Volume.VolumeLabel.cs","lineNumber":71,"sourceCode":"      /// <param name=\"volumePath\">\n      ///   A path to a volume. For example: \"C:\\\", \"\\\\server\\share\", or \"\\\\?\\Volume{c0580d5e-2ad6-11dc-9924-806e6f6e6963}\\\".\n      /// </param>\n      /// <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>\n      [SecurityCritical]\n      public static string GetVolumeLabel(string volumePath)\n      {\n         return new VolumeInfo(volumePath, true, true).Name;\n      }\n\n\n      /// <summary>[AlphaFS] Sets the label of the file system volume that is the root of the current directory.</summary>\n      /// <exception cref=\"ArgumentNullException\"/>\n      /// <param name=\"volumeName\">A name for the volume.</param>\n      [SecurityCritical]\n      public static void SetCurrentVolumeLabel(string volumeName)\n      {\n         if (Utils.IsNullOrWhiteSpace(volumeName))\n            throw new ArgumentNullException(\"volumeName\");\n\n\n         var success = NativeMethods.SetVolumeLabel(null, volumeName);\n\n         var lastError = Marshal.GetLastWin32Error();\n         if (!success)\n            NativeError.ThrowException(lastError, volumeName);\n      }\n\n\n      /// <summary>[AlphaFS] Sets the label of a file system volume.</summary>\n      /// <param name=\"volumePath\">\n      ///   <para>A path to a volume. For example: \"C:\\\", \"\\\\server\\share\", or \"\\\\?\\Volume{c0580d5e-2ad6-11dc-9924-806e6f6e6963}\\\"</para>\n      ///   <para>If this parameter is <c>null</c>, the function uses the current drive.</para>\n      /// </param>\n      /// <param name=\"volumeName\">\n      ///   <para>A name for the volume.</para>\n      ///   <para>If this parameter is <c>null</c>, the function deletes any existing label</para>","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/Volume.VolumeLabel.cs#L53-L89","documentation":"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.","triggerScenarios":"Calling Volume.SetCurrentVolumeLabel(null), SetCurrentVolumeLabel(\"\"), or whitespace; assigning a label sourced from an empty TextBox, missing config key, or an unset environment variable.","commonSituations":"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.","solutions":["Pass a non-empty label string, e.g. Volume.SetCurrentVolumeLabel(\"BACKUP\").","To remove a label, call Volume.DeleteVolumeLabel(rootPathName) instead of passing null/empty here.","Trim and validate user-supplied labels before calling; retry with a placeholder label if clearing was the intent."],"exampleFix":"// before\nstring label = userInput; // may be \"\"\nVolume.SetCurrentVolumeLabel(label);\n// after\nstring label = userInput;\nif (string.IsNullOrWhiteSpace(label))\n    Volume.DeleteVolumeLabel(Directory.GetCurrentDirectory().Substring(0, 3));\nelse\n    Volume.SetCurrentVolumeLabel(label.Trim());","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrWhiteSpace(volumeName))\n{\n    Volume.SetCurrentVolumeLabel(volumeName.Trim());\n}","typeGuard":"static bool IsValidLabel(string s) => !string.IsNullOrWhiteSpace(s) && s.Length <= 32;","tryCatchPattern":"try { Volume.SetCurrentVolumeLabel(label); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"volumeName\")\n{\n    // empty label supplied; fall back to DeleteVolumeLabel or prompt user\n}","preventionTips":["Trim user input before assigning a volume label","Remember null/empty means 'clear label' — use DeleteVolumeLabel for that intent","Validate labels from UI/config before calling native volume APIs","Cap label length to the file-system limit (32 chars NTFS)"],"tags":["csharp","alphafs","argument-null","filesystem"],"backgroundTag":"null-or-empty-argument","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}