From 844ce972fed056e1c4e0517e43b814c62d68edce Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 5 Feb 2018 10:23:35 -0800 Subject: fixes #228 aio iov should have larger limits (dynamically allocated) --- src/nng.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/nng.c') diff --git a/src/nng.c b/src/nng.c index 92d19d87..6f710993 100644 --- a/src/nng.c +++ b/src/nng.c @@ -1086,8 +1086,22 @@ nng_aio_set_timeout(nng_aio *aio, nni_duration when) } int -nng_aio_set_iov(nng_aio *aio, int niov, nng_iov *iov) -{ +nng_aio_set_iov(nng_aio *aio, unsigned niov, const nng_iov *iov) +{ +// We limit the niov to prevent user insanity. This is required +// to avoid stack allocations that might smash the stack. The +// assumption is that we can always put at least 1kB on the stack -- +// our nng_iov structures are 16B. Systems without stack allocation +// get a smaller limit, because we use an automatic variable. +#if defined(NNG_HAVE_ALLOCA) || defined(_WIN32) + if (niov > 64) { + return (NNG_EINVAL); + } +#else + if (niov > 16) { + return (NNG_EINVAL); + } +#endif return (nni_aio_set_iov(aio, niov, iov)); } -- cgit v1.2.3-70-g09d2