hashicorp/nomad · error

failed to convert user domain to UTF-16

Error message

failed to convert user domain to UTF-16: %w

What it means

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.

Solutions

  1. Inspect the domain portion of the user value for embedded NUL/control characters and fix its source.
  2. Sanitize the domain string to printable characters before executor setup.
  3. Correct the task user format, e.g. 'DOMAIN\\user'.

Example fix

// before
user = "CORP\x00\\appuser"
// after
user = "CORP\\appuser"
Defensive patterns

Strategy: validation

Validate before calling

// Go: reject domains containing NUL before calling the executor
if strings.ContainsRune(domain, 0) {
    return errors.New("domain must not contain NUL bytes")
}

Type guard

func utf16Safe(s string) bool {
    _, err := syscall.UTF16PtrFromString(s)
    return err == nil
}

Try / catch

if err := exec.SetUser(cmd, user); err != nil {
    if strings.Contains(err.Error(), "convert user domain to UTF-16") {
        return fmt.Errorf("malformed domain in user value %q", user)
    }
    return err
}

Prevention

When it happens

Trigger: The domain string (nameParts[0] after splitting user on '\\') contains a NUL character.

Common situations: Same as the username variant: corrupted or programmatically mangled user strings; binary contamination in config from a template or plugin.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/8bbfb3af12e0064f. Report an issue: GitHub.

Appendix: source

Thrown at drivers/shared/executor/executor_windows.go:88

var (
	advapiDll      = windows.NewLazySystemDLL("advapi32.dll")
	procLogonUserW = advapiDll.NewProc("LogonUserW")
)

const (
	_LOGON_SERVICE    uint32 = 5
	_PROVIDER_DEFAULT uint32 = 0
)

func createUserToken(domain, username string) (*syscall.Token, error) {
	userw, err := syscall.UTF16PtrFromString(username)
	if err != nil {
		return nil, fmt.Errorf("failed to convert username to UTF-16: %w", err)
	}
	domainw, err := syscall.UTF16PtrFromString(domain)
	if err != nil {
		return nil, fmt.Errorf("failed to convert user domain to UTF-16: %w", err)
	}
	var token syscall.Token
	ret, _, e := procLogonUserW.Call(
		uintptr(unsafe.Pointer(userw)),
		uintptr(unsafe.Pointer(domainw)),
		uintptr(unsafe.Pointer(nil)),
		uintptr(_LOGON_SERVICE),
		uintptr(_PROVIDER_DEFAULT),
		uintptr(unsafe.Pointer(&token)),
	)
	if ret == 0 {
		return nil, e
	}

	return &token, nil
}

func (e *UniversalExecutor) ListProcesses() set.Collection[int] {

View on GitHub (pinned to 482b49bf1a)