Fix out of bounds read and write in IO.select

Added error handling for file descriptors larger than FD_SETSIZE in mrb_hal_io_fdset_set and mrb_hal_io_fdset_isset functions, for posix hal.

I actually don't know how to fix this on windows, or if it needs fixing.
This commit is contained in:
Hendrik
2026-01-25 15:42:17 +01:00
committed by GitHub
parent c25b562256
commit 44831711fc
+8
View File
@@ -519,6 +519,10 @@ void
mrb_hal_io_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
{
(void)mrb;
if (fd >= FD_SETSIZE) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "fd is larger than FD_SETSIZE");
return;
}
if (fdset) {
FD_SET(fd, &fdset->fds);
}
@@ -528,6 +532,10 @@ int
mrb_hal_io_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
{
(void)mrb;
if (fd >= FD_SETSIZE) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "fd is larger than FD_SETSIZE");
return 0;
}
if (fdset) {
return FD_ISSET(fd, &fdset->fds);
}