mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
vim-patch:9.0.0105: illegal memory access when pattern starts with illegal byte
Problem: Illegal memory access when pattern starts with illegal byte.
Solution: Do not match a character with an illegal byte.
f50940531d
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
63cd2adf3d
commit
17f95fe79b
@ -1804,7 +1804,9 @@ static inline char *cstrchr(const char *const s, const int c)
|
||||
if (c > 0x80) {
|
||||
const int folded_c = utf_fold(c);
|
||||
for (const char *p = s; *p != NUL; p += utfc_ptr2len(p)) {
|
||||
if (utf_fold(utf_ptr2char(p)) == folded_c) {
|
||||
const int uc = utf_ptr2char(p);
|
||||
// Do not match an illegal byte. E.g. 0xff matches 0xc3 0xbf, not 0xff.
|
||||
if ((uc < 0x80 || uc != (uint8_t)(*p)) && utf_fold(uc) == folded_c) {
|
||||
return (char *)p;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
" Tests for regexp in utf8 encoding
|
||||
|
||||
source shared.vim
|
||||
|
||||
func s:equivalence_test()
|
||||
let str = "AÀÁÂÃÄÅĀĂĄǍǞǠǺȂȦȺḀẠẢẤẦẨẪẬẮẰẲẴẶ BƁɃḂḄḆ CÇĆĈĊČƇȻḈꞒ DĎĐƊḊḌḎḐḒ EÈÉÊËĒĔĖĘĚȄȆȨɆḔḖḘḚḜẸẺẼẾỀỂỄỆ FƑḞꞘ GĜĞĠĢƓǤǦǴḠꞠ HĤĦȞḢḤḦḨḪⱧ IÌÍÎÏĨĪĬĮİƗǏȈȊḬḮỈỊ JĴɈ KĶƘǨḰḲḴⱩꝀ LĹĻĽĿŁȽḶḸḺḼⱠ MḾṀṂ NÑŃŅŇǸṄṆṈṊꞤ OÒÓÔÕÖØŌŎŐƟƠǑǪǬǾȌȎȪȬȮȰṌṎṐṒỌỎỐỒỔỖỘỚỜỞỠỢ PƤṔṖⱣ QɊ RŔŖŘȐȒɌṘṚṜṞⱤꞦ SŚŜŞŠȘṠṢṤṦṨⱾꞨ TŢŤŦƬƮȚȾṪṬṮṰ UÙÚÛÜŨŪŬŮŰƯǕǙǛǓǗȔȖɄṲṴṶṸṺỤỦỨỪỬỮỰ VƲṼṾ WŴẀẂẄẆẈ XẊẌ YÝŶŸƳȲɎẎỲỴỶỸ ZŹŻŽƵẐẒẔⱫ aàáâãäåāăąǎǟǡǻȃȧᶏḁẚạảấầẩẫậắằẳẵặⱥ bƀɓᵬᶀḃḅḇ cçćĉċčƈȼḉꞓꞔ dďđɗᵭᶁᶑḋḍḏḑḓ eèéêëēĕėęěȅȇȩɇᶒḕḗḙḛḝẹẻẽếềểễệ fƒᵮᶂḟꞙ gĝğġģǥǧǵɠᶃḡꞡ hĥħȟḣḥḧḩḫẖⱨꞕ iìíîïĩīĭįǐȉȋɨᶖḭḯỉị jĵǰɉ kķƙǩᶄḱḳḵⱪꝁ lĺļľŀłƚḷḹḻḽⱡ mᵯḿṁṃ nñńņňʼnǹᵰᶇṅṇṉṋꞥ oòóôõöøōŏőơǒǫǭǿȍȏȫȭȯȱɵṍṏṑṓọỏốồổỗộớờởỡợ pƥᵱᵽᶈṕṗ qɋʠ rŕŗřȑȓɍɽᵲᵳᶉṛṝṟꞧ sśŝşšșȿᵴᶊṡṣṥṧṩꞩ tţťŧƫƭțʈᵵṫṭṯṱẗⱦ uùúûüũūŭůűųǚǖưǔǘǜȕȗʉᵾᶙṳṵṷṹṻụủứừửữự vʋᶌṽṿ wŵẁẃẅẇẉẘ xẋẍ yýÿŷƴȳɏẏẙỳỵỷỹ zźżžƶᵶᶎẑẓẕⱬ"
|
||||
let groups = split(str)
|
||||
@ -559,6 +561,19 @@ func Test_match_invalid_byte()
|
||||
call delete('Xinvalid')
|
||||
endfunc
|
||||
|
||||
func Test_match_illegal_byte()
|
||||
let lines =<< trim END
|
||||
silent! buffer ÿ\c
|
||||
next ÿ
|
||||
0scriptnames
|
||||
source
|
||||
END
|
||||
call writefile(lines, 'Xregexp')
|
||||
call system(GetVimCommand() .. ' -X -Z -e -s -S Xregexp -c qa!')
|
||||
|
||||
call delete('Xregexp')
|
||||
endfunc
|
||||
|
||||
func Test_match_too_complicated()
|
||||
set regexpengine=1
|
||||
exe "noswapfile vsplit \xeb\xdb\x99"
|
||||
|
Loading…
Reference in New Issue
Block a user