Compare commits

..

3 Commits

Author SHA1 Message Date
Vladimir Dubrovin
ec48b7f30e Clear mingw warnings
Some checks are pending
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
2026-05-06 23:07:16 +03:00
Vladimir Dubrovin
88a09bc3ff Fix socks v5 derivations from standard 2026-05-06 23:02:04 +03:00
Vladimir Dubrovin
0e13f57139 Allocate udp buffer dynamically 2026-05-06 22:45:00 +03:00
7 changed files with 32 additions and 13 deletions

View File

@ -163,14 +163,14 @@ int start_proxy_thread(struct child * chp){
_3proxy_sem_lock(conf.threadinit);
#ifdef _WIN32
#ifndef _WINCE
h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 32768+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
#else
h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, 32768+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
#endif
if(h)CloseHandle(h);
#else
pthread_attr_init(&pa);
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (65536+conf.stacksize));
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (32768+conf.stacksize));
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
pthread_create(&thread, &pa, startsrv, (void *)chp);
pthread_attr_destroy(&pa);

View File

@ -121,8 +121,12 @@ void daemonize(void);
#endif
#ifdef _WIN32
#ifndef strcasecmp
#define strcasecmp stricmp
#endif
#ifndef strncasecmp
#define strncasecmp strnicmp
#endif
#define seterrno3(x) _set_errno(x)
#else
#define seterrno3(x) (errno = x)

View File

@ -349,6 +349,14 @@ int MODULEMAINFUNC (int argc, char** argv){
#ifndef NOUDPMAIN
if(isudp) {
if(!udp_table.ihashtable)inithashtable(&udp_table, 64, 256, 65536);
srv.udpbuf = malloc(UDPBUFSIZE);
srv.udpbuf2 = malloc(UDPBUFSIZE);
if(!srv.udpbuf || !srv.udpbuf2) {
#ifndef STDMAIN
haveerror = 2;
#endif
return 11;
}
}
#endif
srv.service = defparam.service = childdef.service;
@ -995,8 +1003,8 @@ int MODULEMAINFUNC (int argc, char** argv){
if(hashresolv(&udp_table, &defparam, &toparam, NULL)) {
int i, len=0;
if(toparam->udp_nhops - 1){
for(i=1; i < toparam->udp_nhops - 1; i++){
if(toparam->udp_nhops){
for(i=1; i < toparam->udp_nhops; i++){
len+=socks5_udp_build_hdr(srv.udpbuf2+len, &toparam->udp_relay[i-1]);
}
len += socks5_udp_build_hdr(srv.udpbuf2+len, &toparam->req);
@ -1241,6 +1249,10 @@ void srvfree(struct srvparam * srv){
if(srv->onetns) free(srv->onetns);
#endif
if(srv->so.freefunc) srv->so.freefunc(srv->so.state);
#ifndef NOUDPMAIN
if(srv->udpbuf) free(srv->udpbuf);
if(srv->udpbuf2) free(srv->udpbuf2);
#endif
}

View File

@ -247,6 +247,8 @@ fflush(stderr);
sin = param->sincl;
*SAPORT(&sin) = 0;
if(param->srv->so._bind(param->sostate, param->clisock,(struct sockaddr *)&sin,SASIZE(&sin))) {RETURN (12);}
sasize = SASIZE(&sin);
param->srv->so._getsockname(param->sostate, param->clisock, (struct sockaddr *)&sin, &sasize);
#if SOCKSTRACE > 0
fprintf(stderr, "%hu binded to communicate with client\n",
ntohs(*SAPORT(&sin))
@ -264,7 +266,7 @@ fflush(stderr);
CLEANRET:
if(param->clisock != INVALID_SOCKET){
if(param->clisock != INVALID_SOCKET && buf){
int repcode;
sasize = sizeof(sin);
@ -285,7 +287,7 @@ CLEANRET:
}
}
#if SOCKSTRACE > 0
myinet_ntop(*SAFAMILY(&sin), &sin, tracebuf, SASIZE(&sin));
myinet_ntop(*SAFAMILY(&sin), SAADDR(&sin), tracebuf, SASIZE(&sin));
fprintf(stderr, "Sending confirmation to client with code %d for %s with %s:%hu\n",
param->res,
commands[command],
@ -299,6 +301,8 @@ fflush(stderr);
else if (param->res < 20) repcode = 5;
else if (param->res < 30) repcode = 1;
else if (param->res < 100) repcode = 4;
else if (param->res == 100) repcode = 4;
else if (param->res == 997) repcode = 8;
else repcode = param->res%10;
if(ver == 5){
@ -365,7 +369,7 @@ fflush(stderr);
param->res = 462;
break;
}
if(SAISNULL(&param->req) &&
if(!SAISNULL(&param->req) &&
memcmp(SAADDR(&param->req),SAADDR(&param->sinsr),SAADDRLEN(&param->req))) {
param->res = 470;
break;

View File

@ -569,11 +569,9 @@ struct srvparam {
uint16_t targetport;
unsigned char replace;
time_t time_start;
#ifndef NOUDPMAIN
unsigned char udpbuf[UDPBUFSIZE];
unsigned char udpbuf2[UDPBUFSIZE];
unsigned char *udpbuf;
unsigned char *udpbuf2;
int udplen;
#endif
};
struct clientparam {

View File

@ -75,7 +75,6 @@ void * udppmchild(struct clientparam* param) {
param->srvinbuf = 0;
param->nwrites++;
param->clisock = param->srv->srvsock;
param->udp_nhops++;
param->waitserver64 = 0x7fffffffffffffff;
param->res = udpsockmap(param, conf.timeouts[STRING_L]);
_3proxy_sem_lock(udpinit);

View File

@ -57,6 +57,8 @@ int udpsockmap(struct clientparam *param, int timeo)
int nhops = param->udp_nhops;
int clisock_idx = -1, ctrlsock_idx = -1, ctrlsocksrv_idx = -1;
int firstpacket = 1;
if(param->srv->service == S_UDPPM) nhops++;
if (param->srvbufsize < UDPBUFSIZE) {
unsigned char *newbuf = realloc(param->srvbuf, UDPBUFSIZE);
if (!newbuf) return 21;