From 703374cae80ad1e46ced913c38a9c9ad5b50951e Mon Sep 17 00:00:00 2001 From: Max Lv Date: Wed, 16 Sep 2015 09:53:36 +0800 Subject: [PATCH] fix a buf issue --- src/encrypt.c | 3 ++- src/encrypt.h | 2 +- src/local.c | 4 ++-- src/redir.c | 2 +- src/tunnel.c | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/encrypt.c b/src/encrypt.c index 2064735d..27b1510e 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -1506,7 +1506,7 @@ int ss_check_crc(char *buf, ssize_t *buf_len, char *crc_buf, ssize_t *crc_idx) return 1; } -void ss_gen_crc(char *buf, ssize_t *buf_len, char *crc_buf, ssize_t *crc_idx, int buf_size) +char *ss_gen_crc(char *buf, ssize_t *buf_len, char *crc_buf, ssize_t *crc_idx, int buf_size) { int i, j; ssize_t blen = *buf_len; @@ -1528,4 +1528,5 @@ void ss_gen_crc(char *buf, ssize_t *buf_len, char *crc_buf, ssize_t *crc_idx, in } *buf_len = j; *crc_idx = cidx; + return buf; } diff --git a/src/encrypt.h b/src/encrypt.h index b7b5a3a9..d2cf82f5 100644 --- a/src/encrypt.h +++ b/src/encrypt.h @@ -173,6 +173,6 @@ int ss_onetimeauth(char *auth, char *msg, int msg_len); int ss_onetimeauth_verify(char *auth, char *msg, int msg_len); int ss_check_crc(char *buf, ssize_t *buf_len, char *crc_buf, ssize_t *crc_idx); -void ss_gen_crc(char *buf, ssize_t *buf_len, char *crc_buf, ssize_t *crc_idx, int buf_size); +char * ss_gen_crc(char *buf, ssize_t *buf_len, char *crc_buf, ssize_t *crc_idx, int buf_size); #endif // _ENCRYPT_H diff --git a/src/local.c b/src/local.c index 34ec6601..0698a89f 100644 --- a/src/local.c +++ b/src/local.c @@ -245,7 +245,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) } if (remote->send_ctx->connected && auth) { - ss_gen_crc(remote->buf, &r, remote->crc_buf, &remote->crc_idx, BUF_SIZE); + remote->buf = ss_gen_crc(remote->buf, &r, remote->crc_buf, &remote->crc_idx, BUF_SIZE); } // insert shadowsocks header @@ -484,7 +484,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) memcpy(remote->buf, ss_addr_to_send, addr_len); if (auth) { - ss_gen_crc(buf, &r, remote->crc_buf, &remote->crc_idx, BUF_SIZE); + buf = ss_gen_crc(buf, &r, remote->crc_buf, &remote->crc_idx, BUF_SIZE); } if (r > 0) { diff --git a/src/redir.c b/src/redir.c index 9a4c3852..d42d4eb7 100644 --- a/src/redir.c +++ b/src/redir.c @@ -185,7 +185,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) } if (auth) { - ss_gen_crc(remote->buf, &r, remote->crc_buf, &remote->crc_idx, BUF_SIZE); + remote->buf = ss_gen_crc(remote->buf, &r, remote->crc_buf, &remote->crc_idx, BUF_SIZE); } remote->buf = ss_encrypt(BUF_SIZE, remote->buf, &r, server->e_ctx); diff --git a/src/tunnel.c b/src/tunnel.c index 6504a463..ad6cf13a 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -197,7 +197,7 @@ static void server_recv_cb(EV_P_ ev_io *w, int revents) } if (auth) { - ss_gen_crc(remote->buf, &r, remote->crc_buf, &remote->crc_idx, BUF_SIZE); + remote->buf = ss_gen_crc(remote->buf, &r, remote->crc_buf, &remote->crc_idx, BUF_SIZE); } remote->buf = ss_encrypt(BUF_SIZE, remote->buf, &r, server->e_ctx);