1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:17:34 +00:00

LookupServer: Move case randomization into DNSName

* DNSName knows how to randomize itself
* DNSPacket no longer constructs DNSQuestion instances, it receives an already
  built DNSQuestion and just adds it to the list
* LookupServer::lookup() explicitly calls randomize_case() if it needs to
  randomize the case.
This commit is contained in:
Sergey Bugaev 2021-02-14 16:25:48 +03:00 committed by Andreas Kling
parent 89f718c4c5
commit bacbde31f3
5 changed files with 27 additions and 23 deletions

View file

@ -37,29 +37,11 @@
namespace LookupServer {
void DNSPacket::add_question(const String& name, u16 record_type, ShouldRandomizeCase should_randomize_case)
void DNSPacket::add_question(const DNSQuestion& question)
{
m_questions.empend(question);
ASSERT(m_questions.size() <= UINT16_MAX);
if (name.is_empty())
return;
StringBuilder builder;
for (size_t i = 0; i < name.length(); ++i) {
u8 ch = name[i];
if (should_randomize_case == ShouldRandomizeCase::Yes) {
// Randomize the 0x20 bit in every ASCII character.
if (isalpha(ch)) {
if (arc4random_uniform(2))
ch |= 0x20;
else
ch &= ~0x20;
}
}
builder.append(ch);
}
m_questions.empend(builder.to_string(), record_type, (u16)C_IN);
}
ByteBuffer DNSPacket::to_byte_buffer() const