OSDN Git Service

epoll_create: reject size <= 0
authorGreg Hackmann <ghackmann@google.com>
Thu, 24 Mar 2016 20:41:17 +0000 (13:41 -0700)
committerGreg Hackmann <ghackmann@google.com>
Thu, 24 Mar 2016 23:37:20 +0000 (16:37 -0700)
Even though the size parameter to epoll_create(2) is (otherwise) unused,
passing in size <= 0 is explicitly documented as an error.

This change fixes the LTP epoll01 testcase.

Change-Id: I044a38be823c2fa956b57e77cc66571dfae8a4bb
Signed-off-by: Greg Hackmann <ghackmann@google.com>
libc/bionic/epoll_create.cpp
tests/sys_epoll_test.cpp

index 1dfafa8..74f664f 100644 (file)
  * SUCH DAMAGE.
  */
 
+#include <errno.h>
 #include <sys/epoll.h>
 
-int epoll_create(int /*obsolete_size*/) {
+int epoll_create(int size) {
+  if (size <= 0) {
+    errno = EINVAL;
+    return -1;
+  }
   return epoll_create1(0);
 }
index 6e7a807..f6be4af 100644 (file)
@@ -40,6 +40,12 @@ TEST(sys_epoll, smoke) {
   ASSERT_EQ(0, epoll_pwait(epoll_fd, events, 1, 1, &ss));
 }
 
+TEST(sys_epoll, epoll_create_invalid_size) {
+  errno = 0;
+  ASSERT_EQ(-1, epoll_create(0));
+  ASSERT_EQ(EINVAL, errno);
+}
+
 TEST(sys_epoll, epoll_event_data) {
   int epoll_fd = epoll_create(1);
   ASSERT_NE(-1, epoll_fd) << strerror(errno);