From 475c23875e459525bad449b328e4a455e60a9178 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 28 Oct 2022 17:49:59 +0100 Subject: [PATCH] Unix: stop accessing ctrl->fileselect for font selectors. The setup code for CTRL_FILESELECT and CTRL_FONTSELECT is shared, which means it's a mistake to test ctrl->fileselect.just_button in it without first checking which control type we're actually dealing with. UBsan picks this up by complaining that the just_button field contains some byte value that's illegal for a boolean. I think it's also the cause of an intermittent assertion failure reported recently, in which dlg_fontsel_set finds that uc->entry is NULL when it never ought to be. If the byte from the wrong union branch happened to be 0 by sheer bad luck, that could give rise to exactly that failure. --- unix/dialog.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unix/dialog.c b/unix/dialog.c index 7e9051be..5846466a 100644 --- a/unix/dialog.c +++ b/unix/dialog.c @@ -2143,7 +2143,10 @@ GtkWidget *layout_ctrls( case CTRL_FONTSELECT: { GtkWidget *ww; - if (!ctrl->fileselect.just_button) { + bool just_button = (ctrl->type == CTRL_FILESELECT && + ctrl->fileselect.just_button); + + if (!just_button) { const char *browsebtn = (ctrl->type == CTRL_FILESELECT ? "Browse..." : "Change...");