Skip to content

Commit

Permalink
Merge pull request #324 from pymumu/master
Browse files Browse the repository at this point in the history
Fork Sync
  • Loading branch information
PikuZheng authored Nov 18, 2024
2 parents 62e5f34 + fdc1a41 commit 45c4e85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/dns_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,20 @@ static void _dns_replied_check_remove(struct dns_query_struct *dns_query, struct
}
}

static int _dns_client_server_package_address_match(struct dns_server_info *server_info, struct sockaddr *addr,
socklen_t addr_len)
{
if (addr_len != server_info->ai_addrlen) {
return -1;
}

if (memcmp(addr, &server_info->addr, addr_len) != 0) {
return -1;
}

return 0;
}

static int _dns_client_recv(struct dns_server_info *server_info, unsigned char *inpacket, int inpacket_len,
struct sockaddr *from, socklen_t from_len)
{
Expand All @@ -1824,6 +1838,11 @@ static int _dns_client_recv(struct dns_server_info *server_info, unsigned char *

packet->head.tc = 0;

if (_dns_client_server_package_address_match(server_info, from, from_len) != 0) {
tlog(TLOG_DEBUG, "packet from invalid server.");
return -1;
}

/* decode domain from udp packet */
len = dns_decode(packet, DNS_PACKSIZE, inpacket, inpacket_len);
if (len != 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/tlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,16 +1080,17 @@ static void _tlog_close_all_fd(void)
}
}

close(dir_fd);

if (bytes < 0) {
goto errout;
}

close(dir_fd);
return;
errout:
if (dir_fd > 0) {
close(dir_fd);
dir_fd = -1;
}
#endif
_tlog_close_all_fd_by_res();
Expand Down

0 comments on commit 45c4e85

Please sign in to comment.