Ticket #4572: mc-4572-quick_c-fix-undefined-behaviour.patch

File mc-4572-quick_c-fix-undefined-behaviour.patch, 3.8 KB (added by and, 2 days ago)
  • lib/widget/quick.c

    From 5bc7aaf54310e08a3f2e1878cabb94c5de6db0b8 Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Thu, 19 Dec 2024 16:00:00 +0000
    Subject: [PATCH] (quick.c) fix undefined behavior
    
    quick.c:432:28: runtime error: member access within null pointer of type 'Widget' (aka 'struct Widget')
       #0 in quick_dialog_skip lib/widget/quick.c:432:28
       #1 in file_mask_dialog src/filemanager/filegui.c:1462:19
       #2 in do_confirm_copy_move src/filemanager/file.c:1977:11
       #3 in panel_operate src/filemanager/file.c:3536:16
       #4 in copy_cmd src/filemanager/./cmd.h:111:5
       #5 in midnight_execute_cmd src/filemanager/filemanager.c:1177:9
       #6 in midnight_callback src/filemanager/filemanager.c
       #7 in send_message lib/widget/../../lib/widget/widget-common.h:255:15
       #8 in buttonbar_call lib/widget/buttonbar.c:157:15
       #9 in buttonbar_callback lib/widget/buttonbar.c:174:42
       #10 in send_message lib/widget/../../lib/widget/widget-common.h:255:15
       #11 in group_handle_hotkey lib/widget/group.c:566:23
       #12 in group_default_callback lib/widget/group.c:640:16
       #13 in dlg_default_callback lib/widget/dialog.c:370:16
       #14 in midnight_callback src/filemanager/filemanager.c:1615:16
       #15 in send_message lib/widget/../../lib/widget/widget-common.h:255:15
       #16 in group_handle_key lib/widget/group.c:503:15
       #17 in group_default_callback lib/widget/group.c:637:16
       #18 in dlg_key_event lib/widget/dialog.c:252:19
       #19 in dlg_process_event lib/widget/dialog.c:539:9
       #20 in frontend_dlg_run lib/widget/dialog.c:321:9
       #21 in dlg_run lib/widget/dialog.c:573:5
       #22 in do_nc src/filemanager/filemanager.c:1826:16
       #23 in main src/main.c:469:21
       #24 in <null> <null>
       #25 in __libc_start_main <null>
       #26 in _start <null>
    
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior quick.c:432:28 
    
    Found by Clang-19 Static Analyzer
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     lib/widget/quick.c | 6 +++++-
     1 file changed, 5 insertions(+), 1 deletion(-)
    
    diff --git a/lib/widget/quick.c b/lib/widget/quick.c
    index 1930c6109..934c16c1f 100644
    a b quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) 
    429429        WRect *r; 
    430430 
    431431        item = &g_array_index (widgets, quick_widget_item_t, i); 
    432         r = &item->widget->rect; 
    433432        column_width = two_columns ? width2 : width1; 
    434433 
    435434        /* adjust widget width and x position */ 
    quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) 
    448447            MC_FALLTHROUGH; 
    449448        case quick_checkbox: 
    450449        case quick_radio: 
     450            r = &item->widget->rect; 
    451451            if (r->x != x1) 
    452452                r->x = x2; 
    453453            if (g != NULL) 
    quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) 
    455455            break; 
    456456 
    457457        case quick_button: 
     458            r = &item->widget->rect; 
    458459            if (!put_buttons) 
    459460            { 
    460461                if (r->x != x1) 
    quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) 
    477478                if (g != NULL) 
    478479                    width -= 4; 
    479480 
     481                r = &item->widget->rect; 
    480482                switch (item->quick_widget->u.input.label_location) 
    481483                { 
    482484                case input_label_left: 
    quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) 
    511513 
    512514        case quick_start_groupbox: 
    513515            g = GROUPBOX (item->widget); 
     516            r = &item->widget->rect; 
    514517            if (r->x != x1) 
    515518                r->x = x2; 
    516519            r->cols = column_width; 
    quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) 
    523526        case quick_separator: 
    524527            if (item->widget != NULL) 
    525528            { 
     529                r = &item->widget->rect; 
    526530                if (g != NULL) 
    527531                { 
    528532                    Widget *wg = WIDGET (g);