Skip to content

Commit

Permalink
dns_server: fix some DOH server issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Nov 11, 2023
1 parent ef806ec commit 591aff2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/dns_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,13 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
server->server_flag = server_flag;
server->ttl = ttl;
server->drop_packet_latency_ms = drop_packet_latency_ms;

if (server->type == DNS_SERVER_HTTPS) {
if (server->path[0] == 0) {
safe_strncpy(server->path, "/", sizeof(server->path));
}
}

dns_conf_server_num++;
tlog(TLOG_DEBUG, "add server %s, flag: %X, ttl: %d", ip, result_flag, ttl);

Expand Down
20 changes: 12 additions & 8 deletions src/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ static int _dns_server_reply_https(struct dns_request *request, struct dns_serve

http_len = snprintf((char *)inpacket, DNS_IN_PACKSIZE,
"HTTP/1.1 200 OK\r\n"
"content-type: application/dns-message\r\n"
"Content-Type: application/dns-message\r\n"
"Content-Length: %d\r\n"
"\r\n",
len);
Expand Down Expand Up @@ -6205,12 +6205,12 @@ static int _dns_server_tcp_process_one_request(struct dns_server_conn_tcp_client
goto out;
}

tlog(TLOG_DEBUG, "remote server not supported.");
tlog(TLOG_DEBUG, "parser http header failed.");
goto errout;
}

if (http_head_get_method(http_head) != HTTP_METHOD_POST) {
tlog(TLOG_DEBUG, "remote server not supported.");
tlog(TLOG_DEBUG, "http method is invalid.");
goto errout;
}

Expand All @@ -6224,15 +6224,14 @@ static int _dns_server_tcp_process_one_request(struct dns_server_conn_tcp_client
request_len = http_head_get_data_len(http_head);
if (request_len >= len) {
tlog(TLOG_DEBUG, "request length is invalid.");

goto errout;
}
request_data = (unsigned char *)http_head_get_data(http_head);
proceed_len += len;
} else {
if ((total_len - proceed_len) <= (int)sizeof(unsigned short)) {
ret = RECV_ERROR_AGAIN;
break;
goto out;
}

/* Get record length */
Expand All @@ -6241,12 +6240,12 @@ static int _dns_server_tcp_process_one_request(struct dns_server_conn_tcp_client

if (request_len >= sizeof(tcpclient->recvbuff.buf)) {
tlog(TLOG_DEBUG, "request length is invalid.");
return RECV_ERROR_FAIL;
goto errout;
}

if (request_len > (total_len - proceed_len - sizeof(unsigned short))) {
ret = RECV_ERROR_AGAIN;
break;
goto out;
}

request_data = (unsigned char *)(tcpclient->recvbuff.buf + proceed_len + sizeof(unsigned short));
Expand All @@ -6257,7 +6256,12 @@ static int _dns_server_tcp_process_one_request(struct dns_server_conn_tcp_client
ret = _dns_server_recv(&tcpclient->head, request_data, request_len, &tcpclient->localaddr,
tcpclient->localaddr_len, &tcpclient->addr, tcpclient->addr_len);
if (ret != 0) {
return ret;
goto errout;
}

if (http_head != NULL) {
http_head_destroy(http_head);
http_head = NULL;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/http_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ int http_head_parse(struct http_head *http_head, const char *data, int data_len)
if (http_head->head_ok == 0) {
for (i = 0; i < data_len; i++, data++) {
*(buff_end + i) = *data;
if (isprint(*data) == 0 && isspace(*data) == 0) {
return -2;
}

if (*data == '\n') {
if (http_head->buff_len + i < 2) {
continue;
Expand Down

0 comments on commit 591aff2

Please sign in to comment.