Skip to content

Commit

Permalink
fix the bugs created after reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Apr 23, 2024
1 parent 7453c2a commit 57b0a1b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
8 changes: 6 additions & 2 deletions tunnels/adapters/connector/tcp/tcp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static bool resumeWriteQueue(tcp_connector_con_state_t *cstate)

unsigned int bytes = bufLen(cw->payload);
int nwrite = hio_write(io, cw->payload);
cw->payload = NULL;
cw->payload = NULL;
contextQueuePush(cstate->finished_queue, cw);
if (nwrite >= 0 && nwrite < bytes)
{
Expand Down Expand Up @@ -163,6 +163,10 @@ static void onClose(hio_t *io)
static void onOutBoundConnected(hio_t *upstream_io)
{
tcp_connector_con_state_t *cstate = hevent_userdata(upstream_io);
if (cstate == NULL)
{
return;
}
#ifdef PROFILE
struct timeval tv2;
gettimeofday(&tv2, NULL);
Expand Down Expand Up @@ -206,7 +210,7 @@ static void upStream(tunnel_t *self, context_t *c)
{
unsigned int bytes = bufLen(c->payload);
int nwrite = hio_write(cstate->io, c->payload);
c->payload = NULL;
c->payload = NULL;
if (nwrite >= 0 && nwrite < bytes)
{
if (c->src_io)
Expand Down
2 changes: 1 addition & 1 deletion tunnels/adapters/connector/udp/udp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void upStream(tunnel_t *self, context_t *c)
size_t nwrite = hio_write(cstate->io, c->payload);
c->payload = NULL;

assert(nwrite >= 0 && nwrite < bytes);
assert(nwrite <= 0 || nwrite == bytes);
destroyContext(c);
}
else
Expand Down
1 change: 0 additions & 1 deletion tunnels/adapters/listener/tcp/tcp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ static void cleanup(tcp_listener_con_state_t *cstate, bool write_queue)
{
reuseContextBuffer(cw);
}
reuseContextBuffer(cw);
destroyContext(cw);
}

Expand Down
18 changes: 6 additions & 12 deletions tunnels/server/trojan/socks/trojan_socks_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include "buffer_stream.h"
#include "hsocket.h"
#include "loggers/network_logger.h"
#include "utils/sockutils.h"
#include "utils/stringutils.h"
#include "utils/userutils.h"
#include "utils/sockutils.h"

#define CRLF_LEN 2

Expand Down Expand Up @@ -312,18 +312,12 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate,
dest_context->address_type = kSatDomainName;
// size_t addr_len = (unsigned char)(rawBuf(c->payload)[0]);
shiftr(c->payload, 1);
if (dest_context->domain == NULL)
if (! cstate->first_sent) // print once per connection
{
dest_context->domain = malloc(260);

if (! cstate->first_sent) // print once per connection
{
LOGD("TrojanSocksServer: udp domain %.*s", domain_len, rawBuf(c->payload));
}

memcpy(dest_context->domain, rawBuf(c->payload), domain_len);
dest_context->domain[domain_len] = 0;
LOGD("TrojanSocksServer: udp domain %.*s", domain_len, rawBuf(c->payload));
}

setSocketContextDomain(dest_context, rawBuf(c->payload), domain_len);
shiftr(c->payload, domain_len);

break;
Expand Down Expand Up @@ -534,7 +528,7 @@ static inline void upStream(tunnel_t *self, context_t *c)
memset(CSTATE(c), 0, sizeof(trojan_socks_server_con_state_t));
trojan_socks_server_con_state_t *cstate = CSTATE(c);
cstate->udp_buf = newBufferStream(getContextBufferPool(c));
allocateDomainBuffer(&(c->line->dest_ctx),true);
allocateDomainBuffer(&(c->line->dest_ctx), true);
destroyContext(c);
}
else if (c->fin)
Expand Down
1 change: 1 addition & 0 deletions ww/utils/sockutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ inline void allocateDomainBuffer(socket_context_t *scontext, bool freeable)
{
scontext->domain_constant = ! freeable;
scontext->domain = malloc(256);
scontext->domain_len = 0;
#ifdef DEBUG
memset(scontext->domain, 0xEE, 256);
#endif
Expand Down

0 comments on commit 57b0a1b

Please sign in to comment.