mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	shada: Fix non-writeable ShaDa directory handling
Before this change,
    nvim -i /etc/shada
segfaults on exit if the file does not exist and user does not have
permissions to create the file at /etc/shada.
Closes #5296
Reported in #5277
https://github.com/neovim/neovim/issues/5277#issuecomment-243937255
			
			
This commit is contained in:
		| @@ -2976,7 +2976,7 @@ shada_write_file_nomerge: {} | |||||||
|   if (sd_writer.cookie == NULL) { |   if (sd_writer.cookie == NULL) { | ||||||
|     xfree(fname); |     xfree(fname); | ||||||
|     xfree(tempname); |     xfree(tempname); | ||||||
|     if (sd_reader.close != NULL) { |     if (sd_reader.cookie != NULL) { | ||||||
|       sd_reader.close(&sd_reader); |       sd_reader.close(&sd_reader); | ||||||
|     } |     } | ||||||
|     return FAIL; |     return FAIL; | ||||||
|   | |||||||
| @@ -8,8 +8,8 @@ local mpack = require('mpack') | |||||||
| local tmpname = helpers.tmpname() | local tmpname = helpers.tmpname() | ||||||
| local additional_cmd = '' | local additional_cmd = '' | ||||||
|  |  | ||||||
| local function nvim_argv() | local function nvim_argv(shada_file) | ||||||
|   local argv = {nvim_prog, '-u', 'NONE', '-i', tmpname, '-N', |   local argv = {nvim_prog, '-u', 'NONE', '-i', shada_file or tmpname, '-N', | ||||||
|                 '--cmd', 'set shortmess+=I background=light noswapfile', |                 '--cmd', 'set shortmess+=I background=light noswapfile', | ||||||
|                 '--cmd', additional_cmd, |                 '--cmd', additional_cmd, | ||||||
|                 '--embed'} |                 '--embed'} | ||||||
| @@ -20,8 +20,8 @@ local function nvim_argv() | |||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
| local reset = function() | local reset = function(shada_file) | ||||||
|   set_session(spawn(nvim_argv())) |   set_session(spawn(nvim_argv(shada_file))) | ||||||
|   meths.set_var('tmpname', tmpname) |   meths.set_var('tmpname', tmpname) | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ local meths, nvim_command, funcs, eq = | |||||||
| local write_file, spawn, set_session, nvim_prog, exc_exec = | local write_file, spawn, set_session, nvim_prog, exc_exec = | ||||||
|   helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, |   helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog, | ||||||
|   helpers.exc_exec |   helpers.exc_exec | ||||||
|  |  | ||||||
| local lfs = require('lfs') | local lfs = require('lfs') | ||||||
| local paths = require('test.config.paths') | local paths = require('test.config.paths') | ||||||
|  |  | ||||||
| @@ -14,10 +15,14 @@ local shada_helpers = require('test.functional.shada.helpers') | |||||||
| local reset, clear, get_shada_rw = | local reset, clear, get_shada_rw = | ||||||
|   shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw |   shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw | ||||||
| local read_shada_file = shada_helpers.read_shada_file | local read_shada_file = shada_helpers.read_shada_file | ||||||
|  | local set_additional_cmd = shada_helpers.set_additional_cmd | ||||||
|  |  | ||||||
| local wshada, _, shada_fname, clean = | local wshada, _, shada_fname, clean = | ||||||
|   get_shada_rw('Xtest-functional-shada-shada.shada') |   get_shada_rw('Xtest-functional-shada-shada.shada') | ||||||
|  |  | ||||||
|  | local dirname = 'Xtest-functional-shada-shada.d' | ||||||
|  | local dirshada = dirname .. '/main.shada' | ||||||
|  |  | ||||||
| if helpers.pending_win32(pending) then return end | if helpers.pending_win32(pending) then return end | ||||||
|  |  | ||||||
| describe('ShaDa support code', function() | describe('ShaDa support code', function() | ||||||
| @@ -25,6 +30,7 @@ describe('ShaDa support code', function() | |||||||
|   after_each(function() |   after_each(function() | ||||||
|     clear() |     clear() | ||||||
|     clean() |     clean() | ||||||
|  |     lfs.rmdir(dirname) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|   it('preserves `s` item size limit with unknown entries', function() |   it('preserves `s` item size limit with unknown entries', function() | ||||||
| @@ -232,4 +238,17 @@ describe('ShaDa support code', function() | |||||||
|     eq('', meths.get_option('viminfo')) |     eq('', meths.get_option('viminfo')) | ||||||
|     eq('', meths.get_option('shada')) |     eq('', meths.get_option('shada')) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|  |   it('does not crash when ShaDa file directory is not writable', function() | ||||||
|  |     funcs.mkdir(dirname, '', 0) | ||||||
|  |     eq(0, funcs.filewritable(dirname)) | ||||||
|  |     set_additional_cmd('set shada=') | ||||||
|  |     reset(dirshada) | ||||||
|  |     meths.set_option('shada', '\'10') | ||||||
|  |     eq('Vim(wshada):E886: System error while opening ShaDa file ' | ||||||
|  |        .. 'Xtest-functional-shada-shada.d/main.shada for reading to merge ' | ||||||
|  |        .. 'before writing it: permission denied', | ||||||
|  |        exc_exec('wshada')) | ||||||
|  |     meths.set_option('shada', '') | ||||||
|  |   end) | ||||||
| end) | end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 ZyX
					ZyX