aboutsummaryrefslogtreecommitdiff
path: root/src/nng.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nng.c')
-rw-r--r--src/nng.c18
1 files changed, 16 insertions, 2 deletions
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));
}