Skip to content

Commit 6281815

Browse files
committed
patch 8.2.2515: memory access error when truncating an empty message
Problem: Memory access error when truncating an empty message. Solution: Check for an empty string. (Dominique Pellé, closes #7841)
1 parent 2379f87 commit 6281815

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/message.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ trunc_string(
248248
int i;
249249
int n;
250250

251+
if (*s == NUL)
252+
{
253+
if (buflen > 0)
254+
*buf = NUL;
255+
return;
256+
}
257+
251258
if (room_in < 3)
252259
room = 0;
253260
half = room / 2;

src/message_test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ test_trunc_string(void)
4949
char_u *buf; /*allocated every time to find uninit errors */
5050
char_u *s;
5151

52+
// Should not write anything to destination if buflen is 0.
53+
trunc_string((char_u *)"", NULL, 1, 0);
54+
55+
// Truncating an empty string does nothing.
56+
buf = alloc(1);
57+
trunc_string((char_u *)"", buf, 1, 1);
58+
assert(buf[0] == NUL);
59+
vim_free(buf);
60+
5261
// in place
5362
buf = alloc(40);
5463
STRCPY(buf, "text");

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2515,
753755
/**/
754756
2514,
755757
/**/

0 commit comments

Comments
 (0)