Skip to content

Commit 43dee18

Browse files
committed
patch 8.1.0056: crash when using :hardcopy with illegal byte
Problem: Crash when using :hardcopy with illegal byte. Solution: Check for string_convert() returning NULL. (Dominique Pelle)
1 parent 52d3aae commit 43dee18

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/hardcopy.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3372,8 +3372,9 @@ mch_print_start_line(int margin, int page_line)
33723372
}
33733373

33743374
int
3375-
mch_print_text_out(char_u *p, int len UNUSED)
3375+
mch_print_text_out(char_u *textp, int len UNUSED)
33763376
{
3377+
char_u *p = textp;
33773378
int need_break;
33783379
char_u ch;
33793380
char_u ch_buff[8];
@@ -3508,8 +3509,15 @@ mch_print_text_out(char_u *p, int len UNUSED)
35083509

35093510
#ifdef FEAT_MBYTE
35103511
if (prt_do_conv)
3512+
{
35113513
/* Convert from multi-byte to 8-bit encoding */
35123514
tofree = p = string_convert(&prt_conv, p, &len);
3515+
if (p == NULL)
3516+
{
3517+
p = (char_u *)"";
3518+
len = 0;
3519+
}
3520+
}
35133521

35143522
if (prt_out_mbyte)
35153523
{

src/testdir/test_hardcopy.vim

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,27 @@ func Test_with_syntax()
6363
endfunc
6464

6565
func Test_fname_with_spaces()
66-
if has('postscript')
67-
split t\ e\ s\ t.txt
68-
call setline(1, ['just', 'some', 'text'])
69-
hardcopy > %.ps
70-
call assert_true(filereadable('t e s t.txt.ps'))
71-
call delete('t e s t.txt.ps')
72-
bwipe!
66+
if !has('postscript')
67+
return
68+
endif
69+
split t\ e\ s\ t.txt
70+
call setline(1, ['just', 'some', 'text'])
71+
hardcopy > %.ps
72+
call assert_true(filereadable('t e s t.txt.ps'))
73+
call delete('t e s t.txt.ps')
74+
bwipe!
75+
endfunc
76+
77+
func Test_illegal_byte()
78+
if !has('postscript') || &enc != 'utf-8'
79+
return
7380
endif
81+
new
82+
" conversion of 0xff will fail, this used to cause a crash
83+
call setline(1, "\xff")
84+
hardcopy >Xpstest
85+
86+
bwipe!
87+
call delete('Xpstest')
7488
endfunc
89+

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
56,
764766
/**/
765767
55,
766768
/**/

0 commit comments

Comments
 (0)