diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-09-19 17:40:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-19 17:40:55 -0400 |
commit | 9f704c88a57cfb797c21c19672ea6617e9673360 (patch) | |
tree | e16e2630d1ed35d32c9af64c7a067be09b39aec8 /src/nvim/eval.c | |
parent | 905c2eb359fc21995c6c0151b169b43c66b287fa (diff) | |
parent | df46f9197764b92e596ad6a5a8c297edc51dd6f6 (diff) | |
download | rneovim-9f704c88a57cfb797c21c19672ea6617e9673360.tar.gz rneovim-9f704c88a57cfb797c21c19672ea6617e9673360.tar.bz2 rneovim-9f704c88a57cfb797c21c19672ea6617e9673360.zip |
Merge pull request #12938 from janlazo/vim-8.1.0285
vim-patch:8.1.{285,1782,1972,2261,2263},8.2.{240,817,824,1549,1676,1696}
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b395d7bb8a..00542e3766 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4518,7 +4518,6 @@ int get_option_tv(const char **const arg, typval_T *const rettv, static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) { char_u *p; - char_u *name; unsigned int extra = 0; /* @@ -4526,11 +4525,14 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) */ for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) { if (*p == '\\' && p[1] != NUL) { - ++p; - /* A "\<x>" form occupies at least 4 characters, and produces up - * to 6 characters: reserve space for 2 extra */ - if (*p == '<') - extra += 2; + p++; + // A "\<x>" form occupies at least 4 characters, and produces up + // to 21 characters (3 * 6 for the char and 3 for a modifier): + // reserve space for 18 extra. + // Each byte in the char could be encoded as K_SPECIAL K_EXTRA x. + if (*p == '<') { + extra += 18; + } } } @@ -4549,7 +4551,8 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) * Copy the string into allocated memory, handling backslashed * characters. */ - name = xmalloc(p - *arg + extra); + const int len = (int)(p - *arg + extra); + char_u *name = xmalloc(len); rettv->v_type = VAR_STRING; rettv->vval.v_string = name; @@ -4616,6 +4619,9 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) extra = trans_special((const char_u **)&p, STRLEN(p), name, true, true); if (extra != 0) { name += extra; + if (name >= rettv->vval.v_string + len) { + iemsg("get_string_tv() used more space than allocated"); + } break; } FALLTHROUGH; |