gri3-wm/src
Chih-Chyuan Hwang faa9915abc Fix an use-after-free bug (#2522)
Fix the issue #2421 (https://github.com/i3/i3/issues/2421).

floating_enable() invokes tree_close_internal() to free con->parent.
After con->parent is freed in tree_close_internal() but before con->parent is reassigned by the caller, con->parent may be dereferenced and causes i3 crash.

The backtrace below is an example.
The already-freed pointer is dereferenced again through the pointer "focused" in x_push_changes().

Reassign con->parent before calling tree_close_internal() to fix this use-after-free bug.

0x0000000000416372 in con_get_workspace (con=0x7ab9c0) at ../i3/src/con.c:375
0x0000000000416103 in con_has_managed_window (con=0x7ab9c0) at ../i3/src/con.c:266
0x000000000042b413 in x_push_changes (con=0x78d190) at ../i3/src/x.c:1132
0x0000000l0004533e8 in tree_render () at ../i3/src/tree.c:504
0x0000000000452b4f in tree_close_internal (con=0x7b67c0, kill_window=DONT_KILL_WINDOW, dont_kill_parent=false, force_set_focus=false)
../i3/src/tree.c:314
0x00000000004196f0 in con_on_remove_child (con=0x7b67c0) at ../i3/src/con.c:1801
0x0000000000452eb7 in tree_close_internal (con=0x783840, kill_window=DONT_KILL_WINDOW, dont_kill_parent=false, force_set_focus=false)
../i3/src/tree.c:364
0x0000000000431516 in floating_enable (con=0x7ab9c0, automatic=false) at ../i3/src/floating.c:183
0x0000000000431eed in toggle_floating_mode (con=0x7ab9c0, automatic=false) at ../i3/src/floating.c:379
0x0000000000420d92 in cmd_floating (current_match=0x679a20 , cmd_output=0x679aa0 , floating_mode=0x7ab8c0 "toggle")
../i3/src/commands.c:1088
0x000000000043e5ae in GENERATED_call (call_identifier=60, result=0x679aa0 ) at include/GENERATED_command_call.h:486
0x000000000043ee19 in next_state (token=0x675d70 ) at ../i3/src/commands_parser.c:187
0x000000000043f2fb in parse_command (input=0x7b4fe0 "floating toggle", gen=0x0) at ../i3/src/commands_parser.c:308
0x00000000004125f8 in run_binding (bind=0x784260, con=0x0) at ../i3/src/bindings.c:792
0x000000000042bace in handle_key_press (event=0x7a01a0) at ../i3/src/key_press.c:33
0x000000000044e6aa in handle_event (type=2, event=0x7a01a0) at ../i3/src/handlers.c:1420
0x0000000000439533 in xcb_check_cb (loop=0x7ffff532f8e0, w=0x68c140, revents=32768) at ../i3/src/main.c:133
0x00007ffff5125d73 in ev_invoke_pending () from /usr/lib/x86_64-linux-gnu/libev.so.4
0x00007ffff51293de in ev_run () from /usr/lib/x86_64-linux-gnu/libev.so.4
0x0000000000439418 in ev_loop (loop=0x7ffff532f8e0, flags=0) at /usr/include/ev.h:835
0x000000000043d51d in main (argc=3, argv=0x7fffffffe0a8) at ../i3/src/main.c:913
2016-11-08 00:56:46 -08:00
..
assignments.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
bindings.c Bugfix: don’t apply shift+numlock fallback for keypad keys 2016-09-12 22:24:23 +02:00
click.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
commands.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
commands_parser.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
con.c Merge pull request #2507 from stapelberg/autotools 2016-10-25 08:56:12 +02:00
config.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
config_directives.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
config_parser.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
debug.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
display_version.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
ewmh.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
fake_outputs.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
floating.c Fix an use-after-free bug (#2522) 2016-11-08 00:56:46 -08:00
handlers.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
ipc.c Merge pull request #2507 from stapelberg/autotools 2016-10-25 08:56:12 +02:00
key_press.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
load_layout.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
log.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
main.c Fix memory leaks. (#2530) 2016-11-03 00:18:18 -07:00
manage.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
match.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
move.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
output.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
randr.c Fix an use-after-free bug (#2522) 2016-11-08 00:56:46 -08:00
regex.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
render.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
resize.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
restore_layout.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
scratchpad.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
sd-daemon.c Always use socket activation 2016-06-11 14:47:23 +02:00
sighandler.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
startup.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
tree.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
util.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
version.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
window.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
workspace.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
x.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
xcb.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
xcursor.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00
xinerama.c Ensure all *.[ch] files include config.h 2016-10-23 21:09:24 +02:00