shada: Do not allow empty keys

This commit is contained in:
ZyX
2015-08-04 08:19:01 +03:00
parent 5b3e668f3e
commit 2244db67aa
2 changed files with 25 additions and 0 deletions

View File

@@ -3345,6 +3345,13 @@ shada_read_next_item_extra_bytes:
(uint64_t) initial_fpos); \ (uint64_t) initial_fpos); \
ga_clear(&ad_ga); \ ga_clear(&ad_ga); \
goto shada_read_next_item_error; \ goto shada_read_next_item_error; \
} else if (unpacked.data.via.map.ptr[i].key.via.str.size == 0) { \
emsgu(_(RERR "Error while reading ShaDa file: " \
entry_name " entry at position %" PRIu64 " " \
"has empty key"), \
(uint64_t) initial_fpos); \
ga_clear(&ad_ga); \
goto shada_read_next_item_error; \
} \ } \
} while (0) } while (0)
#define CHECKED_KEY(entry_name, name, error_desc, tgt, condition, attr, proc) \ #define CHECKED_KEY(entry_name, name, error_desc, tgt, condition, attr, proc) \

View File

@@ -124,6 +124,12 @@ describe('ShaDa error handling', function()
eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has key which is not a string', exc_exec(sdrcmd())) eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has key which is not a string', exc_exec(sdrcmd()))
end) end)
-- sp entry is here because it causes an allocation.
it('fails on search pattern item with empty key', function()
wshada('\002\000\013\131\162sp\196\001a\162sX\192\160\000')
eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has empty key', exc_exec(sdrcmd()))
end)
it('fails on search pattern item with NIL magic key value', function() it('fails on search pattern item with NIL magic key value', function()
wshada('\002\000\009\130\162sX\192\162sm\192') wshada('\002\000\009\130\162sX\192\162sm\192')
eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sm key value which is not a boolean', exc_exec(sdrcmd())) eq('Vim(rshada):E575: Error while reading ShaDa file: search pattern entry at position 0 has sm key value which is not a boolean', exc_exec(sdrcmd()))
@@ -192,6 +198,12 @@ describe('ShaDa error handling', function()
eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has key which is not a string', exc_exec(sdrcmd())) eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has key which is not a string', exc_exec(sdrcmd()))
end) end)
-- f entry is here because it causes an allocation.
it('fails on ' .. v.name .. ' item with empty key', function()
wshada(v.mpack .. '\000\012\131\161f\196\001/\162mX\192\160\000')
eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 has empty key', exc_exec(sdrcmd()))
end)
it('fails on ' .. v.name .. ' item without f key', function() it('fails on ' .. v.name .. ' item without f key', function()
wshada(v.mpack .. '\000\008\130\162mX\192\161l\001') wshada(v.mpack .. '\000\008\130\162mX\192\161l\001')
eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 is missing file name', exc_exec(sdrcmd())) eq('Vim(rshada):E575: Error while reading ShaDa file: mark entry at position 0 is missing file name', exc_exec(sdrcmd()))
@@ -244,6 +256,12 @@ describe('ShaDa error handling', function()
eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has key which is not a string', exc_exec(sdrcmd())) eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has key which is not a string', exc_exec(sdrcmd()))
end) end)
-- rc entry is here because it causes an allocation
it('fails on register item with BIN key', function()
wshada('\005\000\014\131\162rc\145\196\001a\162rX\192\160\000')
eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has empty key', exc_exec(sdrcmd()))
end)
it('fails on register item with NIL rt key value', function() it('fails on register item with NIL rt key value', function()
wshada('\005\000\009\130\162rX\192\162rt\192') wshada('\005\000\009\130\162rX\192\162rt\192')
eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rt key value which is not an unsigned integer', exc_exec(sdrcmd())) eq('Vim(rshada):E575: Error while reading ShaDa file: register entry at position 0 has rt key value which is not an unsigned integer', exc_exec(sdrcmd()))