diff options
| author | Adam <Adam@anope.org> | 2015-10-27 18:57:37 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2015-10-27 18:58:48 -0400 |
| commit | 64dac60071fab652745a6e7a06cf6b7bdbbd3625 (patch) | |
| tree | f8f30161150451672b381f6370a8fdcab654bbb8 /modules/m_dns.cpp | |
| parent | 162fdbe5815bbdf187f549fefac94ff476d72e62 (diff) | |
| parent | 830361e97d03c74e54cb1cf1bbf329dffdeb66f7 (diff) | |
Merge branch '2.0' into 2.1
Diffstat (limited to 'modules/m_dns.cpp')
| -rw-r--r-- | modules/m_dns.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/modules/m_dns.cpp b/modules/m_dns.cpp index c5fe8a767..1ea70a6ed 100644 --- a/modules/m_dns.cpp +++ b/modules/m_dns.cpp @@ -22,10 +22,15 @@ namespace time_t timeout; } -/** A full packet sent or recieved to/from the nameserver +/** A full packet sent or received to/from the nameserver */ class Packet : public Query { + static bool IsValidName(const Anope::string &name) + { + return name.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-") == Anope::string::npos; + } + void PackName(unsigned char *output, unsigned short output_size, unsigned short &pos, const Anope::string &name) { if (pos + name.length() + 2 > output_size) @@ -116,6 +121,9 @@ class Packet : public Query if (pos + 4 > input_size) throw SocketException("Unable to unpack question"); + if (!IsValidName(question.name)) + throw SocketException("Invalid question name"); + question.type = static_cast<QueryType>(input[pos] << 8 | input[pos + 1]); pos += 2; @@ -179,6 +187,10 @@ class Packet : public Query case QUERY_PTR: { record.rdata = this->UnpackName(input, input_size, pos); + + if (!IsValidName(record.rdata)) + throw SocketException("Invalid cname/ptr record data"); + break; } default: @@ -792,7 +804,7 @@ class MyManager : public Manager, public Timer } Packet *packet = new Packet(recv_packet); - packet->flags |= QUERYFLAGS_QR; /* This is a reponse */ + packet->flags |= QUERYFLAGS_QR; /* This is a response */ packet->flags |= QUERYFLAGS_AA; /* And we are authoritative */ packet->answers.clear(); |
