{"record":{"id":"16a8caec5b95df0b","repo":"OpenNHP/opennhp","slug":"nhp-server-length-is-too-long","errorCode":null,"errorMessage":"nhp server length is too long","messagePattern":"nhp server length is too long","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/core/ztdo/ztdo.go","lineNumber":121,"sourceCode":"\t// generate uuid\n\tuuid := uuid.New()\n\theader.ObjectID = [ObjectIDSize]byte(uuid)\n\n\t// User first 4 bytes to set magic number\n\theader.MagicNumber = [MagicNumberSize]byte(uuid[0:4])\n}\n\nfunc (header *ZtdoHeader) GetObjectID() string {\n\treturn uuid.UUID(header.ObjectID).String()\n}\n\nfunc (header *ZtdoHeader) SetVersion() {\n\theader.Version = [VersionSize]byte{0x00, 0x01}\n}\n\nfunc (header *ZtdoHeader) SetNhpServer(nhpServer string) error {\n\tif len(nhpServer) > NhpServerMaxSize {\n\t\treturn fmt.Errorf(\"nhp server length is too long\")\n\t}\n\n\theader.NhpServerLen[0] = byte(len(nhpServer))\n\theader.NhpServer = []byte(nhpServer)\n\n\treturn nil\n}\n\n// SetMetadata supports variable length of metadata\nfunc (header *ZtdoHeader) SetMetadata(metadata string) error {\n\theader.Metadata = []ZtdoMetadata{}\n\n\ttotalLen := len(metadata)\n\tchunkNum := totalLen / MetadataChunkMaxSize\n\n\tfor i := 0; i < chunkNum; i++ {\n\t\tchunk := metadata[i*MetadataChunkMaxSize : (i+1)*MetadataChunkMaxSize]\n\t\tchunkEncodedLen, err := encodeMetadataLength(len(chunk), true)","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/core/ztdo/ztdo.go#L103-L139","documentation":"SetNhpServer stores the NHP server identity into the ZtdoHeader. The header reserves a single byte (NhpServerLen) for the server string length, capping it at NhpServerMaxSize bytes. Longer strings return this error instead of silently truncating.","triggerScenarios":"Calling ZtdoHeader.SetNhpServer with a string longer than NhpServerMaxSize bytes (nhp/core/ztdo/ztdo.go:121). Called from runApp and recursively via SetNhpServer wrappers.","commonSituations":"Configuring long FQDNs or \"host:port\" with IPv6 literal addresses exceeding the byte limit; concatenating scheme + host + port into the server field.","solutions":["Shorten the nhp server string (use a shorter hostname; check it against NhpServerMaxSize bytes, not characters)","Move port/scheme out of the field if possible","Validate the length before constructing the header and fail config load early with a clearer message"],"exampleFix":"// before\nif len(nhpServer) > NhpServerMaxSize {\n\treturn fmt.Errorf(\"nhp server length is too long\")\n}\n// after\nif len(nhpServer) > NhpServerMaxSize {\n\treturn fmt.Errorf(\"nhp server %q is %d bytes, max is %d\", nhpServer, len(nhpServer), NhpServerMaxSize)\n}","handlingStrategy":"validation","validationCode":"if len(nhpServer) > NhpServerMaxSize {\n\treturn fmt.Errorf(\"nhp server must be at most %d bytes, got %d\", NhpServerMaxSize, len(nhpServer))\n}","typeGuard":null,"tryCatchPattern":"if err := header.SetNhpServer(server); err != nil {\n\tif strings.Contains(err.Error(), \"nhp server length is too long\") {\n\t\t// shorten hostname or reject config\n\t}\n\treturn err\n}","preventionTips":["Validate server string length (in bytes) at config load time","Use short hostnames; avoid embedding scheme and port in the field","Watch IPv6 literals, which consume many bytes"],"tags":["go","validation","protocol","ztdo"],"backgroundTag":"value-out-of-range","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}