Skip to content

Commit

Permalink
patch 9.0.0105: illegal memory access when pattern starts with illega…
Browse files Browse the repository at this point in the history
…l byte

Problem:    Illegal memory access when pattern starts with illegal byte.
Solution:   Do not match a character with an illegal byte.
  • Loading branch information
brammool committed Jul 29, 2022
1 parent 1e56bda commit f509405
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/regexp.c
Expand Up @@ -1641,7 +1641,11 @@ cstrchr(char_u *s, int c)
{
if (enc_utf8 && c > 0x80)
{
if (utf_fold(utf_ptr2char(p)) == cc)
int uc = utf_ptr2char(p);

// Do not match an illegal byte. E.g. 0xff matches 0xc3 0xbf,
// not 0xff.
if ((uc < 0x80 || uc != *p) && utf_fold(uc) == cc)
return p;
}
else if (*p == c || *p == cc)
Expand Down
15 changes: 15 additions & 0 deletions src/testdir/test_regexp_utf8.vim
@@ -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臚藻�廎S舅廎艮落廎芬惕 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簽����廘唸�廜�廜��� o簷籀繫繭繹繪������伂廜�廜�廙�廙�廙�廙�廙�廙﹥誨 p廘晨善廑�廜� q�� r������刓廘聊絨廑�廜��� s���禳�廘氮�廜﹥馳廜丟鳩廜抱 t籟聽襲��廘菲鼠廜凍僖廜晨�漹� u羅繳羶羹觼贖躑轡鑄鑒��������廘擔�廜喔僱廜猿凳廜頗誑廙扭貍廙後賒廙脊跼 v�廑厭廜� w霾廕�廕�廕� x廕� y羸藩韁�廕�廙喔輓廙猿遜 z驕髒鱉廘嗤�廕�廕惇"
let groups = split(str)
Expand Down Expand Up @@ -560,6 +562,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"
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -735,6 +735,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
105,
/**/
104,
/**/
Expand Down

0 comments on commit f509405

Please sign in to comment.