mirror of
https://codeberg.org/scip/udpxd.git
synced 2025-12-16 11:30:57 +01:00
Check for socket exhaustion and fix memory leak
This commit is contained in:
15
net.c
15
net.c
@@ -68,7 +68,7 @@ int bindsocket( host_t *sock_h) {
|
||||
fd = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
}
|
||||
|
||||
if( -1 == bind( fd, (struct sockaddr*)sock_h->sock, sock_h->size ) ) {
|
||||
if( ! ( fd >= 0 && -1 != bind( fd, (struct sockaddr*)sock_h->sock, sock_h->size ) ) ) {
|
||||
err = 1;
|
||||
}
|
||||
|
||||
@@ -270,14 +270,11 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
||||
len = recvfrom( inside, buffer, sizeof( buffer ), 0,
|
||||
(struct sockaddr*)src, (socklen_t *)&size );
|
||||
|
||||
if(len > 0) {
|
||||
if(listen_h->is_v6)
|
||||
src_h = get_host(NULL, 0, NULL, (struct sockaddr_in6 *)src);
|
||||
else
|
||||
src_h = get_host(NULL, 0, (struct sockaddr_in *)src, NULL);
|
||||
|
||||
free(src);
|
||||
|
||||
if(len > 0) {
|
||||
/* do we know it ? */
|
||||
client = client_find_src(src_h);
|
||||
if(client != NULL) {
|
||||
@@ -293,6 +290,7 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
||||
else {
|
||||
client_seen(client);
|
||||
}
|
||||
host_clean(src_h);
|
||||
}
|
||||
else {
|
||||
/* unknown client, open new out socket */
|
||||
@@ -301,7 +299,7 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
||||
verb_prbind(bind_h);
|
||||
|
||||
output = bindsocket(bind_h);
|
||||
|
||||
if (output >= 0) {
|
||||
/* send req out */
|
||||
if(sendto(output, buffer, len, 0, (struct sockaddr*)dst_h->sock, dst_h->size) < 0) {
|
||||
fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port);
|
||||
@@ -328,7 +326,12 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
||||
client_add(client);
|
||||
}
|
||||
}
|
||||
else {
|
||||
host_clean(src_h);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(src);
|
||||
}
|
||||
|
||||
/* handle answer from the outside */
|
||||
|
||||
Reference in New Issue
Block a user