Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on invalid regular expressions in misc:swallow_regex #2065

Closed
jbeich opened this issue Apr 15, 2023 · 1 comment
Closed

Crash on invalid regular expressions in misc:swallow_regex #2065

jbeich opened this issue Apr 15, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jbeich
Copy link
Contributor

jbeich commented Apr 15, 2023

libc++ doesn't like [[EMPTY]] but otherwise both libc++ and libstdc++ will raise an exception (thus crash Hyprland) with something unambigously invalid.

$ Hyprland -c /tmp/hyprland.conf
[...]
terminate called after throwing an instance of 'std::regex_error'
  what():  Mismatched '(' and ')' in regular expression
Abort trap

(gdb) bt
#0  0x000000080125633a in thr_kill () at /lib/libc.so.7
#1  0x00000008011cec74 in raise () at /lib/libc.so.7
#2  0x0000000801280109 in abort () at /lib/libc.so.7
#3  0x000000000068b1f8 in __gnu_cxx::__verbose_terminate_handler() [clone .cold] ()
#4  0x0000000000900c56 in __cxxabiv1::__terminate(void (*)()) ()
#5  0x0000000000900cb1 in  ()
#6  0x0000000000900e1c in  ()
#7  0x000000000068cab0 in std::__throw_regex_error(std::regex_constants::error_type) ()
#8  0x00000000007422fc in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_Compiler(char const*, char const*, std::locale const&, std::regex_constants::syntax_option_type) ()
#9  0x00000000007415c7 in std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >::_M_compile(char const*, char const*, std::regex_constants::syntax_option_type) ()
#10 0x0000000000740c95 in std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >::basic_regex<std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::regex_constants::syntax_option_type) ()
#11 0x0000000000739d06 in Events::listener_mapWindow(void*, void*) ()
#12 0x00000000006ef2f1 in void std::__invoke_impl<void, void (*&)(void*, void*), void*, void*>(std::__invoke_other, void (*&)(void*, void*), void*&&, void*&&) ()
#13 0x00000000006ee037 in std::enable_if<is_invocable_r_v<void, void (*&)(void*, void*), void*, void*>, void>::type std::__invoke_r<void, void (*&)(void*, void*), void*, void*>(void (*&)(void*, void*), void*&&, void*&&) ()
#14 0x00000000006eceb5 in std::_Function_handler<void (void*, void*), void (*)(void*, void*)>::_M_invoke(std::_Any_data const&, void*&&, void*&&) ()
#15 0x000000000084b57f in std::function<void (void*, void*)>::operator()(void*, void*) const ()
#16 0x000000000084b385 in CHyprWLListener::emit(void*) ()
#17 0x000000000084afac in handleWrapped(wl_listener*, void*) ()
#18 0x0000000800bce4e4 in wl_signal_emit_mutable (signal=0x8026af7e0, data=0x0) at ../src/wayland-server.c:2241
#19 0x00000000008ac8f5 in xdg_surface_role_commit ()
#20 0x00000000008b0f90 in surface_commit_state ()
#21 0x00000000008b1060 in surface_handle_commit ()
#22 0x000000080154507a in ffi_call_unix64 () at ../src/x86/unix64.S:104
#23 0x000000080154486c in ffi_call_int
    (cif=0x7fffffffe2b0, fn=0x8b0fcf <surface_handle_commit>, rvalue=0x0, avalue=0x7fffffffe380, closure=0x0) at ../src/x86/ffi64.c:673
#24 0x0000000801544a0c in ffi_call (cif=0x7fffffffe2b0, fn=0x8b0fcf <surface_handle_commit>, rvalue=0x0, avalue=0x7fffffffe380)
    at ../src/x86/ffi64.c:710
#25 0x0000000800bd38f3 in wl_closure_invoke (closure=0x81071f7a0, flags=2, target=0x80dc74800, opcode=6, data=0x81071f420)
    at ../src/connection.c:1025
#26 0x0000000800bcbd43 in wl_client_connection_data (fd=33, mask=1, data=0x81071f420) at ../src/wayland-server.c:438
#27 0x0000000800bcf9ef in wl_event_source_fd_dispatch (source=0x80dc67a00, ep=0x7fffffffe530) at ../src/event-loop.c:112
#28 0x0000000800bd110a in wl_event_loop_dispatch (loop=0x8026393c0, timeout=-1) at ../src/event-loop.c:1027
#29 0x0000000800bcd515 in wl_display_run (display=0x80269f0e0) at ../src/wayland-server.c:1493
#30 0x00000000007b191c in CCompositor::startCompositor() ()
#31 0x0000000000712e3c in main ()

$ cat /tmp/hyprland.conf
exec-once = kitty

misc {
    enable_swallow = true
    swallow_regex = ?
    swallow_exception_regex = ?
}

Simplified example:

$ clang++ -o test-libc++ -stdlib=libc++ a.cc
$ g++ -o test-libstdc++ a.cc

$ ./test-libc++ "[[EMPTY]]"
regex_error: The parser did not consume the entire regular expression.
$ ./test-libc++ "?"
regex_error: One of *?+{ was not preceded by a valid regular expression.

$ ./test-libstdc++ "[[EMPTY]]"
$ ./test-libstdc++ "?"
regex_error: Mismatched '(' and ')' in regular expression

$ cat a.cc
#include <iostream>
#include <regex>

int main(int argc, char **argv)
{
    if (argc < 2) {
	std::cerr << "usage: " << argv[0] << " regex" << std::endl;
	return 1;
    }
    try {
        std::regex rgx(argv[1]);
    }
    catch (const std::regex_error& e) {
        std::cout << "regex_error: " << e.what() << std::endl;
    }
    return 0;
}
@jbeich jbeich added the bug Something isn't working label Apr 15, 2023
@vaxerski
Copy link
Member

should be fixed with 8944db4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants