Browse Source

Fix #761

pull/773/head
Max Lv 8 years ago
parent
commit
915047e957
1 changed files with 11 additions and 11 deletions
  1. 22
      src/udprelay.c

22
src/udprelay.c

@ -645,7 +645,7 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
memset(&src_addr, 0, src_addr_len); memset(&src_addr, 0, src_addr_len);
buffer_t *buf = ss_malloc(sizeof(buffer_t)); buffer_t *buf = ss_malloc(sizeof(buffer_t));
balloc(buf, packet_size);
balloc(buf, buf_size);
// recv // recv
r = recvfrom(remote_ctx->fd, buf->array, buf_size, 0, (struct sockaddr *)&src_addr, &src_addr_len); r = recvfrom(remote_ctx->fd, buf->array, buf_size, 0, (struct sockaddr *)&src_addr, &src_addr_len);
@ -663,7 +663,7 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
buf->len = r; buf->len = r;
#ifdef MODULE_LOCAL #ifdef MODULE_LOCAL
int err = ss_decrypt_all(buf, server_ctx->method, 0, packet_size);
int err = ss_decrypt_all(buf, server_ctx->method, 0, buf_size);
if (err) { if (err) {
// drop the packet silently // drop the packet silently
goto CLEAN_UP; goto CLEAN_UP;
@ -697,7 +697,7 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
memmove(buf->array, buf->array + len, buf->len); memmove(buf->array, buf->array + len, buf->len);
#else #else
// Construct packet // Construct packet
brealloc(buf, buf->len + 3, packet_size);
brealloc(buf, buf->len + 3, buf_size);
memmove(buf->array + 3, buf->array, buf->len); memmove(buf->array + 3, buf->array, buf->len);
memset(buf->array, 0, 3); memset(buf->array, 0, 3);
buf->len += 3; buf->len += 3;
@ -718,12 +718,12 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
} }
// Construct packet // Construct packet
brealloc(buf, buf->len + addr_header_len, packet_size);
brealloc(buf, buf->len + addr_header_len, buf_size);
memmove(buf->array + addr_header_len, buf->array, buf->len); memmove(buf->array + addr_header_len, buf->array, buf->len);
memcpy(buf->array, addr_header, addr_header_len); memcpy(buf->array, addr_header, addr_header_len);
buf->len += addr_header_len; buf->len += addr_header_len;
int err = ss_encrypt_all(buf, server_ctx->method, 0, packet_size);
int err = ss_encrypt_all(buf, server_ctx->method, 0, buf_size);
if (err) { if (err) {
// drop the packet silently // drop the packet silently
goto CLEAN_UP; goto CLEAN_UP;
@ -797,7 +797,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
memset(&src_addr, 0, sizeof(struct sockaddr_storage)); memset(&src_addr, 0, sizeof(struct sockaddr_storage));
buffer_t *buf = ss_malloc(sizeof(buffer_t)); buffer_t *buf = ss_malloc(sizeof(buffer_t));
balloc(buf, packet_size);
balloc(buf, buf_size);
socklen_t src_addr_len = sizeof(struct sockaddr_storage); socklen_t src_addr_len = sizeof(struct sockaddr_storage);
unsigned int offset = 0; unsigned int offset = 0;
@ -815,7 +815,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
msg.msg_controllen = sizeof(control_buffer); msg.msg_controllen = sizeof(control_buffer);
iov[0].iov_base = buf->array; iov[0].iov_base = buf->array;
iov[0].iov_len = packet_size;
iov[0].iov_len = buf_size;
msg.msg_iov = iov; msg.msg_iov = iov;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
@ -860,7 +860,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
tx += buf->len; tx += buf->len;
int err = ss_decrypt_all(buf, server_ctx->method, server_ctx->auth, packet_size);
int err = ss_decrypt_all(buf, server_ctx->method, server_ctx->auth, buf_size);
if (err) { if (err) {
// drop the packet silently // drop the packet silently
goto CLEAN_UP; goto CLEAN_UP;
@ -928,7 +928,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
} }
// reconstruct the buffer // reconstruct the buffer
brealloc(buf, buf->len + addr_header_len, packet_size);
brealloc(buf, buf->len + addr_header_len, buf_size);
memmove(buf->array + addr_header_len, buf->array, buf->len); memmove(buf->array + addr_header_len, buf->array, buf->len);
memcpy(buf->array, addr_header, addr_header_len); memcpy(buf->array, addr_header, addr_header_len);
buf->len += addr_header_len; buf->len += addr_header_len;
@ -982,7 +982,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
addr_header_len += 2; addr_header_len += 2;
// reconstruct the buffer // reconstruct the buffer
brealloc(buf, buf->len + addr_header_len, packet_size);
brealloc(buf, buf->len + addr_header_len, buf_size);
memmove(buf->array + addr_header_len, buf->array, buf->len); memmove(buf->array + addr_header_len, buf->array, buf->len);
memcpy(buf->array, addr_header, addr_header_len); memcpy(buf->array, addr_header, addr_header_len);
buf->len += addr_header_len; buf->len += addr_header_len;
@ -1120,7 +1120,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents)
buf->array[0] |= ONETIMEAUTH_FLAG; buf->array[0] |= ONETIMEAUTH_FLAG;
} }
int err = ss_encrypt_all(buf, server_ctx->method, server_ctx->auth, packet_size);
int err = ss_encrypt_all(buf, server_ctx->method, server_ctx->auth, buf_size);
if (err) { if (err) {
// drop the packet silently // drop the packet silently

Loading…
Cancel
Save