Fix crash bug
This commit is contained in:
25
src/dns.c
25
src/dns.c
@@ -1586,6 +1586,10 @@ static int _dns_decode_an(struct dns_context *context, dns_rr_type type)
|
|||||||
dns_set_OPT_payload_size(packet, qclass);
|
dns_set_OPT_payload_size(packet, qclass);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
|
if (_dns_left_len(context) < rr_len) {
|
||||||
|
tlog(TLOG_DEBUG, "length mitchmatch\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
context->ptr += rr_len;
|
context->ptr += rr_len;
|
||||||
tlog(TLOG_DEBUG, "DNS type = %d not supported", qtype);
|
tlog(TLOG_DEBUG, "DNS type = %d not supported", qtype);
|
||||||
break;
|
break;
|
||||||
@@ -1661,41 +1665,46 @@ static int _dns_decode_body(struct dns_context *context)
|
|||||||
struct dns_head *head = &packet->head;
|
struct dns_head *head = &packet->head;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
for (i = 0; i < head->qdcount; i++) {
|
count = head->qdcount;
|
||||||
|
head->qdcount = 0;
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
ret = _dns_decode_qd(context);
|
ret = _dns_decode_qd(context);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tlog(TLOG_DEBUG, "decode qd failed.");
|
tlog(TLOG_DEBUG, "decode qd failed.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
head->qdcount--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < head->ancount; i++) {
|
count = head->ancount;
|
||||||
|
head->ancount = 0;
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
ret = _dns_decode_an(context, DNS_RRS_AN);
|
ret = _dns_decode_an(context, DNS_RRS_AN);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tlog(TLOG_DEBUG, "decode an failed.");
|
tlog(TLOG_DEBUG, "decode an failed.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
head->ancount--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < head->nscount; i++) {
|
count = head->nscount;
|
||||||
|
head->nscount = 0;
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
ret = _dns_decode_an(context, DNS_RRS_NS);
|
ret = _dns_decode_an(context, DNS_RRS_NS);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tlog(TLOG_DEBUG, "decode ns failed.");
|
tlog(TLOG_DEBUG, "decode ns failed.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
head->nscount--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < head->nrcount; i++) {
|
count = head->nrcount;
|
||||||
|
head->nrcount = 0;
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
ret = _dns_decode_an(context, DNS_RRS_NR);
|
ret = _dns_decode_an(context, DNS_RRS_NR);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tlog(TLOG_DEBUG, "decode nr failed.");
|
tlog(TLOG_DEBUG, "decode nr failed.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
head->nrcount--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -986,7 +986,7 @@ static int _dns_client_socket_ssl_send(SSL *ssl, const void *buf, int num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = SSL_write(ssl, buf, num);
|
ret = SSL_write(ssl, buf, num);
|
||||||
if (ret > 0) {
|
if (ret >= 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1131,7 +1131,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
tlog(TLOG_ERROR, "recv failed, %s, %d\n", strerror(errno), errno);
|
tlog(TLOG_ERROR, "recv failed, %s\n", strerror(errno));
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1211,8 +1211,12 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
|
|||||||
/* send data in send_buffer */
|
/* send data in send_buffer */
|
||||||
len = _dns_client_socket_send(server_info);
|
len = _dns_client_socket_send(server_info);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
|
if (errno == EAGAIN) {
|
||||||
|
pthread_mutex_unlock(&client.server_list_lock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
pthread_mutex_unlock(&client.server_list_lock);
|
pthread_mutex_unlock(&client.server_list_lock);
|
||||||
return -1;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
server_info->send_buff.len -= len;
|
server_info->send_buff.len -= len;
|
||||||
@@ -1233,7 +1237,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
|
|||||||
event.data.ptr = server_info;
|
event.data.ptr = server_info;
|
||||||
if (epoll_ctl(client.epoll_fd, EPOLL_CTL_MOD, server_info->fd, &event) != 0) {
|
if (epoll_ctl(client.epoll_fd, EPOLL_CTL_MOD, server_info->fd, &event) != 0) {
|
||||||
tlog(TLOG_ERROR, "epoll ctl failed.");
|
tlog(TLOG_ERROR, "epoll ctl failed.");
|
||||||
return -1;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user