Ticket #4650 (closed defect: fixed)
Segfault after pressing Shift+F4
Reported by: | linnando | Owned by: | andrew_b |
---|---|---|---|
Priority: | major | Milestone: | 4.8.34 |
Component: | mcedit | Version: | 4.8.33 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Branch state: | merged | Votes for changeset: | committed-master |
Description
Actions to reproduce: press Shift+F4 (reproducibility may depend on the config; I got it on a freshly built instance, but I am not sure which config it pulled).
Expected result: open an editor window.
Actual result: segfault.
The segfault happens at https://github.com/MidnightCommander/mc/blob/5cae1ddd9a4dc80ace53d02da6843401eaeb4e7c/src/execute.c#L311 because argv is dereferenced unconditionally, even though https://github.com/MidnightCommander/mc/blob/5cae1ddd9a4dc80ace53d02da6843401eaeb4e7c/src/execute.c#L664 passes NULL as argv when parsing external_cmd_options fails.
A possible patch is here: https://github.com/linnando/mc/tree/fix-shiftf4-segfault
Output of mc -V:
GNU Midnight Commander 4.8.31
Built with GLib 2.82.1
Built with S-Lang 2.3.3 with terminfo database
Built with libssh2 1.11.0
With builtin Editor and Aspell support
With subshell support as default
With support for background operations
With mouse support on xterm and Linux console
With support for X11 events
With internationalization support
With multiple codepages support
With ext2fs attributes support
Virtual File Systems:
cpiofs, tarfs, sfs, extfs, ext2undelfs, ftpfs, sftpfs, shell
Data types:
char: 8; int: 32; long: 64; void *: 64; size_t: 64; off_t: 64;
Change History
comment:1 Changed 2 weeks ago by andrew_b
- Status changed from new to closed
- Resolution set to invalid
- Component changed from mc-core to mcedit
- Milestone Future Releases deleted
comment:2 Changed 2 weeks ago by andrew_b
Sorry, this is another issue.
In any case, it's not reproducible for me in 4.8.33.
comment:3 Changed 2 weeks ago by linnando
- Status changed from closed to reopened
- Resolution invalid deleted
Yes, it is another issue. Unfortunately, for me it is the same in 4.8.33 and at the current master HEAD. I collected extra information about the reproduction, and the situation looks like that:
- The critical part of the reproduction is entering the branch where g_shell_parse_argv cannot parse the provided argument extern_cmd_options (i.e., https://github.com/MidnightCommander/mc/blob/5cae1ddd9a4dc80ace53d02da6843401eaeb4e7c/src/execute.c#L664).
- In my case, extern_cmd_options contain an empty string, which is enough for g_shell_parse_argv to return an error ("Text was empty (or contained only whitespace)" if I add debug info).
- extern_cmd_options is an empty string because filename_vpath is an empty string, which in turn is caused by the configuration option 'Ask new file name' unchecked.
- I tried checking 'Ask new file name' in the Options / Configuration... menu. In this case, Shift+F4 works correctly: asks for a file name, opens the editor, and allows me to save the file. However, with 'Ask new file name' unchecked, a segmentation fault happens after pressing Shift+F4 (the editor does not open). With the fix that I provided, Shift+F4 opens the editor, allows me to edit the file and asks for the file name before saving it.
comment:4 Changed 2 weeks ago by zaytsev
- Priority changed from minor to major
- Version changed from master to 4.8.33
- Milestone set to 4.8.34
comment:5 Changed 2 weeks ago by andrew_b
- Owner set to andrew_b
- Status changed from reopened to accepted
comment:6 Changed 2 weeks ago by andrew_b
- Votes for changeset set to andrew_b
- Branch state changed from no branch to on review
Branch: 4650_shift_f4_segfault
changeset:ed0bf815035394e7cb8a750d85c57b36cc33bf75
comment:7 Changed 2 weeks ago by zaytsev
- Votes for changeset changed from andrew_b to andrew_b zaytsev
- Branch state changed from on review to approved
Thank you!
comment:8 Changed 2 weeks ago by andrew_b
- Status changed from accepted to testing
- Votes for changeset changed from andrew_b zaytsev to committed-master
- Resolution set to fixed
- Branch state changed from approved to merged
Merged to master: [f2b482886711a1305abffdffa054216944453f3d].
#4580
Fixed in 4.8.33.