Changeset 0415776 in mainline


Ignore:
Timestamp:
2022-05-24T14:21:32Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
174be87
Parents:
8b22d44
git-author:
Jiri Svoboda <jiri@…> (2022-05-23 17:21:15)
git-committer:
Jiri Svoboda <jiri@…> (2022-05-24 14:21:32)
Message:

Prevent use after free when destroying window

Cannot access window after return from event handler (where it could
have been destroyed), cannot deliver event to window if it was
already claimed by window decoration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/window.c

    r8b22d44 r0415776  
    400400        ui_wdecor_destroy(window->wdecor);
    401401        ui_resource_destroy(window->res);
    402         if (0 && window->app_mgc != NULL)
     402        if (window->app_mgc != NULL)
    403403                mem_gc_delete(window->app_mgc);
    404         if (0 && window->app_bmp != NULL)
     404        if (window->app_bmp != NULL)
    405405                gfx_bitmap_destroy(window->app_bmp);
    406406        if (window->mgc != NULL) {
     
    413413                display_window_destroy(window->dwindow);
    414414
    415         free(window);
    416 
    417415        /* Need to repaint if windows are emulated */
    418416        if (ui_is_fullscreen(ui)) {
     
    424422                (void) console_set_caption(ui->console, "");
    425423        }
     424
     425        free(window);
    426426}
    427427
     
    810810{
    811811        ui_window_t *window = (ui_window_t *) arg;
    812 
    813         ui_lock(window->ui);
     812        ui_t *ui = window->ui;
     813
     814        ui_lock(ui);
    814815
    815816        if (window->wdecor != NULL) {
     
    819820
    820821        ui_window_send_focus(window);
    821         ui_unlock(window->ui);
     822        ui_unlock(ui);
    822823}
    823824
     
    826827{
    827828        ui_window_t *window = (ui_window_t *) arg;
    828 
    829         ui_lock(window->ui);
     829        ui_t *ui = window->ui;
     830
     831        ui_lock(ui);
    830832        ui_window_send_kbd(window, kbd_event);
    831         ui_unlock(window->ui);
     833        ui_unlock(ui);
    832834}
    833835
     
    836838{
    837839        ui_window_t *window = (ui_window_t *) arg;
     840        ui_t *ui = window->ui;
     841        ui_evclaim_t claim;
    838842
    839843        /* Make sure we don't process events until fully initialized */
     
    841845                return;
    842846
    843         ui_lock(window->ui);
    844         ui_wdecor_pos_event(window->wdecor, event);
     847        ui_lock(ui);
     848
     849        claim = ui_wdecor_pos_event(window->wdecor, event);
     850        if (claim == ui_claimed) {
     851                ui_unlock(ui);
     852                return;
     853        }
     854
    845855        ui_window_send_pos(window, event);
    846         ui_unlock(window->ui);
     856        ui_unlock(ui);
    847857}
    848858
     
    851861{
    852862        ui_window_t *window = (ui_window_t *) arg;
     863        ui_t *ui = window->ui;
    853864
    854865        /* Make sure we don't process events until fully initialized */
     
    859870                return;
    860871
    861         ui_lock(window->ui);
     872        ui_lock(ui);
    862873        (void) ui_window_resize(window, rect);
    863874        (void) ui_window_paint(window);
    864         ui_unlock(window->ui);
     875        ui_unlock(ui);
    865876}
    866877
     
    869880{
    870881        ui_window_t *window = (ui_window_t *) arg;
    871 
    872         ui_lock(window->ui);
     882        ui_t *ui = window->ui;
     883
     884        ui_lock(ui);
    873885
    874886        if (window->wdecor != NULL) {
     
    878890
    879891        ui_window_send_unfocus(window);
    880         ui_unlock(window->ui);
     892        ui_unlock(ui);
    881893}
    882894
Note: See TracChangeset for help on using the changeset viewer.