{"record":{"id":"624d94bd309ba8e6","repo":"jdx/mise","slug":"history-directory-contains-a-nul-character","errorCode":null,"errorMessage":"history directory contains a NUL character","messagePattern":"history directory contains a NUL character","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/store.rs","lineNumber":144,"sourceCode":"    let sddl: Vec<u16> = \"D:P(A;OICI;FA;;;OW)\\0\".encode_utf16().collect();\n    let mut descriptor = std::ptr::null_mut();\n    // SAFETY: both pointers are valid for the call; Windows allocates the\n    // descriptor, released with LocalFree below on every path.\n    if unsafe {\n        ConvertStringSecurityDescriptorToSecurityDescriptorW(\n            sddl.as_ptr(),\n            1,\n            &mut descriptor,\n            std::ptr::null_mut(),\n        )\n    } == 0\n    {\n        return Err(std::io::Error::last_os_error().into());\n    }\n    let result = (|| -> Result<()> {\n        let mut path: Vec<u16> = dir.as_os_str().encode_wide().collect();\n        if path.contains(&0) {\n            eyre::bail!(\"history directory contains a NUL character\");\n        }\n        path.push(0);\n        let attributes = SECURITY_ATTRIBUTES {\n            nLength: std::mem::size_of::<SECURITY_ATTRIBUTES>() as u32,\n            lpSecurityDescriptor: descriptor,\n            bInheritHandle: 0,\n        };\n        if !dir.is_dir()\n            // SAFETY: path is NUL-terminated and attributes/descriptor remain live.\n            && unsafe { CreateDirectoryW(path.as_ptr(), &attributes) } == 0\n            && !dir.is_dir()\n        {\n            return Err(std::io::Error::last_os_error().into());\n        }\n        // Also tighten an existing directory instead of trusting inherited ACLs.\n        // SAFETY: path and descriptor are valid until the call returns.\n        if unsafe {\n            SetFileSecurityW(","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/store.rs#L126-L162","documentation":"On Windows, mise creates the history directory with restricted ACLs via Win32 APIs. Before calling the API it encodes the directory path as UTF-16; if the path contains an interior NUL character, the Win32 string would be silently truncated, so mise rejects it up front with this io-like error. Interior NULs indicate a corrupted or malformed path.","triggerScenarios":"Resolving the history directory path from configuration/environment on Windows when the computed path string contains an embedded NUL byte (e.g. corrupted env var or misbuilt path buffer).","commonSituations":"A MISE_DATA_DIR / XDG-style env var corrupted on Windows; a programmatic caller constructing a path from a buffer that retained a NUL terminator; registry or env corruption.","solutions":["Check the environment variables that determine the data/state dir on Windows (`MISE_DATA_DIR`, `LOCALAPPDATA`) for corruption.","Re-set the variable from a clean shell: `setx MISE_DATA_DIR \"%LOCALAPPDATA%\\mise\"`.","If the path is built programmatically, trim at the first NUL before passing it in.","Restart the shell to pick up non-corrupted environment."],"exampleFix":"// before: corrupted env value with embedded NUL\nset MISE_DATA_DIR=C:\\Users\\me\\AppData\\Local\\mis<0x00>e\n\n// after\nsetx MISE_DATA_DIR \"%LOCALAPPDATA%\\mise\"","handlingStrategy":"validation","validationCode":"// Windows: reject interior NULs before invoking Win32 APIs\nlet wide: Vec<u16> = dir.as_os_str().encode_wide().collect();\nif wide.contains(&0) {\n  eprintln!(\"history directory path contains NUL; fix MISE_DATA_DIR/env\");\n}","typeGuard":"fn path_is_nul_free(dir: &Path) -> bool {\n  use std::os::windows::ffi::OsStrExtW;\n  !dir.as_os_str().encode_wide().any(|c| c == 0)\n}","tryCatchPattern":"match result {\n  Err(e) if e.to_string().contains(\"NUL character\") => {\n    // repair the environment variable that produced the path\n  }\n  other => other?,\n}","preventionTips":["Keep MISE_DATA_DIR/LOCALAPPDATA set to plain, valid Windows paths.","Trim at the first NUL when building paths from raw buffers.","Re-open shells after changing environment variables."],"tags":["windows","path","history","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}