Skip to content

Only check error length during startup, limit response size for some types#1327

Merged
arp242 merged 1 commit into
masterfrom
msglen
Jul 11, 2026
Merged

Only check error length during startup, limit response size for some types#1327
arp242 merged 1 commit into
masterfrom
msglen

Conversation

@arp242

@arp242 arp242 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

#1248 is not entirely correct, as it should only apply on startup messages, as that check is done in PQconnectPoll():

if (beresp == PqMsg_ErrorResponse && (msgLength < 8 || msgLength > MAX_ERRLEN)

We can re-use the txnStatus field to check if we're in the connection phase.

In addition, in pqParseInput3(), it does limit the message length, but only for some respose types:

#define VALID_LONG_MESSAGE_TYPE(id) \
	((id) == PqMsg_CopyData || \
	(id) == PqMsg_DataRow || \
	(id) == PqMsg_ErrorResponse || \
	(id) == PqMsg_FunctionCallResponse || \
	(id) == PqMsg_NoticeResponse || \
	(id) == PqMsg_NotificationResponse || \
	(id) == PqMsg_RowDescription)

if (msgLength > 30000 && !VALID_LONG_MESSAGE_TYPE(id))

So check for that as well.

Fixes #1324
Closes #1326

…types

#1248 is not entirely correct, as it should only apply on startup
messages, as that check is done in PQconnectPoll():

	if (beresp == PqMsg_ErrorResponse && (msgLength < 8 || msgLength > MAX_ERRLEN)

We can re-use the txnStatus field to check if we're in the connection
phase.

In addition, in pqParseInput3(), it does limit the message length, but
only for some respose types:

	#define VALID_LONG_MESSAGE_TYPE(id) \
		((id) == PqMsg_CopyData || \
		(id) == PqMsg_DataRow || \
		(id) == PqMsg_ErrorResponse || \
		(id) == PqMsg_FunctionCallResponse || \
		(id) == PqMsg_NoticeResponse || \
		(id) == PqMsg_NotificationResponse || \
		(id) == PqMsg_RowDescription)

	if (msgLength > 30000 && !VALID_LONG_MESSAGE_TYPE(id))

So check for that as well.

Fixes #1324
Closes #1326
@arp242
arp242 merged commit b125f75 into master Jul 11, 2026
14 checks passed
@arp242
arp242 deleted the msglen branch July 11, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ErrorResponse > 30000 bytes is misparsed as a pre-protocol plain-text error

1 participant