mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
evdns: accept domains up to 254 long (previosly only 63 long was accepted)
Previously evdns was using HOST_NAME_MAX, and define it to 255 *only* if it not set, however it does set on linux: $ egrep -r define.*HOST_NAME_MAX /usr/include/bits /usr/include/bits/local_lim.h:#define HOST_NAME_MAX 64 /usr/include/bits/posix1_lim.h:#define _POSIX_HOST_NAME_MAX 255 /usr/include/bits/confname.h:#define _SC_HOST_NAME_MAX _SC_HOST_NAME_MAX But 64 should be the limit of the host component, not for the whole hostname, as also noted by @ploxiln So use our own EVDNS_NAME_MAX const, which is set to 255. Fixes: #1280
This commit is contained in:
parent
1933f6aadd
commit
5ff98dc1f3
10
evdns.c
10
evdns.c
@ -122,8 +122,8 @@
|
||||
#define EVDNS_LOG_WARN EVENT_LOG_WARN
|
||||
#define EVDNS_LOG_MSG EVENT_LOG_MSG
|
||||
|
||||
#ifndef HOST_NAME_MAX
|
||||
#define HOST_NAME_MAX 255
|
||||
#ifndef EVDNS_NAME_MAX
|
||||
#define EVDNS_NAME_MAX 255
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@ -1350,7 +1350,7 @@ reply_parse(struct evdns_base *base, u8 *packet, int length)
|
||||
* to parse the response. To simplify things let's just allocate
|
||||
* a little bit more to avoid complex evaluations.
|
||||
*/
|
||||
buf_size = MAX(length - j, HOST_NAME_MAX);
|
||||
buf_size = MAX(length - j, EVDNS_NAME_MAX);
|
||||
reply.data.raw = mm_malloc(buf_size);
|
||||
|
||||
/* now we have the answer section which looks like
|
||||
@ -1394,7 +1394,7 @@ reply_parse(struct evdns_base *base, u8 *packet, int length)
|
||||
reply.have_answer = 1;
|
||||
break;
|
||||
} else if (type == TYPE_CNAME) {
|
||||
char cname[HOST_NAME_MAX];
|
||||
char cname[EVDNS_NAME_MAX];
|
||||
if (name_parse(packet, length, &j, cname,
|
||||
sizeof(cname))<0)
|
||||
goto err;
|
||||
@ -3982,7 +3982,7 @@ evdns_search_ndots_set(const int ndots) {
|
||||
|
||||
static void
|
||||
search_set_from_hostname(struct evdns_base *base) {
|
||||
char hostname[HOST_NAME_MAX + 1], *domainname;
|
||||
char hostname[EVDNS_NAME_MAX + 1], *domainname;
|
||||
|
||||
ASSERT_LOCKED(base);
|
||||
search_postfix_clear(base);
|
||||
|
@ -98,6 +98,13 @@
|
||||
#define REPEAT_256(address) \
|
||||
REPEAT_128(address) "," REPEAT_128(address)
|
||||
|
||||
#define HOST_NAME_MAX_NAME "1111111111111111111111111111111111111111111111111." /* 50 */ \
|
||||
"1111111111111111111111111111111111111111111111111." /* 100 */ \
|
||||
"1111111111111111111111111111111111111111111111111." /* 150 */ \
|
||||
"1111111111111111111111111111111111111111111111111." /* 200 */ \
|
||||
"1111111111111111111111111111.both-canonical.exampl" /* 250 */ \
|
||||
"e.co" /* 254 */
|
||||
|
||||
static int dns_ok = 0;
|
||||
static int dns_got_cancel = 0;
|
||||
static int dns_err = 0;
|
||||
@ -1265,6 +1272,16 @@ be_getaddrinfo_server_cb(struct evdns_server_request *req, void *data)
|
||||
}
|
||||
evdns_server_request_add_cname_reply(req, qname,
|
||||
"both-canonical.example.com", 1000);
|
||||
} else if (!evutil_ascii_strcasecmp(qname,
|
||||
"long.example.com")) {
|
||||
if (qtype == EVDNS_TYPE_A) {
|
||||
ans.s_addr = htonl(0x12345678);
|
||||
evdns_server_request_add_a_reply(req, qname,
|
||||
1, &ans.s_addr, 2000);
|
||||
added_any = 1;
|
||||
}
|
||||
evdns_server_request_add_cname_reply(req, qname,
|
||||
HOST_NAME_MAX_NAME, 1000);
|
||||
} else if (!evutil_ascii_strcasecmp(qname,
|
||||
"v4only.example.com") ||
|
||||
!evutil_ascii_strcasecmp(qname, "v4assert.example.com")) {
|
||||
@ -1599,7 +1616,7 @@ test_getaddrinfo_async(void *arg)
|
||||
struct basic_test_data *data = arg;
|
||||
struct evutil_addrinfo hints, *a;
|
||||
struct gai_outcome local_outcome;
|
||||
struct gai_outcome a_out[12];
|
||||
struct gai_outcome a_out[13];
|
||||
unsigned i;
|
||||
struct evdns_getaddrinfo_request *r;
|
||||
char buf[128];
|
||||
@ -1862,6 +1879,14 @@ test_getaddrinfo_async(void *arg)
|
||||
r, &tv);
|
||||
}
|
||||
|
||||
/* 12: Request for hostnames longer then 63 (#1280) -> HOST_NAME_MAX_NAME. */
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = EVUTIL_AI_CANONNAME;
|
||||
r = evdns_getaddrinfo(dns_base, "long.example.com", "8000",
|
||||
&hints, gai_cb, &a_out[12]);
|
||||
tt_assert(r);
|
||||
|
||||
/* XXXXX There are more tests we could do, including:
|
||||
|
||||
- A test to elicit NODATA.
|
||||
@ -1955,6 +1980,14 @@ test_getaddrinfo_async(void *arg)
|
||||
tt_int_op(a_out[11].err, ==, EVUTIL_EAI_CANCEL);
|
||||
tt_assert(a_out[11].ai == NULL);
|
||||
|
||||
/* 12: HOST_NAME_MAX_NAME */
|
||||
tt_int_op(a_out[12].err, ==, 0);
|
||||
tt_assert(a_out[12].ai);
|
||||
tt_assert(! a_out[12].ai->ai_next);
|
||||
test_ai_eq(a_out[12].ai, "18.52.86.120:8000", SOCK_STREAM, IPPROTO_TCP);
|
||||
tt_str_op(a_out[12].ai->ai_canonname, ==, HOST_NAME_MAX_NAME);
|
||||
|
||||
|
||||
end:
|
||||
if (local_outcome.ai)
|
||||
evutil_freeaddrinfo(local_outcome.ai);
|
||||
|
Loading…
x
Reference in New Issue
Block a user