Skip to content

Commit

Permalink
Fix crash when reloading config with invalid criteria
Browse files Browse the repository at this point in the history
Came up in #6141
  • Loading branch information
orestisfl committed Jul 8, 2024
1 parent be840af commit 88ab8f3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions release-notes/bugfixes/5-reload-match-criteria
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
fix crash when reloading config with invalid criteria
16 changes: 16 additions & 0 deletions src/config_directives.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 231,10 @@ CFGFUN(exec, const char *exectype, const char *no_startup_id, const char *comman
}

CFGFUN(for_window, const char *command) {
if (current_match->error != NULL) {
ELOG("match has error: %s\n", current_match->error);
return;
}
if (match_is_empty(current_match)) {
ELOG("Match is empty, ignoring this for_window statement\n");
return;
Expand Down Expand Up @@ -631,6 635,10 @@ CFGFUN(color, const char *colorclass, const char *border, const char *background
}

CFGFUN(assign_output, const char *output) {
if (current_match->error != NULL) {
ELOG("match has error: %s\n", current_match->error);
return;
}
if (match_is_empty(current_match)) {
ELOG("Match is empty, ignoring this assignment\n");
return;
Expand All @@ -650,6 658,10 @@ CFGFUN(assign_output, const char *output) {
}

CFGFUN(assign, const char *workspace, bool is_number) {
if (current_match->error != NULL) {
ELOG("match has error: %s\n", current_match->error);
return;
}
if (match_is_empty(current_match)) {
ELOG("Match is empty, ignoring this assignment\n");
return;
Expand All @@ -674,6 686,10 @@ CFGFUN(assign, const char *workspace, bool is_number) {
}

CFGFUN(no_focus) {
if (current_match->error != NULL) {
ELOG("match has error: %s\n", current_match->error);
return;
}
if (match_is_empty(current_match)) {
ELOG("Match is empty, ignoring this assignment\n");
return;
Expand Down
34 changes: 34 additions & 0 deletions testcases/t/322-match-error-crash.t
Original file line number Diff line number Diff line change
@@ -0,0 1,34 @@
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
# (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
# (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
# (or docs/ipc)
#
# • https://i3wm.org/downloads/modern_perl_a4.pdf
# (unless you are already familiar with Perl)
#
# Verify i3 does not crash when reloading configuration with invalid match
# criteria.
# Ticket: #6141
# Bug still in: 4.23-47-gbe840af4
use i3test i3_config => <<EOT;
# i3 config file (v4)
assign [class="class" window_type="some_type"] workspace 1
assign [class="class" window_type="some_type"] output 1
for_window [class="class" window_type="some_type"] workspace 1
no_focus [class="class" window_type="some_type"] workspace 1
EOT

does_i3_live;

cmd 'reload';
does_i3_live;

done_testing;

0 comments on commit 88ab8f3

Please sign in to comment.