diff --git a/third_party/musl/ndk_musl_include/sys/select.h b/third_party/musl/ndk_musl_include/sys/select.h index d933d308c4c7d947b56f6e996b5c90f725c2e306..8c93b038013e9f8110ed3b80bc074fa3968ab925 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 e72f5997b314cbd349fc88db3fc6674abab0d258..863e3255aff53169cfa31381e56dcb4be4d6b22e 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" + } ]