Skip to content

Throw PostgresInterfaceError for NUL bytes in protocol strings - #27

Merged
quinnj merged 1 commit into
mainfrom
fix/nul-byte-error
Oct 14, 2026
Merged

quinnj merged 1 commit into
mainfrom
fix/nul-byte-error

Conversation

@quinnj

@quinnj quinnj commented Oct 14, 2026

Copy link
Copy Markdown
Member

SQL containing a NUL byte raised a confusing UndefVarError instead of the intended PostgresInterfaceError:

DBInterface.execute(conn, "SELECT 1\0")
# UndefVarError: `Postgres` not defined in `Postgres.API`

writepart in src/api/API.jl threw Postgres.PostgresInterfaceError(...), but the name Postgres is not bound inside module API. The module already imports PostgresInterfaceError, so the fix drops the prefix. The startup-parameter variant had the same mistake; it is normally unreachable because Connection rejects NUL bytes in its parameters first.

The check runs while the message is still in a local buffer, so nothing reaches the server and the connection stays usable. That was already true; only the error type was wrong.

Tests:

  • A no-server testset checks both methods throw PostgresInterfaceError and write nothing.
  • An integration assertion checks DBInterface.execute(conn, "SELECT 1\0") throws PostgresInterfaceError and the connection still answers SELECT 1.

Validation:

  • The new testset fails on main (2 × UndefVarError) and passes with the fix.
  • JET.report_package(Postgres; mode=:typo) reports exactly these two undefined references on main and none with the fix, so there are no others in the package.

🤖 Generated with Claude Code

writepart referred to Postgres.PostgresInterfaceError from inside module
API, where the name Postgres is not bound, so SQL containing a NUL byte
raised UndefVarError instead of the intended error. API already imports
PostgresInterfaceError; use it directly. The check runs while the message
is still buffered, so nothing is sent and the connection stays usable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quinnj
quinnj merged commit 240c434 into main Oct 14, 2026
16 checks passed
quinnj referenced this pull request Oct 14, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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