martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.2k stars 258 forks source link

vis: file corruption and segfault when using regular expressions #1030

Open artsi0m opened 1 year ago

artsi0m commented 1 year ago

vis v0.7 +curses +lua +tre on OpenBSD 7.1 amd64

I tried to rename type with variable from one type to another: I wrote: :x/int token_type/ :c/int_fast8_t token_type/ and so on. One time i wrote: :x/int/ :c/int_fast8_t/ but then i hit undo because it would change <stdint.h> into <stdint_fast8_t.h> Then i continued renaming type with variable. At some point vise segfaulted and corrupted file.

For example: errx(1, "Inconsistent number of operators"); changed into errx(1, "I_fast64_tnconsistent number of ope_fast8_trators");_fa_fast64_tst8_t

add_token_to_list(TNUM, atoi(argv[i])); changed into add_token_TNUM, atoi(a

This and similar looking changes can be viewed at this commit: https://github.com/artsi0m/argcalc/commit/a5c3d5e1edf6bfa22f983ea3c073d6d2ea025d5d

artsi0m commented 1 year ago

Opened vise.core in lldb

(lldb) target create "/usr/local/bin/vise" --core "vise.core"
Core file '/home/artsi0m/SRC/argcalc/vise.core' (x86_64) was loaded.
(lldb) bt
* thread #1, stop reason = signal SIGSEGV
  * frame #0: 0x0000020548464a77 vise`view_selections_dispose_force + 39
    frame #1: 0x00000205484532b3 vise`extract + 867
    frame #2: 0x00000205484505f1 vise`cmd_extract + 161
    frame #3: 0x000002054844f603 vise`sam_execute + 179
    frame #4: 0x0000020548453466 vise`cmd_select + 198
    frame #5: 0x000002054844f603 vise`sam_execute + 179
    frame #6: 0x000002054844f170 vise`sam_cmd + 448
    frame #7: 0x000002054846a006 vise`vis_cmd + 134
    frame #8: 0x0000020548476a9d vise`prompt_enter + 733
    frame #9: 0x0000020548469843 vise`vis_keys_push + 1059
    frame #10: 0x000002054846935d vise`vis_run + 797
    frame #11: 0x000002054844b375 vise`main + 1765
    frame #12: 0x0000020548449572 vise`__start + 322
mcepl commented 1 year ago

Wouldn’t you have some more descriptive traceback? gdb usually gives me also signatures of all functions being called with values of their arguments.

artsi0m commented 1 year ago

Sorry, for late response. Unfortunately i lost original vise.core file. I may try to reproduce it later. For today i mostly spend my time studying in university.