From ec1313fd37637ff087f796d31980b56191cadb7c Mon Sep 17 00:00:00 2001 From: jenrryyou Date: Wed, 17 May 2023 21:22:30 +0800 Subject: [PATCH] Fix stack buffer overflow issue when calling copy_to_cstr --- src/brpc/input_messenger.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/brpc/input_messenger.cpp b/src/brpc/input_messenger.cpp index 699f080c0a..1234eef45b 100644 --- a/src/brpc/input_messenger.cpp +++ b/src/brpc/input_messenger.cpp @@ -101,7 +101,8 @@ ParseResult InputMessenger::CutInputMessage( return result; } else { if (m->_read_buf.size() >= 4) { - char data[PROTO_DUMMY_LEN]; + // The length of `data' must be PROTO_DUMMY_LEN + 1 to store extra ending char '\0' + char data[PROTO_DUMMY_LEN + 1]; m->_read_buf.copy_to_cstr(data, PROTO_DUMMY_LEN); if (strncmp(data, "RDMA", PROTO_DUMMY_LEN) == 0 && m->_rdma_state == Socket::RDMA_OFF) {