{"record":{"id":"45c1a1ef6a2a122f","repo":"jackc/pgx","slug":"bad-startup-message-last-byte-expected-0-got-d","errorCode":null,"errorMessage":"Bad startup message last byte. Expected 0, got %d","messagePattern":"Bad startup message last byte\\. Expected 0, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgproto3/startup_message.go","lineNumber":62,"sourceCode":"\t\tidx := bytes.IndexByte(src[rp:], 0)\n\t\tif idx < 0 {\n\t\t\treturn &invalidMessageFormatErr{messageType: \"StartupMessage\"}\n\t\t}\n\t\tkey := string(src[rp : rp+idx])\n\t\trp += idx + 1\n\n\t\tidx = bytes.IndexByte(src[rp:], 0)\n\t\tif idx < 0 {\n\t\t\treturn &invalidMessageFormatErr{messageType: \"StartupMessage\"}\n\t\t}\n\t\tvalue := string(src[rp : rp+idx])\n\t\trp += idx + 1\n\n\t\tdst.Parameters[key] = value\n\n\t\tif len(src[rp:]) == 1 {\n\t\t\tif src[rp] != 0 {\n\t\t\t\treturn fmt.Errorf(\"Bad startup message last byte. Expected 0, got %d\", src[rp])\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.\nfunc (src *StartupMessage) Encode(dst []byte) ([]byte, error) {\n\tsp := len(dst)\n\tdst = pgio.AppendInt32(dst, -1)\n\n\tdst = pgio.AppendUint32(dst, src.ProtocolVersion)\n\tfor k, v := range src.Parameters {\n\t\tdst = append(dst, k...)\n\t\tdst = append(dst, 0)\n\t\tdst = append(dst, v...)","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgproto3/startup_message.go#L44-L80","documentation":"While parsing the startup message's null-terminated parameter list, the final remaining byte was expected to be the terminating NUL but was not. The %d shows the actual byte value, indicating a malformed parameter block.","triggerScenarios":"Thrown at pgproto3/startup_message.go:62 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure all parameter strings are NUL-terminated","Add the final NUL terminator byte after the last key/value pair","Use pgproto3's StartupMessage.Encode which handles termination","Check for off-by-one errors in manual packet construction"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}