* [sleepy.penguin] [PATCH] epoll: enforce maxevents > 0 before memory allocation
@ 2013-04-21 3:51 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2013-04-21 3:51 UTC (permalink / raw)
To: sleepy.penguin
This prevents overflow and excessive memory usage/OOM error.
Note: the kernel enforces this and returns EINVAL anyways,
we just do it to prevent OOM here.
---
ext/sleepy_penguin/epoll.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c
index 8e49171..a6f86f8 100644
--- a/ext/sleepy_penguin/epoll.c
+++ b/ext/sleepy_penguin/epoll.c
@@ -65,6 +65,12 @@ static struct ep_per_thread *ept_get(VALUE self, int maxevents)
int err;
void *ptr;
+ /* error check here to prevent OOM from posix_memalign */
+ if (maxevents <= 0) {
+ errno = EINVAL;
+ rb_sys_fail("epoll_wait maxevents <= 0");
+ }
+
if (ept && ept->capa >= maxevents)
goto out;
--
Eric Wong
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-04-21 3:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-21 3:51 [sleepy.penguin] [PATCH] epoll: enforce maxevents > 0 before memory allocation Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/sleepy_penguin.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).