From: vlsi (@vlsi) <noreply+vlsi@github.com>
To: pgjdbc/pgjdbc <noreply+pgjdbc-pgjdbc@github.com>
Subject: Re: [pgjdbc/pgjdbc] PR #4251: OAuth implementation
Date: Wed, 09 Sep 2026 15:45:36 +0000
Message-ID: <gh-pgjdbc-pgjdbc-4251-rc3970363241@github.com> (raw)
In-Reply-To: <gh-pgjdbc-pgjdbc-4251@github.com>
References: <gh-pgjdbc-pgjdbc-4251@github.com>
(on pgjdbc/src/main/java/org/postgresql/core/v3/ConnectionFactoryImpl.java)
The loop ignores `msgLen` and reads until it meets two NUL bytes, so an `AuthenticationSASL` whose body is a single terminator makes it read past the end of the message. I sent that from a fake backend, followed by an `ErrorResponse`:
```text
CLIENT-EXC: The server requested SASL authentication with mechanisms [, E],
but none of them configured or supported by the driver.
```
The `E` is the type byte of the `ErrorResponse`, which the parser consumed as a mechanism name, and the server's real error never reaches the user. The `mechanisms.isEmpty()` check below cannot fire either, because `do/while` appends before it tests.
This came over unchanged from `ScramAuthenticator.advertisedMechanisms`, so it is not a regression. It is worth fixing here because the move is what makes it fixable: `msgLen` is in scope at the call site now and was not before. Passing the body length in and reading exactly that many bytes also lets the empty-list check become reachable.
One more on line 1257: `assert c == 0` is not an error handler, and the CI matrix has rows both with and without `-ea`, so a malformed packet behaves differently between them.