Skip to content

postgres: do not count string terminators twice in message lengths - #5312

Open
mmporong wants to merge 1 commit into
secdev:masterfrom
mmporong:postgres-strnull-lengths
Open

mmporong wants to merge 1 commit into
secdev:masterfrom
mmporong:postgres-strnull-lengths

Conversation

@mmporong

Copy link
Copy Markdown

Description

Since #3683, StrNullField.i2len() counts the trailing NUL (fields.py#L2260-L2262). The adjust of Query, Close, Describe and Execute in the postgres contrib was written before that change and still adds 1 for the NUL (Query, Close, Describe, Execute), so the built length field is one byte too long:

>>> from scapy.contrib.postgres import Query
>>> bytes(Query(query=b"SELECT 1"))
b'Q\x00\x00\x00\x0eSELECT 1\x00'  # length 14, the message is 13 bytes after the tag

PostgreSQL 17 waits for the missing byte, so this query gets no answer. This PR removes the extra 1 from the four adjust lambdas. In test/contrib/postgres.uts, the built Query, Describe and Execute are checked against the captures already there, and Close against bytes written from the message format.

This message was written with the help of AI (Claude Opus 5.5).

StrNullField.i2len() includes the trailing NUL since secdev#3683, but the
adjust of Query, Close, Describe and Execute still adds it, so the
length field of these messages is one byte too long when built.

AI-Assisted: yes (Claude Opus 5.5)
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.

1 participant