aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-04-09 20:55:48 +0300
committerZyX <kp-pav@yandex.ru>2017-04-09 22:02:36 +0300
commit8d982ab52269e8adccbc21cc0d6f8ab3b817bf6e (patch)
tree96bc1b084ae8dd1881e2b26adde7249b890755b4 /test/functional
parentdbdd69e418a3baa4750abc25fae7516a36776e75 (diff)
downloadrneovim-8d982ab52269e8adccbc21cc0d6f8ab3b817bf6e.tar.gz
rneovim-8d982ab52269e8adccbc21cc0d6f8ab3b817bf6e.tar.bz2
rneovim-8d982ab52269e8adccbc21cc0d6f8ab3b817bf6e.zip
coverity/13686: Do not allow NUL byte in precondition regex
Before this commit it emitted e_spell_trunc in the first case and treated file as completely valid on the second. While first is fine (both errors are actually valid, though old error is probably better), second results in incorrect regex used.
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/spell/spellfile_spec.lua61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/functional/spell/spellfile_spec.lua b/test/functional/spell/spellfile_spec.lua
new file mode 100644
index 0000000000..88f757249e
--- /dev/null
+++ b/test/functional/spell/spellfile_spec.lua
@@ -0,0 +1,61 @@
+local helpers = require('test.functional.helpers')(after_each)
+local lfs = require('lfs')
+
+local eq = helpers.eq
+local clear = helpers.clear
+local meths = helpers.meths
+local exc_exec = helpers.exc_exec
+local write_file = helpers.write_file
+
+local testdir = 'Xtest-functional-spell-spellfile.d'
+
+describe('spellfile', function()
+ before_each(function()
+ clear()
+ lfs.mkdir(testdir)
+ lfs.mkdir(testdir .. '/spell')
+ end)
+ after_each(function()
+ lfs.rmdir(testdir)
+ end)
+ -- ┌ Magic string (#VIMSPELLMAGIC)
+ -- │ ┌ Spell file version (#VIMSPELLVERSION)
+ local spellheader = 'VIMspell\050'
+ it('errors out when prefcond section is truncated', function()
+ meths.set_option('runtimepath', testdir)
+ write_file(testdir .. '/spell/en.ascii.spl',
+ -- ┌ Section identifier (#SN_PREFCOND)
+ -- │ ┌ Section flags (#SNF_REQUIRED or zero)
+ -- │ │ ┌ Section length (4 bytes, MSB first)
+ -- │ │ │
+ spellheader .. '\003\001\000\000\000\003'
+ -- ┌ Number of regexes in section (2 bytes, MSB first)
+ -- │ ┌ Condition length (1 byte)
+ -- │ │ ┌ Condition regex (missing!)
+ .. '\000\001\001')
+ meths.set_option('spelllang', 'en')
+ eq('Vim(set):E759: Format error in spell file',
+ exc_exec('set spell'))
+ end)
+ it('errors out when prefcond regexp contains NUL byte', function()
+ meths.set_option('runtimepath', testdir)
+ write_file(testdir .. '/spell/en.ascii.spl',
+ -- ┌ Section identifier (#SN_PREFCOND)
+ -- │ ┌ Section flags (#SNF_REQUIRED or zero)
+ -- │ │ ┌ Section length (4 bytes, MSB first)
+ -- │ │ │
+ spellheader .. '\003\001\000\000\000\008'
+ -- ┌ Number of regexes in section (2 bytes, MSB first)
+ -- │ ┌ Condition length (1 byte)
+ -- │ │ ┌ Condition regex
+ -- │ │ │ ┌ End of sections marker
+ .. '\000\001\005ab\000cd\255'
+ -- ┌ LWORDTREE tree length (4 bytes)
+ -- │ ┌ KWORDTREE tree length (4 bytes)
+ -- │ │ ┌ PREFIXTREE tree length
+ .. '\000\000\000\000\000\000\000\000\000\000\000\000')
+ meths.set_option('spelllang', 'en')
+ eq('Vim(set):E759: Format error in spell file',
+ exc_exec('set spell'))
+ end)
+end)