Skip to content

Commit 7be67e9

Browse files
committed
registry: Reject unsupported flags
1 parent 5ce9d13 commit 7be67e9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/registry.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ log_level(const char *level) {
492492
return RXKB_LOG_LEVEL_ERROR;
493493
}
494494

495+
enum {
496+
RXKB_CONTEXT_FLAGS = RXKB_CONTEXT_NO_DEFAULT_INCLUDES
497+
| RXKB_CONTEXT_LOAD_EXOTIC_RULES
498+
| RXKB_CONTEXT_NO_SECURE_GETENV
499+
};
500+
495501
struct rxkb_context *
496502
rxkb_context_new(enum rxkb_context_flags flags)
497503
{
@@ -512,6 +518,14 @@ rxkb_context_new(enum rxkb_context_flags flags)
512518
if (env)
513519
rxkb_context_set_log_level(ctx, log_level(env));
514520

521+
if (flags & ~(enum rxkb_context_flags) RXKB_CONTEXT_FLAGS) {
522+
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
523+
"%s: Invalid context flags: 0x%x\n", __func__,
524+
(flags & ~(enum rxkb_context_flags) RXKB_CONTEXT_FLAGS));
525+
free(ctx);
526+
return NULL;
527+
}
528+
515529
list_init(&ctx->models);
516530
list_init(&ctx->layouts);
517531
list_init(&ctx->option_groups);

test/registry.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,10 @@ main(void)
11261126
{
11271127
test_init();
11281128

1129+
/* Reject unsupported flags */
1130+
assert(!rxkb_context_new(-1));
1131+
assert(!rxkb_context_new(0xffff));
1132+
11291133
test_xml_error_handler();
11301134
test_no_include_paths();
11311135
test_invalid_include();

0 commit comments

Comments
 (0)