From c15e796211f04b16f58d06fe440f4009a69a1a01 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 25 Jan 2016 02:12:06 -0500 Subject: [PATCH 1/4] coverity/125476: RI: Null pointer dereference --- src/nvim/eval.c | 12 ++++++------ src/nvim/version.c | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 219bd38d82..33c584eede 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10786,15 +10786,15 @@ static void f_globpath(typval_T *argvars, typval_T *rettv) } } -/* - * "glob2regpat()" function - */ +// "glob2regpat()" function static void f_glob2regpat(typval_T *argvars, typval_T *rettv) { - char_u *pat = get_tv_string_chk(&argvars[0]); + char_u *pat = get_tv_string_chk(&argvars[0]); // NULL on type error - rettv->v_type = VAR_STRING; - rettv->vval.v_string = file_pat_to_reg_pat(pat, NULL, NULL, FALSE); + rettv->v_type = VAR_STRING; + rettv->vval.v_string = (pat == NULL) + ? NULL + : file_pat_to_reg_pat(pat, NULL, NULL, false); } /* diff --git a/src/nvim/version.c b/src/nvim/version.c index dcd1773a7a..acdee8c005 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -69,6 +69,12 @@ static char *features[] = { // clang-format off static int included_patches[] = { + 1081, + + + + + 1055, // 1054, // 1053, From 765d394f18733bc6d962e3915ff53c06ac095642 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 27 Jan 2016 03:19:23 -0500 Subject: [PATCH 2/4] vim-patch:ac809999 https://github.com/vim/vim/commit/ac80999985299dae4a9ef56dbf31fbdb35c04c08 --- test/functional/legacy/glob2regpat_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/functional/legacy/glob2regpat_spec.lua diff --git a/test/functional/legacy/glob2regpat_spec.lua b/test/functional/legacy/glob2regpat_spec.lua new file mode 100644 index 0000000000..373aad68a1 --- /dev/null +++ b/test/functional/legacy/glob2regpat_spec.lua @@ -0,0 +1,19 @@ +-- Tests for signs + +local helpers = require('test.functional.helpers') +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval + +describe('glob2regpat()', function() + before_each(clear) + + it('handles invalid input', function() + execute('call glob2regpat(1.33)') + helpers.feed('') + neq(nil, string.find(eval('v:errmsg'), '^E806:')) + end) + it('handles valid input', function() + eq('^foo\\.', eval("glob2regpat('foo.*')")) + eq('\\.vim$', eval("glob2regpat('*.vim')")) + end) +end) From 894fcb778e123a9986be480e94dc78b545e01ec4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 27 Jan 2016 03:26:13 -0500 Subject: [PATCH 3/4] glob2regpat(): handle empty string. --- src/nvim/eval.c | 2 +- src/nvim/fileio.c | 1 + test/functional/legacy/glob2regpat_spec.lua | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 33c584eede..25f3cbf180 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10792,7 +10792,7 @@ static void f_glob2regpat(typval_T *argvars, typval_T *rettv) char_u *pat = get_tv_string_chk(&argvars[0]); // NULL on type error rettv->v_type = VAR_STRING; - rettv->vval.v_string = (pat == NULL) + rettv->vval.v_string = (pat == NULL || *pat == NUL) ? NULL : file_pat_to_reg_pat(pat, NULL, NULL, false); } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 26376afa27..3256004153 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -7106,6 +7106,7 @@ char_u * file_pat_to_reg_pat( char *allow_dirs, // Result passed back out in here int no_bslash // Don't use a backward slash as pathsep ) + FUNC_ATTR_NONNULL_ARG(1) { const char_u *endp; char_u *reg_pat; diff --git a/test/functional/legacy/glob2regpat_spec.lua b/test/functional/legacy/glob2regpat_spec.lua index 373aad68a1..25f0ffd007 100644 --- a/test/functional/legacy/glob2regpat_spec.lua +++ b/test/functional/legacy/glob2regpat_spec.lua @@ -12,6 +12,9 @@ describe('glob2regpat()', function() helpers.feed('') neq(nil, string.find(eval('v:errmsg'), '^E806:')) end) + it('returns empty string for empty input', function() + eq('', eval("glob2regpat('')")) + end) it('handles valid input', function() eq('^foo\\.', eval("glob2regpat('foo.*')")) eq('\\.vim$', eval("glob2regpat('*.vim')")) From db77b7bc9e510f790064333473abde98e0284af1 Mon Sep 17 00:00:00 2001 From: oni-link Date: Thu, 28 Jan 2016 00:45:26 -0500 Subject: [PATCH 4/4] file_pat_to_reg_pat(): handle empty string. --- src/nvim/eval.c | 2 +- src/nvim/fileio.c | 4 ++++ test/functional/legacy/glob2regpat_spec.lua | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 25f3cbf180..33c584eede 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10792,7 +10792,7 @@ static void f_glob2regpat(typval_T *argvars, typval_T *rettv) char_u *pat = get_tv_string_chk(&argvars[0]); // NULL on type error rettv->v_type = VAR_STRING; - rettv->vval.v_string = (pat == NULL || *pat == NUL) + rettv->vval.v_string = (pat == NULL) ? NULL : file_pat_to_reg_pat(pat, NULL, NULL, false); } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 3256004153..899e338b48 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -7119,6 +7119,10 @@ char_u * file_pat_to_reg_pat( if (pat_end == NULL) pat_end = pat + STRLEN(pat); + if (pat_end == pat) { + return (char_u *)xstrdup("^$"); + } + size_t size = 2; // '^' at start, '$' at end. for (p = pat; p < pat_end; p++) { diff --git a/test/functional/legacy/glob2regpat_spec.lua b/test/functional/legacy/glob2regpat_spec.lua index 25f0ffd007..357128bcb6 100644 --- a/test/functional/legacy/glob2regpat_spec.lua +++ b/test/functional/legacy/glob2regpat_spec.lua @@ -12,8 +12,8 @@ describe('glob2regpat()', function() helpers.feed('') neq(nil, string.find(eval('v:errmsg'), '^E806:')) end) - it('returns empty string for empty input', function() - eq('', eval("glob2regpat('')")) + it('returns ^$ for empty input', function() + eq('^$', eval("glob2regpat('')")) end) it('handles valid input', function() eq('^foo\\.', eval("glob2regpat('foo.*')"))