Fixed heap-buffer-overflow detected by asan in searchc() #1528
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.
afl-fuzz found another case that causes invalid memory access
in vim-8.0.397 and older. The bug is detected by asan, but not by
valgrind somehow.
Steps to reproduced:
The crash happen at search.c:1698:
Adding printf(), I see that:
Bug happen because memcpy at search:1689 compares 3 bytes which can
go beyond end of string p+col. Using STRNCMP() instead of memcmp() fixes it.
I also added a test that triggers the invalid memory access prior to the fix.