*/
class Packet : public Query
{
+ static bool IsValidName(const std::string& name)
+ {
+ return (name.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-") == std::string::npos);
+ }
+
void PackName(unsigned char* output, unsigned short output_size, unsigned short& pos, const std::string& name)
{
if (pos + name.length() + 2 > output_size)
case QUERY_PTR:
{
record.rdata = this->UnpackName(input, input_size, pos);
+ if (!IsValidName(record.rdata))
+ throw Exception("Invalid name"); // XXX: Causes the request to time out
+
break;
}
default:
return;
}
+ // Update name in the original request so question checking works for PTR queries
+ req->name = p.question.name;
+
if (SocketEngine::SendTo(this, buffer, len, 0, &this->myserver.sa, this->myserver.sa_size()) != len)
throw Exception("DNS: Unable to send query");
}
return;
}
+ if (static_cast<Question&>(*request) != recv_packet.question)
+ {
+ // This can happen under high latency, drop it silently, do not fail the request
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Received an answer that isn't for a question we asked");
+ return;
+ }
+
if (recv_packet.flags & QUERYFLAGS_OPCODE)
{
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Received a nonstandard query");