Fix crash bug

This commit is contained in:
Nick Peng
2019-01-25 23:34:56 +08:00
parent 6e5fc54439
commit 65ede47cf7
2 changed files with 25 additions and 12 deletions

View File

@@ -1586,6 +1586,10 @@ static int _dns_decode_an(struct dns_context *context, dns_rr_type type)
dns_set_OPT_payload_size(packet, qclass);
} break;
default:
if (_dns_left_len(context) < rr_len) {
tlog(TLOG_DEBUG, "length mitchmatch\n");
return -1;
}
context->ptr += rr_len;
tlog(TLOG_DEBUG, "DNS type = %d not supported", qtype);
break;
@@ -1661,41 +1665,46 @@ static int _dns_decode_body(struct dns_context *context)
struct dns_head *head = &packet->head;
int i = 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);
if (ret < 0) {
tlog(TLOG_DEBUG, "decode qd failed.");
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);
if (ret < 0) {
tlog(TLOG_DEBUG, "decode an failed.");
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);
if (ret < 0) {
tlog(TLOG_DEBUG, "decode ns failed.");
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);
if (ret < 0) {
tlog(TLOG_DEBUG, "decode nr failed.");
return -1;
}
head->nrcount--;
}
return 0;

View File

@@ -986,7 +986,7 @@ static int _dns_client_socket_ssl_send(SSL *ssl, const void *buf, int num)
}
ret = SSL_write(ssl, buf, num);
if (ret > 0) {
if (ret >= 0) {
return ret;
}
@@ -1131,7 +1131,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
goto errout;
}
tlog(TLOG_ERROR, "recv failed, %s, %d\n", strerror(errno), errno);
tlog(TLOG_ERROR, "recv failed, %s\n", strerror(errno));
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 */
len = _dns_client_socket_send(server_info);
if (len < 0) {
if (errno == EAGAIN) {
pthread_mutex_unlock(&client.server_list_lock);
return 0;
}
pthread_mutex_unlock(&client.server_list_lock);
return -1;
goto errout;
}
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;
if (epoll_ctl(client.epoll_fd, EPOLL_CTL_MOD, server_info->fd, &event) != 0) {
tlog(TLOG_ERROR, "epoll ctl failed.");
return -1;
goto errout;
}
return 0;