1
0
mirror of https://github.com/solemnwarning/ipxwrapper synced 2024-12-30 16:45:37 +01:00

Check packet size and cache source IP in recv_packet. Destination network number is replaced with the source IP of the packet by the router thread.

This commit is contained in:
Daniel Collins 2011-09-07 20:37:18 +00:00
parent d046b6522d
commit 0b73241fe8
2 changed files with 20 additions and 2 deletions

View File

@ -204,7 +204,14 @@ DWORD router_main(void *arg) {
continue;
}
add_host(packet->src_net, packet->src_node, addr.sin_addr.s_addr);
/* Replace destination network field of packet with source IP address
* so that the client can cache it.
*/
char dest_net[4];
memcpy(dest_net, packet->dest_net, 4);
memcpy(packet->dest_net, &(addr.sin_addr.s_addr), 4);
struct router_addr *ra = router->addrs;
@ -212,7 +219,7 @@ DWORD router_main(void *arg) {
if(
ra->local_port &&
(ra->filter_ptype < 0 || ra->filter_ptype == packet->ptype) &&
(memcmp(packet->dest_net, ra->addr.sa_netnum, 4) == 0 || memcmp(packet->dest_net, f6, 4) == 0) &&
(memcmp(dest_net, ra->addr.sa_netnum, 4) == 0 || memcmp(dest_net, f6, 4) == 0) &&
(memcmp(packet->dest_node, ra->addr.sa_nodenum, 6) == 0 || memcmp(packet->dest_node, f6, 6) == 0) &&
packet->dest_socket == ra->addr.sa_socket
) {

View File

@ -322,6 +322,17 @@ static int recv_packet(ipx_socket *sockptr, char *buf, int bufsize, int flags, s
return -1;
}
if(rval < sizeof(ipx_packet) || rval != packet->size + sizeof(ipx_packet) - 1) {
log_printf("Invalid packet received on loopback port!");
free(packet);
WSASetLastError(WSAEWOULDBLOCK);
return -1;
}
/* Router thread replaces destination network number with source IP address */
add_host(packet->src_net, packet->src_node, *((uint32_t*)packet->dest_net));
if(addr) {
addr->sa_family = AF_IPX;
memcpy(addr->sa_netnum, packet->src_net, 4);