Skip to content

Stop cstring reading on any falsy value#3691

Merged
brianc merged 1 commit into
masterfrom
bmc/security-advisory-fix
Jun 19, 2026
Merged

Stop cstring reading on any falsy value#3691
brianc merged 1 commit into
masterfrom
bmc/security-advisory-fix

Conversation

@brianc

@brianc brianc commented Jun 17, 2026

Copy link
Copy Markdown
Owner

I got a massive, obviously LLM generated security vuln report generated about a potential MITM attack where if you connect pg to a compromised backend or a malicious MITM and the cstring buffer does not have a null terminator anywhere in it it will cause your process to infinite loop. Pretty unlikely to happen in practice and honestly you're probably in more trouble than just that if your db connection is being tampered with maliciously, but I figure its still worth fixing since the fix itself is very straight forward.

@sehrope

sehrope commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

So the change here is to stop when the buffer gets undefined trying to read past it's max rather than looping forever? LGTM.

Though now I'm also curious if there's other spots where we're reading past the edge of the message or field limits. Will take a peek...

@brianc

brianc commented Jun 19, 2026

Copy link
Copy Markdown
Owner Author

Though now I'm also curious if there's other spots where we're reading past the edge of the message or field limits. Will take a peek...

if memory serves this is the only place.

as an aside: the empty while loop was a performance "hack" I did a super super long time ago. I forget where I copied it from - maybe the old version of the node mysql driver back in 2009? Anyways I was curious if it was still the most efficent way to read a cstring out of the result buffer - because this code gets called in the extremely hot path I wanted to test it. I thought maybe Buffer.indexOf would be better now - but turns out this is still 10% faster than using Buffer.indexOf 🤷

@brianc brianc merged commit 695fe61 into master Jun 19, 2026
21 of 22 checks passed
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.

2 participants