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) |
429 | 429 | WRect *r; |
430 | 430 | |
431 | 431 | item = &g_array_index (widgets, quick_widget_item_t, i); |
432 | | r = &item->widget->rect; |
433 | 432 | column_width = two_columns ? width2 : width1; |
434 | 433 | |
435 | 434 | /* adjust widget width and x position */ |
… |
… |
quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) |
448 | 447 | MC_FALLTHROUGH; |
449 | 448 | case quick_checkbox: |
450 | 449 | case quick_radio: |
| 450 | r = &item->widget->rect; |
451 | 451 | if (r->x != x1) |
452 | 452 | r->x = x2; |
453 | 453 | if (g != NULL) |
… |
… |
quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) |
455 | 455 | break; |
456 | 456 | |
457 | 457 | case quick_button: |
| 458 | r = &item->widget->rect; |
458 | 459 | if (!put_buttons) |
459 | 460 | { |
460 | 461 | if (r->x != x1) |
… |
… |
quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) |
477 | 478 | if (g != NULL) |
478 | 479 | width -= 4; |
479 | 480 | |
| 481 | r = &item->widget->rect; |
480 | 482 | switch (item->quick_widget->u.input.label_location) |
481 | 483 | { |
482 | 484 | case input_label_left: |
… |
… |
quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) |
511 | 513 | |
512 | 514 | case quick_start_groupbox: |
513 | 515 | g = GROUPBOX (item->widget); |
| 516 | r = &item->widget->rect; |
514 | 517 | if (r->x != x1) |
515 | 518 | r->x = x2; |
516 | 519 | r->cols = column_width; |
… |
… |
quick_dialog_skip (quick_dialog_t *quick_dlg, int nskip) |
523 | 526 | case quick_separator: |
524 | 527 | if (item->widget != NULL) |
525 | 528 | { |
| 529 | r = &item->widget->rect; |
526 | 530 | if (g != NULL) |
527 | 531 | { |
528 | 532 | Widget *wg = WIDGET (g); |