summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2023-12-30 14:48:15 +0000
committerChristian Hopps <chopps@labn.net>2023-12-30 16:03:45 +0000
commitb28cd405c82ec41e51e11e773594d88da1339edb (patch)
treed22a78f9d6ebe64bff70943dd761ef110a6ef0e5
parent913892e2adce7a622d75ffca730ad0b4be8580b0 (diff)
lib: fix coverity CID 1574979
Signed-off-by: Christian Hopps <chopps@labn.net>
-rw-r--r--lib/mgmt_msg.c5
-rw-r--r--lib/mgmt_msg.h2
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/mgmt_msg.c b/lib/mgmt_msg.c
index b03dbe8cc3..23cfbc3b01 100644
--- a/lib/mgmt_msg.c
+++ b/lib/mgmt_msg.c
@@ -111,6 +111,11 @@ enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd,
* therefor the stream is too small to fit the message..
* Resize the stream to fit.
*/
+ if (mhdr->len > MGMT_MSG_MAX_MSG_ALLOC_LEN) {
+ MGMT_MSG_ERR(ms, "corrupt msg len rcvd %u",
+ mhdr->len);
+ return MSR_DISCONNECT;
+ }
news = stream_new(mhdr->len);
stream_put(news, mhdr, left);
stream_set_endp(news, left);
diff --git a/lib/mgmt_msg.h b/lib/mgmt_msg.h
index 3195d4a7fb..6bdc9a6cfc 100644
--- a/lib/mgmt_msg.h
+++ b/lib/mgmt_msg.h
@@ -24,6 +24,8 @@ DECLARE_MTYPE(MSG_CONN);
#define MGMT_MSG_VERSION_PROTOBUF 0
#define MGMT_MSG_VERSION_NATIVE 1
+/* The absolute maximum message size (16MB) */
+#define MGMT_MSG_MAX_MSG_ALLOC_LEN (16 * 1024 * 1024)
struct mgmt_msg_state {
struct stream *ins;