summaryrefslogtreecommitdiff
path: root/libbcachefs/printbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbcachefs/printbuf.c')
-rw-r--r--libbcachefs/printbuf.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libbcachefs/printbuf.c b/libbcachefs/printbuf.c
index 8b036918..9f529e4c 100644
--- a/libbcachefs/printbuf.c
+++ b/libbcachefs/printbuf.c
@@ -45,6 +45,13 @@ int bch2_printbuf_make_room(struct printbuf *out, unsigned extra)
unsigned new_size = roundup_pow_of_two(out->size + extra);
+ /* Sanity check... */
+ if (new_size > PAGE_SIZE << MAX_PAGE_ORDER) {
+ out->allocation_failure = true;
+ out->overflow = true;
+ return -ENOMEM;
+ }
+
/*
* Note: output buffer must be freeable with kfree(), it's not required
* that the user use printbuf_exit().