{"record":{"id":"8bbfb3af12e0064f","repo":"hashicorp/nomad","slug":"failed-to-convert-user-domain-to-utf-16-w","errorCode":null,"errorMessage":"failed to convert user domain to UTF-16: %w","messagePattern":"failed to convert user domain to UTF-16: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/shared/executor/executor_windows.go","lineNumber":88,"sourceCode":"\nvar (\n\tadvapiDll      = windows.NewLazySystemDLL(\"advapi32.dll\")\n\tprocLogonUserW = advapiDll.NewProc(\"LogonUserW\")\n)\n\nconst (\n\t_LOGON_SERVICE    uint32 = 5\n\t_PROVIDER_DEFAULT uint32 = 0\n)\n\nfunc createUserToken(domain, username string) (*syscall.Token, error) {\n\tuserw, err := syscall.UTF16PtrFromString(username)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to convert username to UTF-16: %w\", err)\n\t}\n\tdomainw, err := syscall.UTF16PtrFromString(domain)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to convert user domain to UTF-16: %w\", err)\n\t}\n\tvar token syscall.Token\n\tret, _, e := procLogonUserW.Call(\n\t\tuintptr(unsafe.Pointer(userw)),\n\t\tuintptr(unsafe.Pointer(domainw)),\n\t\tuintptr(unsafe.Pointer(nil)),\n\t\tuintptr(_LOGON_SERVICE),\n\t\tuintptr(_PROVIDER_DEFAULT),\n\t\tuintptr(unsafe.Pointer(&token)),\n\t)\n\tif ret == 0 {\n\t\treturn nil, e\n\t}\n\n\treturn &token, nil\n}\n\nfunc (e *UniversalExecutor) ListProcesses() set.Collection[int] {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/shared/executor/executor_windows.go#L70-L106","documentation":"createUserToken converts the domain portion of 'DOMAIN\\\\user' to a UTF-16 pointer for LogonUserW. syscall.UTF16PtrFromString fails if the domain string contains an interior NUL byte, so token creation aborts before calling LogonUser.","triggerScenarios":"The domain string (nameParts[0] after splitting user on '\\\\') contains a NUL character.","commonSituations":"Same as the username variant: corrupted or programmatically mangled user strings; binary contamination in config from a template or plugin.","solutions":["Inspect the domain portion of the user value for embedded NUL/control characters and fix its source.","Sanitize the domain string to printable characters before executor setup.","Correct the task user format, e.g. 'DOMAIN\\\\user'."],"exampleFix":"// before\nuser = \"CORP\\x00\\\\appuser\"\n// after\nuser = \"CORP\\\\appuser\"","handlingStrategy":"validation","validationCode":"// Go: reject domains containing NUL before calling the executor\nif strings.ContainsRune(domain, 0) {\n    return errors.New(\"domain must not contain NUL bytes\")\n}","typeGuard":"func utf16Safe(s string) bool {\n    _, err := syscall.UTF16PtrFromString(s)\n    return err == nil\n}","tryCatchPattern":"if err := exec.SetUser(cmd, user); err != nil {\n    if strings.Contains(err.Error(), \"convert user domain to UTF-16\") {\n        return fmt.Errorf(\"malformed domain in user value %q\", user)\n    }\n    return err\n}","preventionTips":["Enforce the 'DOMAIN\\\\user' format with a regex at submission.","Sanitize templated values (strip control chars) before they reach the executor.","Unit-test user-string parsing with edge-case inputs."],"tags":["windows","utf-16","encoding","logonuser"],"backgroundTag":"string-encoding-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}