Skip to content

Commit cdd09aa

Browse files
committed
patch 8.0.1503: access memory beyond end of string
Problem: Access memory beyond end of string. (Coverity) Solution: Keep allocated memory in separate pointer. Avoid outputting the NUL character.
1 parent 71a43c0 commit cdd09aa

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

src/hardcopy.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,6 +3382,7 @@ mch_print_text_out(char_u *p, int len UNUSED)
33823382
#ifdef FEAT_MBYTE
33833383
int in_ascii;
33843384
int half_width;
3385+
char_u *tofree = NULL;
33853386
#endif
33863387

33873388
char_width = prt_char_width;
@@ -3507,27 +3508,22 @@ mch_print_text_out(char_u *p, int len UNUSED)
35073508

35083509
#ifdef FEAT_MBYTE
35093510
if (prt_do_conv)
3510-
{
35113511
/* Convert from multi-byte to 8-bit encoding */
3512-
p = string_convert(&prt_conv, p, &len);
3513-
if (p == NULL)
3514-
p = (char_u *)"";
3515-
}
3512+
tofree = p = string_convert(&prt_conv, p, &len);
35163513

35173514
if (prt_out_mbyte)
35183515
{
35193516
/* Multi-byte character strings are represented more efficiently as hex
35203517
* strings when outputting clean 8 bit PS.
35213518
*/
3522-
do
3519+
while (len-- > 0)
35233520
{
35243521
ch = prt_hexchar[(unsigned)(*p) >> 4];
35253522
ga_append(&prt_ps_buffer, ch);
35263523
ch = prt_hexchar[(*p) & 0xf];
35273524
ga_append(&prt_ps_buffer, ch);
35283525
p++;
35293526
}
3530-
while (--len);
35313527
}
35323528
else
35333529
#endif
@@ -3574,8 +3570,7 @@ mch_print_text_out(char_u *p, int len UNUSED)
35743570

35753571
#ifdef FEAT_MBYTE
35763572
/* Need to free any translated characters */
3577-
if (prt_do_conv && (*p != NUL))
3578-
vim_free(p);
3573+
vim_free(tofree);
35793574
#endif
35803575

35813576
prt_text_run += char_width;

src/version.c

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

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1503,
774776
/**/
775777
1502,
776778
/**/

0 commit comments

Comments
 (0)