From 8577d5aea360f9925c1dda77b11f49967b601525 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 27 Jun 2020 23:32:45 -0400 Subject: [PATCH] Buflib_init Bugfix Minsize when buflib_init is called with a buffer smaller than sizeof(union buflib_data); size will be zero Later when the alloc fails buflib will keep try to free items in order to satisify the request this crashes in the sim I suspect this behavior holds true on device as well but I havent verified this as of yet. patch adds minimal overhead to the buflib and panics when the size is too small Change-Id: I46e510367fc1cac19ce01ee6f92d8cf0d65ef914 --- firmware/buflib.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/firmware/buflib.c b/firmware/buflib.c index f909ab8333..0e90e7fe72 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c @@ -123,6 +123,12 @@ buflib_init(struct buflib_context *ctx, void *buf, size_t size) */ ctx->alloc_end = bd_buf; ctx->compact = true; + + if (size == 0) + { + BPANICF("buflib_init error (CTX:%p, %zd bytes):\n", ctx, + (ctx->handle_table - ctx->buf_start) * sizeof(union buflib_data)); + } } bool buflib_context_relocate(struct buflib_context *ctx, void *buf)