]> git.meshlink.io Git - meshlink/commitdiff
Limit the size of the fd read buffer in channel_poll().
authorGuus Sliepen <guus@meshlink.io>
Wed, 20 May 2020 22:13:50 +0000 (00:13 +0200)
committerGuus Sliepen <guus@meshlink.io>
Thu, 21 May 2020 12:32:57 +0000 (14:32 +0200)
src/meshlink.c

index 14ff7155888c96a04ff33945dfd71dcf9e4481dd..e50be188b32ef9b19b96c2961766da4ef2d60bc4 100644 (file)
@@ -3675,6 +3675,11 @@ static void channel_poll(struct utcp_connection *connection, size_t len) {
                if(aio->data) {
                        sent = utcp_send(connection, (char *)aio->data + aio->done, todo);
                } else {
+                       /* Limit the amount we read at once to avoid stack overflows */
+                       if(todo > 65536) {
+                               todo = 65536;
+                       }
+
                        char buf[todo];
                        ssize_t result = read(aio->fd, buf, todo);