From 9353aa14fe8a2c9ba9fe77d9680cd67765148698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 5 Jun 2022 00:33:30 +0200 Subject: [PATCH] =?UTF-8?q?bar:=20set=20clip=20region=20before=20calling?= =?UTF-8?q?=20the=20particles=E2=80=99=20expose()=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures particles that are “too wide” doesn’t try to render outside the bar, possibly overrunning both margins and borders. Or worse, crashes yambar. Closes #198 --- CHANGELOG.md | 3 +++ bar/bar.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b27504a..88880fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,11 +93,14 @@ * examples/dwl-tags: updated parsing of `output` name ([#178][178]). * sway-xkb: don’t crash when Sway sends an _”added”_ event for a device yambar is already tracking ([#177][177]). +* Crash when a particle is “too wide”, and tries to render outside the + bar ([#198][198]). [169]: https://codeberg.org/dnkl/yambar/issues/169 [172]: https://codeberg.org/dnkl/yambar/issues/172 [178]: https://codeberg.org/dnkl/yambar/issues/178 [177]: https://codeberg.org/dnkl/yambar/issues/177 +[198]: https://codeberg.org/dnkl/yambar/issues/198 ### Security diff --git a/bar/bar.c b/bar/bar.c index 4f1895f..ab9a587 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -134,6 +134,18 @@ expose(const struct bar *_bar) int y = bar->border.top_width; int x = bar->border.left_width + bar->left_margin - bar->left_spacing; + pixman_region32_t clip; + pixman_region32_init_rect( + &clip, + bar->border.left_width + bar->left_margin, + bar->border.top_width, + (bar->width - + bar->left_margin - bar->right_margin - + bar->border.left_width - bar->border.right_width), + bar->height); + pixman_image_set_clip_region32(pix, &clip); + pixman_region32_fini(&clip); + for (size_t i = 0; i < bar->left.count; i++) { const struct exposable *e = bar->left.exps[i]; e->expose(e, pix, x + bar->left_spacing, y, bar->height);