From 6148934dd7ad4c7cc872c4fd65484af0520df7d4 Mon Sep 17 00:00:00 2001 From: Jack Zeal Date: Sat, 28 Mar 2026 18:49:42 -0700 Subject: [PATCH] Protection around allocating malformed border buffers --- src/common/borderset.c | 15 +++++++++++++++ src/ssd/ssd-border.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/borderset.c b/src/common/borderset.c index 0c02b6c1..f889ae33 100644 --- a/src/common/borderset.c +++ b/src/common/borderset.c @@ -4,9 +4,24 @@ #include "common/macros.h" #include "buffer.h" + struct borderset * getBorders(uint32_t id, int size, enum border_type type, int bevelSize) { struct borderset * current = borderCache; struct borderset * last; + + // Preventing building nonsense borders: + // If you try for a double bevel but it's so deep they would overlap, convert to a single bevel + if (type == BORDER_DOUBLE && (bevelSize > size/2)) { + type = BORDER_SINGLE; + } + + // Anything with a size of 0 is converted to a 1-pixel flat border so as to prevent empty allocations + + if (size < 1) { + type = BORDER_FLAT; + size = 1; + } + while (current != NULL) { if (current->size == size && current->id == id && current->type == type) { return current; diff --git a/src/ssd/ssd-border.c b/src/ssd/ssd-border.c index 91f54093..4bfd40b5 100644 --- a/src/ssd/ssd-border.c +++ b/src/ssd/ssd-border.c @@ -54,7 +54,7 @@ ssd_border_create(struct ssd *ssd) - int bevelSize = theme->border_bevel_width; // TODO: configurable + int bevelSize = theme->border_bevel_width; /* From Pull request 3382 */ float r = color[0];