From 65f54a7d6aa5b1117196326717fa9fd3dbbdcfa2 Mon Sep 17 00:00:00 2001 From: haotuo Date: Tue, 12 Mar 2024 10:41:32 +0800 Subject: [PATCH] Add select fd check Signed-off-by: haotuo Change-Id: Ib8386adb8266391d276337fc181f2882a7de0dfb --- third_party/musl/ndk_musl_include/sys/select.h | 15 ++++++++++++--- third_party/musl/ndk_script/adapter/libc.ndk.json | 6 +++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/third_party/musl/ndk_musl_include/sys/select.h b/third_party/musl/ndk_musl_include/sys/select.h index d933d308c4c..8c93b038013 100644 --- a/third_party/musl/ndk_musl_include/sys/select.h +++ b/third_party/musl/ndk_musl_include/sys/select.h @@ -23,10 +23,19 @@ typedef struct { unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; } fd_set; +/** +* @brief Check if fd passed to fd_set is valid (<1024). +* +* This method will check fd(0 <= fd < 1024) is valid for select, abort if not. +* +* @param fd: Specified fd. +*/ +void __fd_chk(int fd); + #define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0) -#define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) -#define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) -#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) +#define FD_SET(d, s) do { __fd_chk(d); ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))); } while(0) +#define FD_CLR(d, s) do { __fd_chk(d); ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))); } while(0) +#define FD_ISSET(d, s) (d >= 0) && (d < 1024) && !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); diff --git a/third_party/musl/ndk_script/adapter/libc.ndk.json b/third_party/musl/ndk_script/adapter/libc.ndk.json index e72f5997b31..863e3255aff 100644 --- a/third_party/musl/ndk_script/adapter/libc.ndk.json +++ b/third_party/musl/ndk_script/adapter/libc.ndk.json @@ -1570,5 +1570,9 @@ { "name": "__recv_chk"}, { "name": "__recvfrom_chk"}, { "name": "__open_chk"}, - { "name": "__strlcat_chk"} + { "name": "__strlcat_chk"}, + { + "first_introduced": "12", + "name":"__fd_chk" + } ] -- Gitee