0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.1.1097: --log with non-existent path causes a crash

Problem:  --log with non-existent path causes a crash
          (Ekkosun)
Solution: split initialization phase and init the execution stack
          earlier (Hirohito Higashi)

fixes: #16606
closes: #16610

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Hirohito Higashi
2025-02-10 20:55:17 +01:00
committed by Christian Brabandt
parent 97baa1cfe8
commit c5654b8448
5 changed files with 30 additions and 6 deletions

View File

@@ -144,6 +144,11 @@ main
atexit(vim_mem_profile_dump); atexit(vim_mem_profile_dump);
#endif #endif
/*
* Various initialisations #1 shared with tests.
*/
common_init_1();
#if defined(STARTUPTIME) || defined(FEAT_JOB_CHANNEL) #if defined(STARTUPTIME) || defined(FEAT_JOB_CHANNEL)
// Need to find "--startuptime" and "--log" before actually parsing // Need to find "--startuptime" and "--log" before actually parsing
// arguments. // arguments.
@@ -185,9 +190,9 @@ main
#endif #endif
/* /*
* Various initialisations shared with tests. * Various initialisations #2 shared with tests.
*/ */
common_init(&params); common_init_2(&params);
#ifdef VIMDLL #ifdef VIMDLL
// Check if the current executable file is for the GUI subsystem. // Check if the current executable file is for the GUI subsystem.
@@ -900,10 +905,10 @@ vim_main2(void)
} }
/* /*
* Initialisation shared by main() and some tests. * Initialisation #1 shared by main() and some tests.
*/ */
void void
common_init(mparm_T *paramp) common_init_1(void)
{ {
estack_init(); estack_init();
cmdline_init(); cmdline_init();
@@ -925,7 +930,15 @@ common_init(mparm_T *paramp)
|| (NameBuff = alloc(MAXPATHL)) == NULL) || (NameBuff = alloc(MAXPATHL)) == NULL)
mch_exit(0); mch_exit(0);
TIME_MSG("Allocated generic buffers"); TIME_MSG("Allocated generic buffers");
}
/*
* Initialisation #2 shared by main() and some tests.
*/
void
common_init_2(mparm_T *paramp)
{
#ifdef NBDEBUG #ifdef NBDEBUG
// Wait a moment for debugging NetBeans. Must be after allocating // Wait a moment for debugging NetBeans. Must be after allocating
// NameBuff. // NameBuff.

View File

@@ -508,7 +508,8 @@ main(int argc, char **argv)
CLEAR_FIELD(params); CLEAR_FIELD(params);
params.argc = argc; params.argc = argc;
params.argv = argv; params.argv = argv;
common_init(&params); common_init_1();
common_init_2(&params);
set_option_value_give_err((char_u *)"encoding", 0, (char_u *)"utf-8", 0); set_option_value_give_err((char_u *)"encoding", 0, (char_u *)"utf-8", 0);
init_chartab(); init_chartab();

View File

@@ -1,6 +1,7 @@
/* main.c */ /* main.c */
int vim_main2(void); int vim_main2(void);
void common_init(mparm_T *paramp); void common_init_1(void);
void common_init_2(mparm_T *paramp);
int is_not_a_term(void); int is_not_a_term(void);
int is_not_a_term_or_gui(void); int is_not_a_term_or_gui(void);
void free_vbuf(void); void free_vbuf(void);

View File

@@ -740,6 +740,13 @@ func Test_log()
call delete('Xlogfile') call delete('Xlogfile')
endfunc endfunc
func Test_log_nonexistent()
" this used to crash Vim
CheckFeature channel
let result = join(systemlist(GetVimCommand() .. ' --log /X/Xlogfile -c qa!'))
call assert_match("E484: Can't open file", result)
endfunc
func Test_read_stdin() func Test_read_stdin()
let after =<< trim [CODE] let after =<< trim [CODE]
write Xtestout write Xtestout

View File

@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1097,
/**/ /**/
1096, 1096,
/**/ /**/