From aafe2dd2d14e1ce88b5c9c819277ca0bc98af6e5 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Tue, 18 Jan 2022 18:20:53 +0000 Subject: [PATCH] tagcache: don't allow temp commit buffer to be moved The temporary buffer used during database commit did not have any buflib callbacks set, which allows it to be moved by buflib at any time. The code is not prepared to deal with this, so things break horribly if anything tries to allocate during the commit. The solution is to pass dummy callbacks to prevent the buffer from being moved. I expect this may create other issues since the commit uses up all available RAM, but at least things won't get silently corrupted anymore. Change-Id: I3183aaee58c94bfbaf4e24424030b8be6e341d22 --- apps/tagcache.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/tagcache.c b/apps/tagcache.c index bf23ac74dc..37f443e036 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -326,7 +326,10 @@ static void allocate_tempbuf(void) if (tempbuf) tempbuf_size = size; #else /* !__PCTOOL__ */ - tempbuf_handle = core_alloc_maximum("tc tempbuf", &size, NULL); + /* Need to pass dummy ops to prevent the buffer being moved + * out from under us, since we yield during the tagcache commit. */ + static struct buflib_callbacks dummy_ops; + tempbuf_handle = core_alloc_maximum("tc tempbuf", &size, &dummy_ops); if (tempbuf_handle > 0) { tempbuf = core_get_data(tempbuf_handle);