/* allocate a bit more memory to be able to spoof the content, get an answer from the cache
or to add ECS without allocating a new buffer */
- state->d_buffer.resize((state->d_querySize + static_cast<size_t>(512)) < s_maxPacketCacheEntrySize ? s_maxPacketCacheEntrySize : (state->d_querySize + static_cast<size_t>(512)));
+ state->d_buffer.resize(std::max(state->d_querySize + static_cast<size_t>(512), s_maxPacketCacheEntrySize));
state->d_currentPos = 0;
}
}
uint16_t len = du->query.length();
/* We reserve at least 512 additional bytes to be able to add EDNS, but we also want
at least s_maxPacketCacheEntrySize bytes to be able to spoof the content or fill the answer from the packet cache */
- du->query.resize((du->query.size() + 512 < s_maxPacketCacheEntrySize) ? s_maxPacketCacheEntrySize : (du->query.size() + 512));
+ du->query.resize(std::max(du->query.size() + 512, s_maxPacketCacheEntrySize));
size_t bufferSize = du->query.size();
auto query = const_cast<char*>(du->query.c_str());
struct dnsheader* dh = reinterpret_cast<struct dnsheader*>(query);
std::string query;
/* We reserve at least 512 additional bytes to be able to add EDNS, but we also want
at least s_maxPacketCacheEntrySize bytes to be able to fill the answer from the packet cache */
- query.reserve(((req->entity.len + 512) < s_maxPacketCacheEntrySize) ? s_maxPacketCacheEntrySize : (req->entity.len + 512));
+ query.reserve(std::max(req->entity.len + 512, s_maxPacketCacheEntrySize));
query.assign(req->entity.base, req->entity.len);
doh_dispatch_query(dsc, self, req, std::move(query), local, remote);
}
/* rough estimate so we hopefully don't need a need allocation later */
/* We reserve at least 512 additional bytes to be able to add EDNS, but we also want
at least s_maxPacketCacheEntrySize bytes to be able to fill the answer from the packet cache */
- size_t estimate = ((sdns.size() * 3) / 4);
- decoded.reserve(((estimate + 512) < s_maxPacketCacheEntrySize) ? s_maxPacketCacheEntrySize : (estimate + 512));
+ const size_t estimate = ((sdns.size() * 3) / 4);
+ decoded.reserve(std::max(estimate + 512, s_maxPacketCacheEntrySize));
if(B64Decode(sdns, decoded) < 0) {
h2o_send_error_400(req, "Bad Request", "Unable to decode BASE64-URL", 0);
++dsc->df->d_badrequests;