summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@localhost.com>2021-01-29 12:14:33 +0800
committerdormando <dormando@rydia.net>2021-06-07 22:33:36 -0700
commit2f8add8838553db423acc2d526e89bb917c21814 (patch)
treed4748301c99fbe741f1bc8170f33131f2521ecf0
parent2a8b96105857dee237889f6a9e02d42352874e02 (diff)
downloadmemcached-2f8add8838553db423acc2d526e89bb917c21814.tar.gz
The total number of UDP datagrams required for the message is calculated incorrectly.
UDP_MAX_PAYLOAD_SIZE actually contains the length of the private UDP header, but resp->tosend only contains the length of the data part. The number of required UDP packets calculated by the original code will be less than the actual need. E.g: 1000000/1400 = 714.2 ceil 715 1000000/1392 = 718.3 ceil 719 Actually 719 datagrams are needed, and 715 is wrong. Signed-off-by: AK Deng <ttttabcd@protonmail.com>
-rw-r--r--memcached.c4
-rw-r--r--memcached.h1
2 files changed, 3 insertions, 2 deletions
diff --git a/memcached.c b/memcached.c
index f41a89d..54369cd 100644
--- a/memcached.c
+++ b/memcached.c
@@ -2635,8 +2635,8 @@ static void build_udp_header(unsigned char *hdr, mc_resp *resp) {
// header, so "tosend" must be static.
if (!resp->udp_total) {
uint32_t total;
- total = resp->tosend / UDP_MAX_PAYLOAD_SIZE;
- if (resp->tosend % UDP_MAX_PAYLOAD_SIZE)
+ total = resp->tosend / UDP_DATA_SIZE;
+ if (resp->tosend % UDP_DATA_SIZE)
total++;
// The spec doesn't really say what we should do here. It's _probably_
// better to bail out?
diff --git a/memcached.h b/memcached.h
index e569ad5..1202fa0 100644
--- a/memcached.h
+++ b/memcached.h
@@ -71,6 +71,7 @@
#define UDP_READ_BUFFER_SIZE 65536
#define UDP_MAX_PAYLOAD_SIZE 1400
#define UDP_HEADER_SIZE 8
+#define UDP_DATA_SIZE 1392 // UDP_MAX_PAYLOAD_SIZE - UDP_HEADER_SIZE
#define MAX_SENDBUF_SIZE (256 * 1024 * 1024)
/* Binary protocol stuff */