Skip to content

Commit 877640c

Browse files
committed
compose: Reject unsupported state flags
1 parent f17047f commit 877640c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Fixed some functions accepting unsupported flags:
22
- `xkb_context_new()`
33
- `xkb_rmlvo_builder_new()`
4+
- `xkb_compose_state_new()`

src/compose/state.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <assert.h>
99

10+
#include "context.h"
1011
#include "table.h"
1112
#include "utils.h"
1213
#include "keysym.h"
@@ -33,9 +34,17 @@ struct xkb_compose_state *
3334
xkb_compose_state_new(struct xkb_compose_table *table,
3435
enum xkb_compose_state_flags flags)
3536
{
36-
struct xkb_compose_state *state;
37+
static const enum xkb_compose_state_flags XKB_COMPOSE_STATE_FLAGS =
38+
XKB_COMPOSE_STATE_NO_FLAGS;
3739

38-
state = calloc(1, sizeof(*state));
40+
if (flags & ~XKB_COMPOSE_STATE_FLAGS) {
41+
log_err_func(table->ctx, XKB_LOG_MESSAGE_NO_ID,
42+
"Unsupported compose state flags: %#x\n",
43+
(flags & ~XKB_COMPOSE_STATE_FLAGS));
44+
return NULL;
45+
}
46+
47+
struct xkb_compose_state * const state = calloc(1, sizeof(*state));
3948
if (!state)
4049
return NULL;
4150

test/compose.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ test_state(struct xkb_context *ctx)
487487
assert(table);
488488
fclose(file);
489489

490+
/* Reject unsupported flags */
491+
assert(!xkb_compose_state_new(table, -1));
492+
assert(!xkb_compose_state_new(table, 0xffff));
493+
490494
state = xkb_compose_state_new(table, XKB_COMPOSE_STATE_NO_FLAGS);
491495
assert(state);
492496

0 commit comments

Comments
 (0)