Fix invalid memory access with :recover command #1488
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an invalid memory access in the :recover command in
Vim-8.0.336 and older. It's an old bug since at least vim-7.4.52
in ubuntu-14.04 already has the bug. Bug was found using afl-fuzz.
Step to reproduce:
$ valgrind vim -u NONE -c 'set dir=/' -c rec -cq 2>vg.log
And vg.log contains:
==17014== Memcheck, a memory error detector
==17014== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==17014== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==17014== Command: vim -u NONE -c set\ dir=/ -c rec -cq
==17014==
==17014== Invalid read of size 1
==17014== at 0x4AB231: recover_names (memline.c:1867)
==17014== by 0x4A9AD0: ml_recover (memline.c:1167)
==17014== by 0x46688B: ex_recover (ex_docmd.c:8234)
==17014== by 0x45CCFD: do_one_cmd (ex_docmd.c:2981)
==17014== by 0x458F5D: do_cmdline (ex_docmd.c:1120)
==17014== by 0x5D1F2C: exe_commands (main.c:2905)
==17014== by 0x5D1F2C: vim_main2 (main.c:781)
==17014== by 0x5D0859: main (main.c:415)
==17014== Address 0x769305f is 1 bytes before a block of size 2 alloc'd
==17014== at 0x4C2ABF5: malloc (vg_replace_malloc.c:299)
==17014== by 0x4C5A17: lalloc (misc2.c:942)
==17014== by 0x4AB150: recover_names (memline.c:1801)
==17014== by 0x4A9AD0: ml_recover (memline.c:1167)
==17014== by 0x46688B: ex_recover (ex_docmd.c:8234)
==17014== by 0x45CCFD: do_one_cmd (ex_docmd.c:2981)
==17014== by 0x458F5D: do_cmdline (ex_docmd.c:1120)
==17014== by 0x5D1F2C: exe_commands (main.c:2905)
==17014== by 0x5D1F2C: vim_main2 (main.c:781)
==17014== by 0x5D0859: main (main.c:415)