aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2017-04-09 13:25:15 -0400
committerGitHub <noreply@github.com>2017-04-09 13:25:15 -0400
commitdbdd69e418a3baa4750abc25fae7516a36776e75 (patch)
tree52007980f4b417d001d37e7fd508b72cfef5432a
parent26bf6e6f6f8819a758611a88e0c0b04e38d4b915 (diff)
parent06a96df510e1fa8d77d21a8120e97342d04be15f (diff)
downloadrneovim-dbdd69e418a3baa4750abc25fae7516a36776e75.tar.gz
rneovim-dbdd69e418a3baa4750abc25fae7516a36776e75.tar.bz2
rneovim-dbdd69e418a3baa4750abc25fae7516a36776e75.zip
Merge pull request #6485 from jamessan/vim-8.0.0377
vim-patch:8.0.0377,8.0.0378,8.0.0322,8.0.0376
-rw-r--r--src/nvim/spellfile.c10
-rw-r--r--src/nvim/undo.c15
2 files changed, 17 insertions, 8 deletions
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index 4d7ff558ad..bbef1f5032 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -223,6 +223,7 @@
// few bytes as possible, see offset2bytes())
#include <stdio.h>
+#include <stdint.h>
#include <wctype.h>
#include "nvim/vim.h"
@@ -1569,9 +1570,14 @@ spell_read_tree (
// The tree size was computed when writing the file, so that we can
// allocate it as one long block. <nodecount>
- int len = get4c(fd);
- if (len < 0)
+ long len = get4c(fd);
+ if (len < 0) {
return SP_TRUNCERROR;
+ }
+ if ((size_t)len >= SIZE_MAX / sizeof(int)) {
+ // Invalid length, multiply with sizeof(int) would overflow.
+ return SP_FORMERROR;
+ }
if (len > 0) {
// Allocate the byte array.
bp = xmalloc(len);
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 4d4e8d9bb9..571ad7204f 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -76,6 +76,7 @@
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
+#include <stdint.h>
#include <string.h>
#include <fcntl.h>
@@ -966,12 +967,12 @@ static u_entry_T *unserialize_uep(bufinfo_T * bi, bool *error,
uep->ue_lcount = undo_read_4c(bi);
uep->ue_size = undo_read_4c(bi);
- char_u **array;
+ char_u **array = NULL;
if (uep->ue_size > 0) {
- array = xmalloc(sizeof(char_u *) * (size_t)uep->ue_size);
- memset(array, 0, sizeof(char_u *) * (size_t)uep->ue_size);
- } else {
- array = NULL;
+ if ((size_t)uep->ue_size < SIZE_MAX / sizeof(char_u *)) {
+ array = xmalloc(sizeof(char_u *) * (size_t)uep->ue_size);
+ memset(array, 0, sizeof(char_u *) * (size_t)uep->ue_size);
+ }
}
uep->ue_array = array;
@@ -1400,7 +1401,9 @@ void u_read_undo(char *name, char_u *hash, char_u *orig_name)
// sequence numbers of the headers.
// When there are no headers uhp_table is NULL.
if (num_head > 0) {
- uhp_table = xmalloc((size_t)num_head * sizeof(u_header_T *));
+ if ((size_t)num_head < SIZE_MAX / sizeof(*uhp_table)) {
+ uhp_table = xmalloc((size_t)num_head * sizeof(*uhp_table));
+ }
}
long num_read_uhps = 0;