1 Star 0 Fork 32

compile_success/gazelle_3

forked from src-openEuler/gazelle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0151-select-timeout-arguments-check.patch 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
From fbd169eb504f5edc905f07f33785ba3df5812b4c Mon Sep 17 00:00:00 2001
From: li_yunqing <liyunqing@kylinos.cn>
Date: Thu, 14 Mar 2024 16:37:27 +0800
Subject: [PATCH] select timeout arguments check
---
src/lstack/api/lstack_epoll.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c
index 7dbef9d..c9d1f0c 100644
--- a/src/lstack/api/lstack_epoll.c
+++ b/src/lstack/api/lstack_epoll.c
@@ -927,13 +927,17 @@ static void fds_poll2select(struct pollfd *fds, nfds_t nfds, fd_set *readfds, fd
}
}
-static inline int timeval_to_ms(struct timeval *timeval)
+static inline int timeval_to_ms(struct timeval *timeval, int32_t *timeout)
{
- if (timeval == NULL) {
+ if (!timeval) {
+ *timeout = -1;
+ return 0;
+ }
+ if (unlikely((timeval->tv_sec < 0 || timeval->tv_usec < 0 || timeval->tv_usec >= 1000000))) {
return -1;
}
-
- return (timeval->tv_sec * 1000 + timeval->tv_usec / 1000);
+ *timeout = timeval->tv_sec * 1000 + timeval->tv_usec / 1000;
+ return 0;
}
static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct pollfd *fds)
@@ -969,7 +973,11 @@ int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfd
/* Convert the select parameter to the poll parameter. */
struct pollfd fds[FD_SETSIZE] = { 0 };
nfds_t nfds = fds_select2poll(maxfd, readfds, writefds, exceptfds, fds);
- int timeout = timeval_to_ms(timeval);
+ int timeout = 0;
+ if (timeval_to_ms(timeval, &timeout)) {
+ LSTACK_LOG(ERR, LSTACK, "select input param timeout error.\n");
+ GAZELLE_RETURN(EINVAL);
+ }
int event_num = lstack_poll(fds, nfds, timeout);
--
2.33.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/compile_success/gazelle_3.git
git@gitee.com:compile_success/gazelle_3.git
compile_success
gazelle_3
gazelle_3
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385