Skip to content

Commit c507727

Browse files
committed
Fix use-after-free with block hotspots
1 parent 0cbd2a4 commit c507727

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

common/pango.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@
66
#include <stdio.h>
77
#include <stdlib.h>
88
#include <string.h>
9+
#include "log.h"
910

1011
PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
1112
const char *text, int32_t scale, bool markup) {
1213
PangoLayout *layout = pango_cairo_create_layout(cairo);
1314
PangoAttrList *attrs;
1415
if (markup) {
1516
char *buf;
16-
pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, NULL);
17+
GError *error = NULL;
18+
if (!sway_assert(pango_parse_markup(
19+
text, -1, 0, &attrs, &buf, NULL, &error),
20+
"pango_parse_markup '%s' -> error %s", text,
21+
error ? error->message : NULL)) {
22+
return NULL;
23+
}
1724
pango_layout_set_markup(layout, buf, -1);
1825
free(buf);
1926
} else {

sway/tree/layout.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ void arrange_windows(struct sway_container *container,
248248
struct wlr_box *area = &output->sway_output->usable_area;
249249
wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
250250
area->width, area->height, area->x, area->y);
251-
container->width = area->width;
252-
container->height = area->height;
251+
container->width = width = area->width;
252+
container->height = height = area->height;
253253
container->x = x = area->x;
254254
container->y = y = area->y;
255255
wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f",

swaybar/i3bar.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ static bool i3bar_parse_json(struct status_line *status, const char *text) {
3030
status_error(status, "[failed to parse i3bar json]");
3131
return false;
3232
}
33-
if (json_object_array_length(results) < 1) {
34-
return true;
35-
}
33+
wlr_log(L_DEBUG, "Got i3bar json: '%s'", text);
3634
for (size_t i = 0; i < json_object_array_length(results); ++i) {
3735
json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
3836
json_object *name, *instance, *separator, *separator_block_width;

swaybar/render.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static uint32_t render_status_block(cairo_t *cairo,
153153
hotspot->width = width;
154154
hotspot->height = height;
155155
hotspot->callback = block_hotspot_callback;
156-
hotspot->destroy = free;
156+
hotspot->destroy = NULL;
157157
hotspot->data = block;
158158
wl_list_insert(&output->hotspots, &hotspot->link);
159159

@@ -227,9 +227,9 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo,
227227
struct swaybar_config *config, struct swaybar_output *output,
228228
struct status_line *status, bool focused,
229229
double *x, uint32_t width, uint32_t height) {
230-
struct i3bar_block *block;
231230
uint32_t max_height = 0;
232231
bool edge = true;
232+
struct i3bar_block *block;
233233
wl_list_for_each_reverse(block, &status->blocks, link) {
234234
uint32_t h = render_status_block(cairo, config, output,
235235
block, x, height, focused, edge);
@@ -376,6 +376,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
376376
static uint32_t render_to_cairo(cairo_t *cairo,
377377
struct swaybar *bar, struct swaybar_output *output) {
378378
struct swaybar_config *config = bar->config;
379+
wlr_log(L_DEBUG, "output %p", output);
379380

380381
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
381382
if (output->focused) {

0 commit comments

Comments
 (0)