-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOH: improve encoding/decoding and update related unit test #4598
Conversation
increased strictness of QNAME-encoding, adding error detection for empty labels and names longer than the overall limit; avoided treating DNAME as unexpected;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could've made the fixes for the encoder and the decoder in separate fixes, but I won't insist on it...
lib/doh.c
Outdated
(12 /* header */ | ||
+ (hostlen ? (hostlen + ((host[hostlen-1] == '.') ? 0 : 1)) : 0) | ||
+ 1 /* zero-length root label */ | ||
+ 4); /* QTYPE, QCLASS */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to deal with a zero hostlen and I think maybe the handling of the trailing dot can be moved outside of the main formula to make this more readable. Maybe like:
size_t expected_len;
DEBUGASSERT(hostlen);
expected_len = 12 + 1 + hostlen + 4;
if(host[hostlen-1]!='.')
hostlen++;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
If libcurl will never need to query for an RRset at the root, supporting zero hostlen is definitely unnecessary. As I don't know about this, I put it in there, so that this corner case, legitimate from a DNS point of view, would be covered.
For avoidance of doubt, I'ld like to see either "No, it's really overkill" or "Oops, good catch" from you, if you wouldn't mind.
-
Not doing all the estimation during initialization certainly improves readability. I had far too much fun with the brackets.
I think you mean
if(host[hostlen-1]!='.')
expected_len++;
Thanks! |
DOH: improve encoding/decoding and update related unit test
A number of bugs in functions doh_encode() and doh_decode() (see below) are addressed.
Unit test 1655 for doh_encode() is updated with more thorough tests
and proofs of detection.
Bugs in function doh_encode():
for encoding in the QNAME, resulting in an invalid DNS query message;
the host name has a trailing dot.
Bug in function doh_decode():
Reported-by: @niallor