@ -55,6 +55,10 @@ static int send_msg(struct UTUN_INSTANCE* inst, uint64_t dst, uint8_t subcmd, ui
e - > dgram [ 1 ] = subcmd ;
e - > dgram [ 1 ] = subcmd ;
memcpy ( e - > dgram + 2 , & sid , 4 ) ;
memcpy ( e - > dgram + 2 , & sid , 4 ) ;
if ( len > 0 ) memcpy ( e - > dgram + TCP_PROXY_HDR_SIZE , data , len ) ;
if ( len > 0 ) memcpy ( e - > dgram + TCP_PROXY_HDR_SIZE , data , len ) ;
if ( TCP_PROXY_HDR_SIZE + len > UINT16_MAX ) {
DEBUG_ERROR ( DEBUG_CATEGORY_SOCKET , " socks_proxy: msg too large len=%zu subcmd=%02x " , len , subcmd ) ;
queue_dgram_free ( e ) ; queue_entry_free ( e ) ; return - 1 ;
}
e - > len = ( uint16_t ) ( TCP_PROXY_HDR_SIZE + len ) ;
e - > len = ( uint16_t ) ( TCP_PROXY_HDR_SIZE + len ) ;
return etcp_route_send ( inst , dst , e , force ) ;
return etcp_route_send ( inst , dst , e , force ) ;
}
}
@ -97,6 +101,12 @@ static int write_to_client(struct socks_proxy_conn* c, const uint8_t* data, uint
if ( e ) queue_entry_free ( e ) ; if ( buf ) memory_pool_free ( c - > tc - > data_pool , buf ) ;
if ( e ) queue_entry_free ( e ) ; if ( buf ) memory_pool_free ( c - > tc - > data_pool , buf ) ;
return - 1 ;
return - 1 ;
}
}
if ( len > c - > tc - > data_pool - > object_size ) {
DEBUG_ERROR ( DEBUG_CATEGORY_SOCKET , " socks_proxy: write_to_client len=%u > pool_sz=%zu sid=%08x " ,
len , c - > tc - > data_pool - > object_size , c - > stream_id ) ;
queue_entry_free ( e ) ; memory_pool_free ( c - > tc - > data_pool , buf ) ;
return - 1 ;
}
memcpy ( buf , data , len ) ;
memcpy ( buf , data , len ) ;
e - > dgram = buf ; e - > len = len ;
e - > dgram = buf ; e - > len = len ;
queue_data_put ( c - > tc - > write_queue , e ) ;
queue_data_put ( c - > tc - > write_queue , e ) ;
@ -361,6 +371,11 @@ int socks_proxy_handle_etcp(struct socks_proxy_conn** head, int* count,
if ( subcmd = = TCP_PROXY_SUBCMD_DATA ) {
if ( subcmd = = TCP_PROXY_SUBCMD_DATA ) {
if ( data_len > 0 ) {
if ( data_len > 0 ) {
if ( data_len > c - > tc - > data_pool - > object_size ) {
DEBUG_ERROR ( DEBUG_CATEGORY_SOCKET , " socks_proxy: data_len=%zu > pool_sz=%zu, dropping sid=%08x " ,
data_len , c - > tc - > data_pool - > object_size , stream_id ) ;
return 1 ;
}
struct ll_entry * e = queue_entry_new_from_pool ( c - > tc - > entry_pool ) ;
struct ll_entry * e = queue_entry_new_from_pool ( c - > tc - > entry_pool ) ;
uint8_t * buf = memory_pool_alloc ( c - > tc - > data_pool ) ;
uint8_t * buf = memory_pool_alloc ( c - > tc - > data_pool ) ;
if ( e & & buf ) {
if ( e & & buf ) {
@ -403,6 +418,8 @@ int socks_proxy_handle_etcp(struct socks_proxy_conn** head, int* count,
void socks_proxy_conn_free ( struct socks_proxy_conn * c ) {
void socks_proxy_conn_free ( struct socks_proxy_conn * c ) {
if ( ! c ) return ;
if ( ! c ) return ;
if ( c - > freed ) return ;
c - > freed = 1 ;
struct socks_proxy_conn * * head = c - > head ; int * count = c - > count ;
struct socks_proxy_conn * * head = c - > head ; int * count = c - > count ;
DEBUG_INFO ( DEBUG_CATEGORY_SOCKET , " socks_proxy: FREE sid=%08x state=%d total=%d " , c - > stream_id , c - > state , count ? * count : 0 ) ;
DEBUG_INFO ( DEBUG_CATEGORY_SOCKET , " socks_proxy: FREE sid=%08x state=%d total=%d " , c - > stream_id , c - > state , count ? * count : 0 ) ;
if ( c - > close_pending & & c - > inst ) {
if ( c - > close_pending & & c - > inst ) {