From db445e70102624344705fe4c3c30dea79aa7c039 Mon Sep 17 00:00:00 2001 From: zxlhhyccc Date: Fri, 3 Jul 2026 21:44:13 +0800 Subject: [PATCH] shadowsocksr-libev: Fix bug. --- .../patches/106-fix-severity-security.patch | 21 ++++++++++++ .../patches/107-fix-encrypt.patch | 33 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 shadowsocksr-libev/patches/106-fix-severity-security.patch create mode 100644 shadowsocksr-libev/patches/107-fix-encrypt.patch diff --git a/shadowsocksr-libev/patches/106-fix-severity-security.patch b/shadowsocksr-libev/patches/106-fix-severity-security.patch new file mode 100644 index 00000000..71884717 --- /dev/null +++ b/shadowsocksr-libev/patches/106-fix-severity-security.patch @@ -0,0 +1,21 @@ +--- a/libev/ev.c ++++ b/libev/ev.c +@@ -1946,7 +1946,7 @@ static void * noinline ecb_cold + array_realloc (int elem, void *base, int *cur, int cnt) + { + *cur = array_nextsize (elem, *cur, cnt); +- return ev_realloc (base, elem * *cur); ++ return ev_realloc (base, (size_t)elem * (size_t)*cur); + } + + #define array_init_zero(base,count) \ +@@ -4252,7 +4252,8 @@ infy_add (EV_P_ ev_stat *w) + if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) + { + char path [4096]; +- strcpy (path, w->path); ++ strncpy (path, w->path, sizeof (path) - 1); ++ path [sizeof (path) - 1] = 0; + + do + { diff --git a/shadowsocksr-libev/patches/107-fix-encrypt.patch b/shadowsocksr-libev/patches/107-fix-encrypt.patch new file mode 100644 index 00000000..f266697e --- /dev/null +++ b/shadowsocksr-libev/patches/107-fix-encrypt.patch @@ -0,0 +1,33 @@ +--- a/server/encrypt.c ++++ b/server/encrypt.c +@@ -320,8 +320,8 @@ static void + merge(uint8_t *left, int llength, uint8_t *right, + int rlength, uint32_t salt, uint64_t key) + { +- uint8_t *ltmp = (uint8_t *)malloc(llength * sizeof(uint8_t)); +- uint8_t *rtmp = (uint8_t *)malloc(rlength * sizeof(uint8_t)); ++ uint8_t *ltmp = (uint8_t *)malloc(llength); ++ uint8_t *rtmp = (uint8_t *)malloc(rlength); + + uint8_t *ll = ltmp; + uint8_t *rr = rtmp; +@@ -783,7 +783,7 @@ cipher_context_set_iv(cipher_ctx_t *ctx, + } + + if (!enc) { +- memcpy(ctx->iv, iv, iv_len); ++ memcpy(ctx->iv, iv, min(iv_len, MAX_IV_LENGTH)); + } + + if (enc_method >= SALSA20) { +@@ -803,8 +803,8 @@ cipher_context_set_iv(cipher_ctx_t *ctx, + #ifdef USE_CRYPTO_APPLECC + cipher_cc_t *cc = &ctx->cc; + if (cc->valid == kCCContextValid) { +- memcpy(cc->iv, iv, iv_len); +- memcpy(cc->key, true_key, enc_key_len); ++ memcpy(cc->iv, iv, min(iv_len, MAX_IV_LENGTH)); ++ memcpy(cc->key, true_key, min(enc_key_len, MAX_KEY_LENGTH)); + cc->iv_len = iv_len; + cc->key_len = enc_key_len; + cc->encrypt = enc ? kCCEncrypt : kCCDecrypt;