Skip to content

Commit 191f18b

Browse files
committed
patch 8.0.1468: illegal memory access in del_bytes()
Problem: Illegal memory access in del_bytes(). Solution: Check for negative byte count. (Christian Brabandt, closes #2466)
1 parent fef4ddd commit 191f18b

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/message.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ emsgn(char_u *s, long n)
761761
void
762762
iemsg(char_u *s)
763763
{
764-
msg(s);
764+
emsg(s);
765765
#ifdef ABORT_ON_INTERNAL_ERROR
766766
abort();
767767
#endif
@@ -4993,7 +4993,7 @@ vim_vsnprintf_typval(
49934993
zero_padding = 0;
49944994
}
49954995
else
4996-
{
4996+
{
49974997
/* Regular float number */
49984998
format[0] = '%';
49994999
l = 1;
@@ -5016,7 +5016,7 @@ vim_vsnprintf_typval(
50165016
format[l + 1] = NUL;
50175017

50185018
str_arg_l = sprintf(tmp, format, f);
5019-
}
5019+
}
50205020

50215021
if (remove_trailing_zeroes)
50225022
{

src/misc1.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,7 +2457,7 @@ del_chars(long count, int fixpos)
24572457
* If "fixpos" is TRUE, don't leave the cursor on the NUL after the line.
24582458
* Caller must have prepared for undo.
24592459
*
2460-
* return FAIL for failure, OK otherwise
2460+
* Return FAIL for failure, OK otherwise.
24612461
*/
24622462
int
24632463
del_bytes(
@@ -2476,12 +2476,21 @@ del_bytes(
24762476
oldp = ml_get(lnum);
24772477
oldlen = (int)STRLEN(oldp);
24782478

2479-
/*
2480-
* Can't do anything when the cursor is on the NUL after the line.
2481-
*/
2479+
/* Can't do anything when the cursor is on the NUL after the line. */
24822480
if (col >= oldlen)
24832481
return FAIL;
24842482

2483+
/* If "count" is zero there is nothing to do. */
2484+
if (count == 0)
2485+
return OK;
2486+
2487+
/* If "count" is negative the caller must be doing something wrong. */
2488+
if (count < 1)
2489+
{
2490+
IEMSGN("E950: Invalid count for del_bytes(): %ld", count);
2491+
return FAIL;
2492+
}
2493+
24852494
#ifdef FEAT_MBYTE
24862495
/* If 'delcombine' is set and deleting (less than) one character, only
24872496
* delete the last combining character. */

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+
1468,
774776
/**/
775777
1467,
776778
/**/

0 commit comments

Comments
 (0)