BugFix: tcp server process failed

This commit is contained in:
Nick Peng
2019-12-28 21:57:56 +08:00
parent ba9fbc981f
commit 198d18f18a
2 changed files with 12 additions and 5 deletions

View File

@@ -1821,6 +1821,10 @@ static int _dns_client_process_tcp_buff(struct dns_server_info *server_info)
}
server_info->recv_buff.len -= len;
if (server_info->recv_buff.len < 0) {
tlog(TLOG_ERROR, "Internal error.");
abort();
}
/* move to next result */
if (server_info->recv_buff.len > 0) {
@@ -1879,7 +1883,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
time(&server_info->last_recv);
server_info->recv_buff.len += len;
if (server_info->recv_buff.len < 2) {
if (server_info->recv_buff.len <= 2) {
/* wait and recv */
return 0;
}
@@ -1916,6 +1920,9 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
server_info->send_buff.len -= len;
if (server_info->send_buff.len > 0) {
memmove(server_info->send_buff.data, server_info->send_buff.data + len, server_info->send_buff.len);
} else if (server_info->send_buff.len < 0) {
tlog(TLOG_ERROR, "Internal Error");
abort();
}
pthread_mutex_unlock(&client.server_list_lock);
}
@@ -1929,7 +1936,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
event.events = EPOLLIN;
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.");
tlog(TLOG_ERROR, "epoll ctl failed, %s", strerror(errno));
goto errout;
}
}
@@ -2128,7 +2135,7 @@ static int _dns_client_process_tls(struct dns_server_info *server_info, struct e
fd_event.data.ptr = server_info;
if (epoll_ctl(client.epoll_fd, EPOLL_CTL_MOD, server_info->fd, &fd_event) != 0) {
tlog(TLOG_ERROR, "epoll ctl failed.");
tlog(TLOG_ERROR, "epoll ctl failed, %s", strerror(errno));
goto errout;
}
@@ -2164,7 +2171,7 @@ static int _dns_client_process_tls(struct dns_server_info *server_info, struct e
fd_event.events = EPOLLIN | EPOLLOUT;
fd_event.data.ptr = server_info;
if (epoll_ctl(client.epoll_fd, EPOLL_CTL_MOD, server_info->fd, &fd_event) != 0) {
tlog(TLOG_ERROR, "epoll ctl failed.");
tlog(TLOG_ERROR, "epoll ctl failed, %s", strerror(errno));
goto errout;
}
}

View File

@@ -2501,7 +2501,7 @@ static int _dns_server_tcp_process_one_request(struct dns_server_conn_tcp_client
return RECV_ERROR_FAIL;
}
if (request_len > (total_len - proceed_len)) {
if (request_len > (total_len - proceed_len - sizeof(unsigned short))) {
ret = RECV_ERROR_AGAIN;
break;
}