From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: normalperson@yhbt.net Received: from zedshaw2.xen.prgmr.com (zedshaw2.xen.prgmr.com [71.19.156.177]) by dcvr.yhbt.net (Postfix) with ESMTP id 5AAFF1F5B5 for ; Sun, 21 Apr 2013 03:51:43 +0000 (UTC) Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 30A2473DCB for ; Sun, 21 Apr 2013 03:52:59 +0000 (UTC) MIME-Version: 1.0 Date: Sun, 21 Apr 2013 03:51:23 +0000 From: Eric Wong In-Reply-To: <20130421035123.GA27772@dcvr.yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Message-Id: <20130421035123.GA27772@dcvr.yhbt.net> Precedence: list References: <20130421035123.GA27772@dcvr.yhbt.net> Sender: sleepy.penguin@librelist.org Subject: [sleepy.penguin] [PATCH] epoll: enforce maxevents > 0 before memory allocation To: sleepy.penguin@librelist.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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