{"record":{"id":"b3820ed8bfa8eef0","repo":"peass-ng/PEASS-ng","slug":"path-b3820e","errorCode":null,"errorMessage":"path","messagePattern":"path","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.CreateDirectoryCore.cs","lineNumber":64,"sourceCode":"      /// <exception cref=\"IOException\"/>\n      /// <exception cref=\"NotSupportedException\"/>\n      /// <exception cref=\"UnauthorizedAccessException\"/>\n      /// <param name=\"returnNull\">When <c>true</c> returns <c>null</c> instead of a <see cref=\"DirectoryInfo\"/> instance.</param>\n      /// <param name=\"transaction\">The transaction.</param>\n      /// <param name=\"path\">The directory to create.</param>\n      /// <param name=\"templatePath\">The path of the directory to use as a template when creating the new directory. May be <c>null</c> to indicate that no template should be used.</param>\n      /// <param name=\"directorySecurity\">The <see cref=\"DirectorySecurity\"/> access control to apply to the directory, may be null.</param>\n      /// <param name=\"compress\">When <c>true</c> compresses the directory using NTFS compression.</param>\n      /// <param name=\"pathFormat\">Indicates the format of the path parameter(s).</param>\n      [SecurityCritical]\n      internal static DirectoryInfo CreateDirectoryCore(bool returnNull, KernelTransaction transaction, string path, string templatePath, ObjectSecurity directorySecurity, bool compress, PathFormat pathFormat)\n      {\n         var longPath = path;\n\n         if (pathFormat != PathFormat.LongFullPath)\n         {\n            if (null == path)\n               throw new ArgumentNullException(\"path\");\n\n\n            Path.CheckSupportedPathFormat(path, true, true);\n            Path.CheckSupportedPathFormat(templatePath, true, true);\n\n            longPath = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator);\n\n            pathFormat = PathFormat.LongFullPath;\n         }\n\n\n         if (!char.IsWhiteSpace(longPath[longPath.Length - 1]))\n         {\n            // Return DirectoryInfo instance if the directory specified by path already exists.\n\n            if (File.ExistsCore(transaction, true, longPath, PathFormat.LongFullPath))\n\n               // We are not always interested in a new DirectoryInfo instance.","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.CreateDirectoryCore.cs#L46-L82","documentation":"AlphaFS's Directory.CreateDirectoryCore validates the input path before touching the filesystem. When the path argument is null and the caller did not request LongFullPath format, it throws ArgumentNullException('path'). The library requires a non-null path string (or PathFormat.LongFullPath to skip normalization, which still needs a valid path downstream).","triggerScenarios":"Calling Directory.CreateDirectory / CreateDirectoryTransacted / CreateJunction (which funnel into CreateDirectoryCore) with a null path string while using the default PathFormat (LongFullPath-less) overload.","commonSituations":"Path assembled from config/appsettings where a key is missing; null return from Environment.GetFolderPath or a lookup; passing an uninitialized variable or a nullable path that was never coalesced; refactored code that dropped a default value.","solutions":["Ensure the path argument is non-null before calling: if (string.IsNullOrEmpty(path)) throw/return or supply a default.","Coalesce nulls at the call site: path ?? defaultPath.","Guard the source of the path (config read, registry, user input) and fail fast with a clear message instead of reaching the library.","If you intentionally pass raw paths, use the PathFormat.LongFullPath overload only with a genuinely non-null path."],"exampleFix":"// before\nDirectory.CreateDirectory(myConfig.Path);\n// after\nif (string.IsNullOrWhiteSpace(myConfig.Path))\n    throw new InvalidOperationException(\"Config 'Path' is not set\");\nDirectory.CreateDirectory(myConfig.Path);","handlingStrategy":"validation","validationCode":"if (path == null)\n    throw new ArgumentNullException(nameof(path));\nif (string.IsNullOrWhiteSpace(path))\n    throw new ArgumentException(\"Path must not be empty\", nameof(path));\nDirectory.CreateDirectory(path);","typeGuard":"static bool IsValidPathArg(string p) => !string.IsNullOrWhiteSpace(p);","tryCatchPattern":"try\n{\n    Directory.CreateDirectory(path);\n}\ncatch (ArgumentNullException ex)\n{\n    // ex.ParamName == \"path\": caller supplied a null path\n    logger.LogError(ex, \"CreateDirectory called with null path\");\n}","preventionTips":["Never pass nullable strings straight into path APIs; coalesce or throw at the boundary.","Validate configuration at startup so missing path keys fail before use.","Enable nullable reference types (C# 8+) so null paths are caught at compile time.","Centralize directory-creation in a helper that guards empty/null."],"tags":["argumentnull","path-validation","alphafs","dotnet"],"backgroundTag":"null-path-argument","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}