0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.3595: check for signed overflow might not work everywhere

Problem:    Check for signed overflow might not work everywhere.
Solution:   Limit to 32 bit int. (closes #9043, closes #9067)
This commit is contained in:
Bram Moolenaar
2021-11-14 14:05:18 +00:00
parent 786e05beb5
commit 0d5a12ea04
2 changed files with 8 additions and 2 deletions

View File

@@ -1001,6 +1001,8 @@ ins_typebuf(
} }
else else
{ {
int extra;
/* /*
* Need to allocate a new buffer. * Need to allocate a new buffer.
* In typebuf.tb_buf there must always be room for 3 * (MAXMAPLEN + 4) * In typebuf.tb_buf there must always be room for 3 * (MAXMAPLEN + 4)
@@ -1008,13 +1010,15 @@ ins_typebuf(
* often. * often.
*/ */
newoff = MAXMAPLEN + 4; newoff = MAXMAPLEN + 4;
newlen = typebuf.tb_len + addlen + newoff + 4 * (MAXMAPLEN + 4); extra = addlen + newoff + 4 * (MAXMAPLEN + 4);
if (newlen < 0) // string is getting too long if (typebuf.tb_len > 2147483647 - extra)
{ {
// string is getting too long for a 32 bit int
emsg(_(e_toocompl)); // also calls flush_buffers emsg(_(e_toocompl)); // also calls flush_buffers
setcursor(); setcursor();
return FAIL; return FAIL;
} }
newlen = typebuf.tb_len + extra;
s1 = alloc(newlen); s1 = alloc(newlen);
if (s1 == NULL) // out of memory if (s1 == NULL) // out of memory
return FAIL; return FAIL;

View File

@@ -757,6 +757,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3595,
/**/ /**/
3594, 3594,
/**/ /**/