#define _cleanup_bus_unref_ __attribute__((cleanup(bus_unrefp)))
#define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
+
+#define BUS_WQUEUE_MAX 128
+#define BUS_RQUEUE_MAX 128
+
+#define BUS_MESSAGE_SIZE_MAX (64*1024*1024)
+#define BUS_AUTH_SIZE_MAX (64*1024)
#include "bus-message.h"
#include "bus-type.h"
-#define WQUEUE_MAX 128
-
static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec);
static void bus_free(sd_bus *b) {
return r;
n = MAX(3 + 32 + 2 + sizeof("AGREE_UNIX_FD") - 1 + 2, b->rbuffer_size * 2);
+
+ if (n > BUS_AUTH_SIZE_MAX)
+ n = BUS_AUTH_SIZE_MAX;
+
+ if (b->rbuffer_size >= n)
+ return -ENOBUFS;
+
p = realloc(b->rbuffer, n);
if (!p)
return -ENOMEM;
static int message_read_need(sd_bus *bus, size_t *need) {
uint32_t a, b;
uint8_t e;
+ uint64_t sum;
assert(bus);
assert(need);
} else
return -EBADMSG;
- *need = sizeof(struct bus_header) + ALIGN_TO(b, 8) + a;
+ sum = (uint64_t) sizeof(struct bus_header) + (uint64_t) ALIGN_TO(b, 8) + (uint64_t) a;
+ if (sum >= BUS_MESSAGE_SIZE_MAX)
+ return -ENOBUFS;
+
+ *need = (size_t) sum;
return 0;
}
/* Just append it to the queue. */
- if (bus->wqueue_size >= WQUEUE_MAX)
+ if (bus->wqueue_size >= BUS_WQUEUE_MAX)
return -ENOBUFS;
q = realloc(bus->wqueue, sizeof(sd_bus_message*) * (bus->wqueue_size + 1));
if (!room) {
sd_bus_message **q;
+ if (bus->rqueue_size >= BUS_RQUEUE_MAX)
+ return -ENOBUFS;
+
/* Make sure there's room for queuing this
* locally, before we read the message */
* - add object handlers
* - add peer message handlers
* - verify object paths
- * - when reading a message, verify its size
- * - add limits to wqueue and rqueue alike
*/
typedef struct sd_bus sd_bus;