From 7e0ae1698d4db0baec858a46de8d1ae875360cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 7 Oct 2019 16:56:08 +0900 Subject: avoid overflow in integer multiplication This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes. --- thread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 901667e1b3..ea0956eabd 100644 --- a/thread.c +++ b/thread.c @@ -3867,7 +3867,9 @@ rb_fd_set(int fd, rb_fdset_t *set) } if (set->fdset->fd_count >= (unsigned)set->capa) { set->capa = (set->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE; - set->fdset = xrealloc(set->fdset, sizeof(unsigned int) + sizeof(SOCKET) * set->capa); + set->fdset = + rb_xrealloc_mul_add( + set->fdset, set->capa, sizeof(SOCKET), sizeof(unsigned int)); } set->fdset->fd_array[set->fdset->fd_count++] = s; } -- cgit v1.2.3