Skip to content

Commit

Permalink
tcpiohandler: Use server preference algoritm for ALPN selection
Browse files Browse the repository at this point in the history
This complies with RFC 7301 section 3.2
  • Loading branch information
dwfreed committed Mar 3, 2024
1 parent 524ce4f commit b599f69
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pdns/tcpiohandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -878,23 +878,24 @@ class OpenSSLTLSIOCtx: public TLSCtx
}
OpenSSLTLSIOCtx* obj = reinterpret_cast<OpenSSLTLSIOCtx*>(arg);

size_t pos = 0;
while (pos < inlen) {
size_t protoLen = in[pos];
pos++;
if (protoLen > (inlen - pos)) {
/* something is very wrong */
return SSL_TLSEXT_ERR_ALERT_WARNING;
}
// Server preference algorithm as per RFC 7301 section 3.2
for (const auto& tentative : obj->d_alpnProtos) {
size_t pos = 0;
while (pos < inlen) {
size_t protoLen = in[pos];

Check warning on line 885 in pdns/tcpiohandler.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, auth)

do not use pointer arithmetic (cppcoreguidelines-pro-bounds-pointer-arithmetic - Level=Warning)

Check warning on line 885 in pdns/tcpiohandler.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, rec)

do not use pointer arithmetic (cppcoreguidelines-pro-bounds-pointer-arithmetic - Level=Warning)

Check warning on line 885 in pdns/tcpiohandler.cc

View workflow job for this annotation

GitHub Actions / Analyze (cpp, dnsdist)

do not use pointer arithmetic (cppcoreguidelines-pro-bounds-pointer-arithmetic - Level=Warning)
pos++;
if (protoLen > (inlen - pos)) {
/* something is very wrong */
return SSL_TLSEXT_ERR_ALERT_WARNING;
}

for (const auto& tentative : obj->d_alpnProtos) {
if (tentative.size() == protoLen && memcmp(in + pos, tentative.data(), tentative.size()) == 0) {
*out = in + pos;
*outlen = protoLen;
return SSL_TLSEXT_ERR_OK;
}
pos += protoLen;
}
pos += protoLen;
}

return SSL_TLSEXT_ERR_NOACK;
Expand Down

0 comments on commit b599f69

Please sign in to comment.