{"record":{"id":"d0fac8d0a1eaec0d","repo":"peass-ng/PEASS-ng","slug":"resources-invaliddriveletterargument","errorCode":null,"errorMessage":"Resources.InvalidDriveLetterArgument","messagePattern":"Resources\\.InvalidDriveLetterArgument","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/DiskSpaceInfo.cs","lineNumber":59,"sourceCode":"      [NonSerialized] private readonly CultureInfo _cultureInfo = CultureInfo.CurrentCulture;\n      [NonSerialized] private readonly bool _continueOnAccessError;\n\n\n      /// <summary>Initializes a DiskSpaceInfo instance.</summary>\n      /// <param name=\"drivePath\">A valid drive path or drive letter. This can be either uppercase or lowercase, 'a' to 'z' or a network share in the format: \\\\server\\share</param>\n      /// <Remark>This is a Lazyloading object; call <see cref=\"Refresh()\"/> to populate all properties first before accessing.</Remark>\n      [SuppressMessage(\"Microsoft.Design\", \"CA1062:Validate arguments of public methods\", MessageId = \"0\", Justification = \"Utils.IsNullOrWhiteSpace validates arguments.\")]\n      [SecurityCritical]\n      public DiskSpaceInfo(string drivePath)\n      {\n         if (Utils.IsNullOrWhiteSpace(drivePath))\n            throw new ArgumentNullException(\"drivePath\");\n\n\n         drivePath = drivePath.Length == 1 ? drivePath + Path.VolumeSeparatorChar : Path.GetPathRoot(drivePath, false);\n\n         if (Utils.IsNullOrWhiteSpace(drivePath))\n            throw new ArgumentException(Resources.InvalidDriveLetterArgument, \"drivePath\");\n\n\n         // MSDN:\n         // If this parameter is a UNC name, it must include a trailing backslash (for example, \"\\\\MyServer\\MyShare\\\").\n         // Furthermore, a drive specification must have a trailing backslash (for example, \"C:\\\").\n         // The calling application must have FILE_LIST_DIRECTORY access rights for this directory.\n         DriveName = Path.AddTrailingDirectorySeparator(drivePath, false);\n      }\n\n      \n      /// <summary>Initializes a DiskSpaceInfo instance.</summary>\n      /// <param name=\"drivePath\">A valid drive path or drive letter. This can be either uppercase or lowercase, 'a' to 'z' or a network share in the format: \\\\server\\share</param>\n      /// <param name=\"spaceInfoType\"><c>null</c> gets both size- and disk cluster information. <c>true</c> Get only disk cluster information, <c>false</c> Get only size information.</param>\n      /// <param name=\"refresh\">Refreshes the state of the object.</param>\n      /// <param name=\"continueOnException\"><c>true</c> suppress any Exception that might be thrown as a result from a failure, such as unavailable resources.</param>\n      [SecurityCritical]\n      public DiskSpaceInfo(string drivePath, bool? spaceInfoType, bool refresh, bool continueOnException) : this(drivePath)\n      {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/DiskSpaceInfo.cs#L41-L77","documentation":"After normalizing the input (single letter gets VolumeSeparatorChar appended, otherwise GetPathRoot is applied), DiskSpaceInfo throws ArgumentException with Resources.InvalidDriveLetterArgument when the normalized path is still null/empty — i.e. the string was non-blank but not a real drive path. GetPathRoot returns empty for malformed inputs like \":::\" on some .NET versions.","triggerScenarios":"new DiskSpaceInfo(\"C\") without separator is OK, but new DiskSpaceInfo(\":\\\\\"), new DiskSpaceInfo(\"123\"), or a UNC/relative path from which GetPathRoot yields an empty root triggers this.","commonSituations":"Users pass 'C:' without backslash in environments where GetPathRoot can't resolve it, pass a device path like \\\\.\\PhysicalDrive0 that GetPathRoot mangles, or pass a URL/relative folder path instead of a drive root.","solutions":["Pass a proper drive root such as 'C:\\\\' or 'C:' (single letters are auto-completed)","Validate with Path.GetPathRoot(path) and check it is non-empty before constructing","Strip invalid characters from user input before passing it","For UNC shares include the full '\\\\\\\\server\\\\share\\\\' form"],"exampleFix":"// before\nvar dsi = new DiskSpaceInfo(pathBox.Text.Trim()); // e.g. \"download folder\"\n// after\nvar root = Path.GetPathRoot(pathBox.Text.Trim());\nif (string.IsNullOrEmpty(root))\n    throw new ArgumentException(\"Enter a valid drive root like C:\\\\\\\\.\");\nvar dsi = new DiskSpaceInfo(root);","handlingStrategy":"type-guard","validationCode":"var root = Path.GetPathRoot(drivePath);\nif (string.IsNullOrEmpty(root))\n    throw new ArgumentException(\"Not a valid drive root: \" + drivePath);\nvar dsi = new DiskSpaceInfo(root);","typeGuard":"static bool IsDriveRoot(string p)\n{\n    if (string.IsNullOrWhiteSpace(p)) return false;\n    var root = Path.GetPathRoot(p.Length == 1 ? p + \":\" : p);\n    return !string.IsNullOrEmpty(root);\n}","tryCatchPattern":"try { var dsi = new DiskSpaceInfo(drivePath); }\ncatch (ArgumentException ex) { log.Error(\"Invalid drive letter/path: \" + drivePath, ex); }","preventionTips":["Pass drive roots ('C:\\\\'), not folders or labels","Normalize input through Path.GetPathRoot first","For UNC paths include the full \\\\\\\\server\\\\share\\\\ form","Validate user input against a drive-letter pattern like ^[A-Za-z]:?$"],"tags":["csharp","argument-exception","alphafs","drive-path"],"backgroundTag":"invalid-drive-path","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}