Skip to content

fix(proxy): use ReadFull for TCP DNS length prefix - #526

Closed
vulragrag-star wants to merge 1 commit into
AdguardTeam:masterfrom
vulragrag-star:fix/523-readprefixed-length
Closed

vulragrag-star wants to merge 1 commit into
AdguardTeam:masterfrom
vulragrag-star:fix/523-readprefixed-length

Conversation

@vulragrag-star

Copy link
Copy Markdown
Contributor

Fixes #523

readPrefixed read the 2-byte DNS-over-TCP length with a single conn.Read and ignored the returned byte count. When the peer delivered that prefix across two TCP segments, the second length byte stayed zero and the message was mis-parsed (empty body / wrong size). The payload path already used io.ReadFull; use it for the length prefix too.

Testing

  • go test ./proxy/ -count=1 -run TestReadPrefixed passes
  • TestReadPrefixed_splitLengthPrefix fails on master (short first Read → empty payload) and passes with this change

A single conn.Read can return only the first length byte when the peer
delivers the 2-byte prefix across two TCP segments. Ignoring the short
read treated the second byte as zero and mis-parsed the message.

Fixes AdguardTeam#523
@EugeneOne1

Copy link
Copy Markdown
Member

Hello @vulragrag-star, thank you for your contribution. We have merged the changes to the master branch (available since ddf250f), making a few corrections to the code style and tests. Unfortunately, we accidentally squashed the commits, so this PR hasn't been closed automatically. Nevertheless, you can see yourself listed as a contributor. Thank you again for this fix. It will be included in the next release.

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.

TCP: readPrefixed uses conn.Read for the 2-byte length prefix and ignores the byte count

2 participants