From ae11ee5b8f55f3f8d9c50357ec3c2d6cbe2c3801 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 16 Jan 2025 13:28:54 +0900 Subject: [PATCH 1/2] net/usrsock/usrsock_sendmsg.c: avoid using variable length array use heap allocation instead. variable length array is a C99 feature, which should not be used in the common code. besides that, stack consumption with the unchecked user-given size a bad idea in general. --- net/usrsock/usrsock_sendmsg.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/net/usrsock/usrsock_sendmsg.c b/net/usrsock/usrsock_sendmsg.c index 048791193327f..ab844a722d952 100644 --- a/net/usrsock/usrsock_sendmsg.c +++ b/net/usrsock/usrsock_sendmsg.c @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -142,9 +143,18 @@ static int do_sendto_request(FAR struct usrsock_conn_s *conn, { }; - struct iovec bufs[2 + msg->msg_iovlen]; + struct iovec *bufs; + size_t iovlen; + int ret; int i; + iovlen = 2 + msg->msg_iovlen; + bufs = kmm_malloc(sizeof(*bufs) * iovlen); + if (bufs == NULL) + { + return -ENOMEM; + } + if (msg->msg_namelen > UINT16_MAX) { msg->msg_namelen = UINT16_MAX; @@ -174,7 +184,9 @@ static int do_sendto_request(FAR struct usrsock_conn_s *conn, memcpy(&bufs[2], msg->msg_iov, sizeof(struct iovec) * msg->msg_iovlen); - return usrsock_do_request(conn, bufs, nitems(bufs)); + ret = usrsock_do_request(conn, bufs, iovlen); + kmm_free(bufs); + return ret; } /**************************************************************************** From 9c8b68ccce3da89d93f0492217ebd1d1e634271c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 16 Jan 2025 13:33:42 +0900 Subject: [PATCH 2/2] sim: add -Wvla --- arch/sim/src/cmake/Toolchain.cmake | 1 + boards/sim/sim/sim/scripts/Make.defs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/sim/src/cmake/Toolchain.cmake b/arch/sim/src/cmake/Toolchain.cmake index c4c0cff080a91..118b62bbc537b 100644 --- a/arch/sim/src/cmake/Toolchain.cmake +++ b/arch/sim/src/cmake/Toolchain.cmake @@ -148,6 +148,7 @@ if(NOT WIN32) -ffunction-sections -fdata-sections -Wall + -Wvla -Wshadow -Wundef -Wno-attributes diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index c56772dc04309..4b392c00171da 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -127,8 +127,8 @@ ARCHCXXFLAGS += -fvisibility=hidden ARCHCFLAGS += -ffunction-sections -fdata-sections ARCHCXXFLAGS += -ffunction-sections -fdata-sections -ARCHCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas -ARCHCXXFLAGS += -Wall -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas +ARCHCFLAGS += -Wall -Wvla -Wstrict-prototypes -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas +ARCHCXXFLAGS += -Wall -Wvla -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas ifneq ($(CONFIG_LIBCXXTOOLCHAIN),y) ARCHCXXFLAGS += -nostdinc++