{"record":{"id":"7ae16ea68cef3bd2","repo":"peass-ng/PEASS-ng","slug":"devicename","errorCode":null,"errorMessage":"deviceName","messagePattern":"deviceName","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/Volume.DefineDosDevice.cs","lineNumber":85,"sourceCode":"      ///   An MS-DOS device name string specifying the device the function is defining, redefining, or deleting.\n      /// </param>\n      /// <param name=\"targetPath\">\n      ///   A pointer to a path string that will implement this device. The string is an MS-DOS path string unless the\n      ///   <see cref=\"DosDeviceAttributes.RawTargetPath\"/> flag is specified, in which case this string is a path string.\n      /// </param>\n      /// <param name=\"deviceAttributes\">\n      ///   The controllable aspects of the DefineDosDevice function, <see cref=\"DosDeviceAttributes\"/> flags which will be combined with the\n      ///   default.\n      /// </param>\n      /// <param name=\"exactMatch\">\n      ///   Only delete MS-DOS device on an exact name match. If <paramref name=\"exactMatch\"/> is <c>true</c>,\n      ///   <paramref name=\"targetPath\"/> must be the same path used to create the mapping.\n      /// </param>\n      [SecurityCritical]\n      internal static void DefineDosDeviceCore(bool isDefine, string deviceName, string targetPath, DosDeviceAttributes deviceAttributes, bool exactMatch)\n      {\n         if (Utils.IsNullOrWhiteSpace(deviceName))\n            throw new ArgumentNullException(\"deviceName\");\n\n         if (isDefine)\n         {\n            // targetPath is allowed to be null.\n\n            // In no case is a trailing backslash (\"\\\") allowed.\n            deviceName = Path.GetRegularPathCore(deviceName, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars, false);\n\n            using (new NativeMethods.ChangeErrorMode(NativeMethods.ErrorMode.FailCriticalErrors))\n            {\n               var success = NativeMethods.DefineDosDevice(deviceAttributes, deviceName, targetPath);\n\n               var lastError = Marshal.GetLastWin32Error();\n               if (!success)\n                  NativeError.ThrowException(lastError, deviceName, targetPath);\n            }\n         }\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/Volume.DefineDosDevice.cs#L67-L103","documentation":"AlphaFS DefineDosDeviceCore (used by DefineDosDevice and DeleteDosDevice) throws ArgumentNullException with param name 'deviceName' when the DOS device name is null, empty, or whitespace. DefineDosDevice maps a device name (e.g. 'X:') to a target path, so the name is mandatory.","triggerScenarios":"DefineDosDevice(...) or DeleteDosDevice(...) with a null/empty deviceName — e.g. an unset drive-letter variable, empty UI field, or a lookup that returned nothing.","commonSituations":"Automating drive mapping where the chosen letter variable was never assigned; config value blank; calling DeleteDosDevice with the wrong parameter order or an empty string from string.Split.","solutions":["Ensure deviceName is a non-empty name like 'X:' before calling; check string.IsNullOrWhiteSpace first","Verify variable assignment/order of arguments (targetPath is allowed to be null for define, deviceName is not)","Fix the source of the empty value (UI field, config key, lookup result)","Pick a free drive letter (e.g. via GetFreeDriveLetter) before mapping instead of passing an unset variable"],"exampleFix":"// before\nAlphaFS.Device.Volume.DefineDosDevice(freeLetter, targetPath); // freeLetter was null\n// after\nif (string.IsNullOrWhiteSpace(freeLetter))\n    freeLetter = DriveInfo.GetFreeDriveLetter() + \":\";\nAlphaFS.Device.Volume.DefineDosDevice(freeLetter, targetPath);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(deviceName))\n    throw new ArgumentException(\"deviceName is required, e.g. \\\"X:\\\"\");\nAlphaFS.Device.Volume.DefineDosDevice(deviceName, targetPath);","typeGuard":"static bool IsValidDosDeviceName(string n) =>\n    !string.IsNullOrWhiteSpace(n) && n.Trim().Length >= 2;","tryCatchPattern":"try { AlphaFS.Device.Volume.DefineDosDevice(deviceName, targetPath); }\ncatch (ArgumentNullException ex) { log.Error(\"deviceName was null/empty\", ex); }","preventionTips":["Assign a real drive letter (e.g. via GetFreeDriveLetter) before mapping","Double-check argument order — targetPath may be null for define, deviceName may not","Validate config/UI values before calling DefineDosDevice/DeleteDosDevice"],"tags":["csharp","argument-null","alphafs","dos-device"],"backgroundTag":"null-argument","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}