{"record":{"id":"2afc1a34bb3a7558","repo":"siyuan-note/siyuan","slug":"variable-q-contains-nul","errorCode":null,"errorMessage":"variable %q contains NUL","messagePattern":"variable %q contains NUL","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/mcp/client/mcp.go","lineNumber":562,"sourceCode":"func validateMCPServerEnvironment(server conf.MCPServer, goos string) error {\n\tinherited := map[string]bool{}\n\tfor _, name := range server.InheritEnv {\n\t\tif err := validateEnvironmentName(name); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tkey := environmentKey(name, goos)\n\t\tif inherited[key] {\n\t\t\treturn fmt.Errorf(\"duplicate inherited variable %q\", name)\n\t\t}\n\t\tinherited[key] = true\n\t}\n\texplicit := map[string]bool{}\n\tfor name, value := range server.Env {\n\t\tif err := validateEnvironmentName(name); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif strings.ContainsRune(value, '\\x00') {\n\t\t\treturn fmt.Errorf(\"variable %q contains NUL\", name)\n\t\t}\n\t\tkey := environmentKey(name, goos)\n\t\tif explicit[key] {\n\t\t\treturn fmt.Errorf(\"duplicate variable %q\", name)\n\t\t}\n\t\texplicit[key] = true\n\t}\n\treturn nil\n}\n\n// ValidateMCPServerEnvironment 校验当前平台上的 stdio 环境变量配置。\nfunc ValidateMCPServerEnvironment(server conf.MCPServer) error {\n\treturn validateMCPServerEnvironment(server, runtime.GOOS)\n}\n\nfunc defaultMCPEnvironmentNames(goos string) []string {\n\tif goos == \"windows\" {\n\t\treturn []string{\"APPDATA\", \"HOMEDRIVE\", \"HOMEPATH\", \"LOCALAPPDATA\", \"PATH\", \"PATHEXT\",","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/mcp/client/mcp.go#L544-L580","documentation":"Validation error from validateMCPServerEnvironment: an explicit Env value contains a NUL byte (\\x00). NUL cannot appear in a C environ entry and would silently truncate the value when passed to the child. The offending variable name is quoted via %q so you can locate it.","triggerScenarios":"Iterating server.Env, validateMCPServerEnvironment runs strings.ContainsRune(value, '\\x00') on each value; if a value contains a NUL byte, this error is returned for the corresponding name.","commonSituations":"Value was read from a binary file or pasted from a terminal that embedded a control character; secret material loaded from a corrupted credential store; mistaken use of a byte slice containing a trailing NUL (e.g. C-go interop residue).","solutions":["Locate the variable named in the error message and rewrite its value without NUL bytes.","If the value comes from model.Conf.Secrets / Variables via ResolveSecretsVars, inspect the source of that secret for corruption.","Strip NUL bytes programmatically before writing the config: strings.ReplaceAll(value, \"\\x00\", \"\")."],"exampleFix":"// before (value contains a stray NUL)\n\"env\": {\"TOKEN\": \"abc\\u0000def\"}\n// after\n\"env\": {\"TOKEN\": \"abcdef\"}","handlingStrategy":"validation","validationCode":"import \"strings\"\nfunc sanitizeEnvValue(v string) string {\n    return strings.ReplaceAll(v, \"\\x00\", \"\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit secret sources for embedded NUL bytes.","Sanitize values read from external stores before assigning to Env."],"tags":["mcp","environment","config-validation","data-integrity"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}