more portability updates

pull/394/head
bradh352 4 years ago
parent d5146a6a4d
commit f4c079d9d0
  1. 4
      src/lib/ares_create_query.c
  2. 33
      src/lib/ares_nameser.h
  3. 2
      test/ares-test-fuzz-name.c
  4. 16
      test/ares-test-live.cc
  5. 24
      test/ares-test-misc.cc
  6. 4
      test/ares-test-mock.cc
  7. 4
      test/ares-test.cc
  8. 6
      test/dns-proto-test.cc
  9. 20
      test/dns-proto.cc
  10. 6
      test/dns-proto.h

@ -48,7 +48,7 @@
* of the remaining fields:
* ID Identifier to match responses with queries
* QR Query (0) or response (1)
* Opcode For our purposes, always QUERY
* Opcode For our purposes, always O_QUERY
* RD Recursion desired
* Z Reserved (zero)
* QDCOUNT Number of queries
@ -107,7 +107,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
q = buf;
memset(q, 0, HFIXEDSZ);
DNS_HEADER_SET_QID(q, id);
DNS_HEADER_SET_OPCODE(q, QUERY);
DNS_HEADER_SET_OPCODE(q, O_QUERY);
if (rd) {
DNS_HEADER_SET_RD(q, 1);
}

@ -219,11 +219,26 @@ typedef enum __ns_rcode {
# define NAMESERVER_PORT NS_DEFAULTPORT
#endif
#ifndef QUERY
# define QUERY ns_o_query
/* opcodes */
#ifndef O_QUERY
# define O_QUERY 0 /* ns_o_query */
#endif
#ifndef O_IQUERY
# define O_IQUERY 1 /* ns_o_iquery */
#endif
#ifndef O_STATUS
# define O_STATUS 2 /* ns_o_status */
#endif
#ifndef O_NOTIFY
# define O_NOTIFY 4 /* ns_o_notify */
#endif
#ifndef O_UPDATE
# define O_UPDATE 5 /* ns_o_update */
#endif
/* response codes */
#ifndef SERVFAIL
# define SERVFAIL ns_r_servfail
#endif
@ -271,22 +286,26 @@ typedef enum __ns_rcode {
# define TSIG_BADTIME 18 /* ns_r_badtime */
#endif
/* classes */
#ifndef C_IN
# define C_IN ns_c_in
# define C_IN 1 /* ns_c_in */
#endif
#ifndef C_CHAOS
# define C_CHAOS ns_c_chaos
# define C_CHAOS 3 /* ns_c_chaos */
#endif
#ifndef C_HS
# define C_HS ns_c_hs
# define C_HS 4 /* ns_c_hs */
#endif
#ifndef C_NONE
# define C_NONE ns_c_none
# define C_NONE 254 /* ns_c_none */
#endif
#ifndef C_ANY
# define C_ANY ns_c_any
# define C_ANY 255 /* ns_c_any */
#endif
/* types */
#ifndef T_A
# define T_A 1 /* ns_t_a */
#endif

@ -17,7 +17,7 @@ int LLVMFuzzerTestOneInput(const unsigned char *data,
unsigned char *buf = NULL;
int buflen = 0;
ares_create_query(name, ns_c_in, T_AAAA, 1234, 0, &buf, &buflen, 1024);
ares_create_query(name, C_IN, T_AAAA, 1234, 0, &buf, &buflen, 1024);
free(buf);
free(name);
return 0;

@ -273,7 +273,7 @@ INSTANTIATE_TEST_CASE_P(Modes, DefaultChannelModeTest,
VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchA) {
SearchResult result;
ares_search(channel_, "www.youtube.com.", ns_c_in, T_A,
ares_search(channel_, "www.youtube.com.", C_IN, T_A,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
@ -282,7 +282,7 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchA) {
VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchEmptyA) {
SearchResult result;
ares_search(channel_, "", ns_c_in, T_A,
ares_search(channel_, "", C_IN, T_A,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
@ -291,7 +291,7 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchEmptyA) {
VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchNS) {
SearchResult result;
ares_search(channel_, "google.com.", ns_c_in, T_NS,
ares_search(channel_, "google.com.", C_IN, T_NS,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
@ -300,7 +300,7 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchNS) {
VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchMX) {
SearchResult result;
ares_search(channel_, "google.com.", ns_c_in, T_MX,
ares_search(channel_, "google.com.", C_IN, T_MX,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
@ -309,7 +309,7 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchMX) {
VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchTXT) {
SearchResult result;
ares_search(channel_, "google.com.", ns_c_in, T_TXT,
ares_search(channel_, "google.com.", C_IN, T_TXT,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
@ -318,7 +318,7 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchTXT) {
VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchSOA) {
SearchResult result;
ares_search(channel_, "google.com.", ns_c_in, T_SOA,
ares_search(channel_, "google.com.", C_IN, T_SOA,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
@ -327,7 +327,7 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchSOA) {
VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchSRV) {
SearchResult result;
ares_search(channel_, "_imap._tcp.gmail.com.", ns_c_in, T_SRV,
ares_search(channel_, "_imap._tcp.gmail.com.", C_IN, T_SRV,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
@ -336,7 +336,7 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchSRV) {
VIRT_NONVIRT_TEST_F(DefaultChannelTest, LiveSearchANY) {
SearchResult result;
ares_search(channel_, "google.com.", ns_c_in, T_ANY,
ares_search(channel_, "google.com.", C_IN, T_ANY,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);

@ -166,7 +166,7 @@ TEST_F(LibraryTest, InetNtoP) {
TEST_F(LibraryTest, Mkquery) {
byte* p;
int len;
ares_mkquery("example.com", ns_c_in, T_A, 0x1234, 0, &p, &len);
ares_mkquery("example.com", C_IN, T_A, 0x1234, 0, &p, &len);
std::vector<byte> data(p, p + len);
ares_free_string(p);
@ -181,7 +181,7 @@ TEST_F(LibraryTest, CreateQuery) {
byte* p;
int len;
EXPECT_EQ(ARES_SUCCESS,
ares_create_query("exam\\@le.com", ns_c_in, T_A, 0x1234, 0,
ares_create_query("exam\\@le.com", C_IN, T_A, 0x1234, 0,
&p, &len, 0));
std::vector<byte> data(p, p + len);
ares_free_string(p);
@ -197,7 +197,7 @@ TEST_F(LibraryTest, CreateQueryTrailingEscapedDot) {
byte* p;
int len;
EXPECT_EQ(ARES_SUCCESS,
ares_create_query("example.com\\.", ns_c_in, T_A, 0x1234, 0,
ares_create_query("example.com\\.", C_IN, T_A, 0x1234, 0,
&p, &len, 0));
std::vector<byte> data(p, p + len);
ares_free_string(p);
@ -215,7 +215,7 @@ TEST_F(LibraryTest, CreateQueryNameTooLong) {
"a1234567890123456789.b1234567890123456789.c1234567890123456789.d1234567890123456789."
"a1234567890123456789.b1234567890123456789.c1234567890123456789.d1234567890123456789."
"x1234567890123456789.y1234567890123456789.",
ns_c_in, T_A, 0x1234, 0, &p, &len, 0));
C_IN, T_A, 0x1234, 0, &p, &len, 0));
}
TEST_F(LibraryTest, CreateQueryFailures) {
@ -228,7 +228,7 @@ TEST_F(LibraryTest, CreateQueryFailures) {
}
p = nullptr;
EXPECT_EQ(ARES_EBADNAME,
ares_create_query(longname.c_str(), ns_c_in, T_A, 0x1234, 0,
ares_create_query(longname.c_str(), C_IN, T_A, 0x1234, 0,
&p, &len, 0));
if (p) ares_free_string(p);
@ -236,7 +236,7 @@ TEST_F(LibraryTest, CreateQueryFailures) {
p = nullptr;
EXPECT_EQ(ARES_ENOMEM,
ares_create_query("example.com", ns_c_in, T_A, 0x1234, 0,
ares_create_query("example.com", C_IN, T_A, 0x1234, 0,
&p, &len, 0));
if (p) ares_free_string(p);
@ -244,14 +244,14 @@ TEST_F(LibraryTest, CreateQueryFailures) {
std::string longlabel = "a.a123456789b123456789c123456789d123456789e123456789f123456789g123456789.org";
p = nullptr;
EXPECT_EQ(ARES_EBADNAME,
ares_create_query(longlabel.c_str(), ns_c_in, T_A, 0x1234, 0,
ares_create_query(longlabel.c_str(), C_IN, T_A, 0x1234, 0,
&p, &len, 0));
if (p) ares_free_string(p);
// Empty non-terminal label
p = nullptr;
EXPECT_EQ(ARES_EBADNAME,
ares_create_query("example..com", ns_c_in, T_A, 0x1234, 0,
ares_create_query("example..com", C_IN, T_A, 0x1234, 0,
&p, &len, 0));
if (p) ares_free_string(p);
}
@ -260,7 +260,7 @@ TEST_F(LibraryTest, CreateQueryOnionDomain) {
byte* p;
int len;
EXPECT_EQ(ARES_ENOTFOUND,
ares_create_query("dontleak.onion", ns_c_in, T_A, 0x1234, 0,
ares_create_query("dontleak.onion", C_IN, T_A, 0x1234, 0,
&p, &len, 0));
}
@ -291,7 +291,7 @@ TEST_F(DefaultChannelTest, GetAddrinfoOnionDomain) {
// still leaks information about the query to malicious resolvers.
TEST_F(DefaultChannelTest, SearchOnionDomain) {
SearchResult result;
ares_search(channel_, "dontleak.onion", ns_c_in, T_A,
ares_search(channel_, "dontleak.onion", C_IN, T_A,
SearchCallback, &result);
EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENOTFOUND, result.status_);
@ -454,7 +454,7 @@ TEST_F(LibraryTest, CreateEDNSQuery) {
byte* p;
int len;
EXPECT_EQ(ARES_SUCCESS,
ares_create_query("example.com", ns_c_in, T_A, 0x1234, 0,
ares_create_query("example.com", C_IN, T_A, 0x1234, 0,
&p, &len, 1280));
std::vector<byte> data(p, p + len);
ares_free_string(p);
@ -470,7 +470,7 @@ TEST_F(LibraryTest, CreateEDNSQuery) {
TEST_F(LibraryTest, CreateRootQuery) {
byte* p;
int len;
ares_create_query(".", ns_c_in, T_A, 0x1234, 0, &p, &len, 0);
ares_create_query(".", C_IN, T_A, 0x1234, 0, &p, &len, 0);
std::vector<byte> data(p, p + len);
ares_free_string(p);

@ -595,7 +595,7 @@ TEST_P(MockChannelTest, SearchNoDataThenFail) {
TEST_P(MockChannelTest, SearchAllocFailure) {
SearchResult result;
SetAllocFail(1);
ares_search(channel_, "fully.qualified.", ns_c_in, T_A, SearchCallback, &result);
ares_search(channel_, "fully.qualified.", C_IN, T_A, SearchCallback, &result);
/* Already done */
EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_ENOMEM, result.status_);
@ -615,7 +615,7 @@ TEST_P(MockChannelTest, SearchHighNdots) {
.WillByDefault(SetReply(&server_, &yesfirst));
SearchResult result;
ares_search(channel_, "a.b.c.w.w.w", ns_c_in, T_A, SearchCallback, &result);
ares_search(channel_, "a.b.c.w.w.w", C_IN, T_A, SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
EXPECT_EQ(ARES_SUCCESS, result.status_);

@ -314,7 +314,7 @@ void MockServer::ProcessFD(int fd) {
std::cerr << "Not a request" << std::endl;
return;
}
if (DNS_HEADER_OPCODE(data) != ns_o_query) {
if (DNS_HEADER_OPCODE(data) != O_QUERY) {
std::cerr << "Not a query (opcode " << DNS_HEADER_OPCODE(data)
<< ")" << std::endl;
return;
@ -344,7 +344,7 @@ void MockServer::ProcessFD(int fd) {
<< " bytes after name)" << std::endl;
return;
}
if (DNS_QUESTION_CLASS(question) != ns_c_in) {
if (DNS_QUESTION_CLASS(question) != C_IN) {
std::cerr << "Unexpected question class (" << DNS_QUESTION_CLASS(question)
<< ")" << std::endl;
return;

@ -10,7 +10,7 @@ TEST(DNSProto, EncodeQuestions) {
DNSPacket pkt;
pkt.set_qid(0x1234).set_response().set_aa()
.add_question(new DNSQuestion("example.com.", T_A))
.add_question(new DNSQuestion("www.example.com", T_AAAA, ns_c_chaos));
.add_question(new DNSQuestion("www.example.com", T_AAAA, C_CHAOS));
std::vector<byte> data = {
0x12, 0x34, // qid
@ -42,7 +42,7 @@ TEST(DNSProto, EncodeSingleNameAnswers) {
pkt.qid_ = 0x1234;
pkt.response_ = true;
pkt.aa_ = true;
pkt.opcode_ = ns_o_query;
pkt.opcode_ = O_QUERY;
pkt.add_answer(new DNSCnameRR("example.com", 0x01020304, "other.com."));
pkt.add_auth(new DNSPtrRR("www.example.com", 0x01020304, "www.other.com"));
@ -87,7 +87,7 @@ TEST(DNSProto, EncodeAddressAnswers) {
pkt.qid_ = 0x1234;
pkt.response_ = true;
pkt.aa_ = true;
pkt.opcode_ = ns_o_query;
pkt.opcode_ = O_QUERY;
std::vector<byte> addrv4 = {0x02, 0x03, 0x04, 0x05};
pkt.add_answer(new DNSARR("example.com", 0x01020304, addrv4));
byte addrv6[16] = {0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02,

@ -145,11 +145,11 @@ std::string RRTypeToString(int rrtype) {
std::string ClassToString(int qclass) {
switch (qclass) {
case ns_c_in: return "IN";
case ns_c_chaos: return "CHAOS";
case ns_c_hs: return "HESIOD";
case ns_c_none: return "NONE";
case ns_c_any: return "ANY";
case C_IN: return "IN";
case C_CHAOS: return "CHAOS";
case C_HS: return "HESIOD";
case C_NONE: return "NONE";
case C_ANY: return "ANY";
default: return "UNKNOWN";
}
}
@ -188,11 +188,11 @@ std::string PacketToString(const std::vector<byte>& packet) {
}
ss << ((DNS_HEADER_QR(data) == 0) ? "REQ " : "RSP ");
switch (DNS_HEADER_OPCODE(data)) {
case ns_o_query: ss << "QRY "; break;
case ns_o_iquery: ss << "IQRY "; break;
case ns_o_status: ss << "STATUS "; break;
case ns_o_notify: ss << "NOTIFY "; break;
case ns_o_update: ss << "UPDATE "; break;
case O_QUERY: ss << "QRY "; break;
case O_IQUERY: ss << "IQRY "; break;
case O_STATUS: ss << "STATUS "; break;
case O_NOTIFY: ss << "NOTIFY "; break;
case O_UPDATE: ss << "UPDATE "; break;
default: ss << "UNKNOWN(" << DNS_HEADER_OPCODE(data) << ") "; break;
}
if (DNS_HEADER_AA(data)) ss << "AA ";

@ -46,7 +46,7 @@ struct DNSQuestion {
DNSQuestion(const std::string& name, int rrtype, int qclass)
: name_(name), rrtype_(rrtype), qclass_(qclass) {}
DNSQuestion(const std::string& name, int rrtype)
: name_(name), rrtype_(rrtype), qclass_(ns_c_in) {}
: name_(name), rrtype_(rrtype), qclass_(C_IN) {}
virtual ~DNSQuestion() {}
virtual std::vector<byte> data() const;
std::string name_;
@ -187,7 +187,7 @@ struct DNSOptRR : public DNSRR {
struct DNSPacket {
DNSPacket()
: qid_(0), response_(false), opcode_(ns_o_query),
: qid_(0), response_(false), opcode_(O_QUERY),
aa_(false), tc_(false), rd_(false), ra_(false),
z_(false), ad_(false), cd_(false), rcode_(NOERROR) {}
// Convenience functions that take ownership of given pointers.
@ -224,7 +224,7 @@ struct DNSPacket {
int qid_;
bool response_;
ns_opcode opcode_;
int opcode_;
bool aa_;
bool tc_;
bool rd_;

Loading…
Cancel
Save