0
0
mirror of https://github.com/vim/vim.git synced 2025-10-06 05:44:14 -04:00

patch 8.0.0493: crash with cd command with very long argument

Problem:    Crash with cd command with very long argument.
Solution:   Check for running out of space. (Dominique pending, closes #1576)
This commit is contained in:
Bram Moolenaar
2017-03-19 21:37:13 +01:00
parent 81b9d0bd5c
commit 15618fa643
5 changed files with 58 additions and 12 deletions

View File

@@ -2096,6 +2096,7 @@ test_arglist \
test_backspace_opt \ test_backspace_opt \
test_breakindent \ test_breakindent \
test_bufwintabinfo \ test_bufwintabinfo \
test_cd \
test_cdo \ test_cdo \
test_changedtick \ test_changedtick \
test_channel \ test_channel \

View File

@@ -4636,14 +4636,24 @@ vim_findfile(void *search_ctx_arg)
/* if we have a start dir copy it in */ /* if we have a start dir copy it in */
if (!vim_isAbsName(stackp->ffs_fix_path) if (!vim_isAbsName(stackp->ffs_fix_path)
&& search_ctx->ffsc_start_dir) && search_ctx->ffsc_start_dir)
{
if (STRLEN(search_ctx->ffsc_start_dir) + 1 < MAXPATHL)
{ {
STRCPY(file_path, search_ctx->ffsc_start_dir); STRCPY(file_path, search_ctx->ffsc_start_dir);
add_pathsep(file_path); add_pathsep(file_path);
} }
else
goto fail;
}
/* append the fix part of the search path */ /* append the fix part of the search path */
if (STRLEN(file_path) + STRLEN(stackp->ffs_fix_path) + 1 < MAXPATHL)
{
STRCAT(file_path, stackp->ffs_fix_path); STRCAT(file_path, stackp->ffs_fix_path);
add_pathsep(file_path); add_pathsep(file_path);
}
else
goto fail;
#ifdef FEAT_PATH_EXTRA #ifdef FEAT_PATH_EXTRA
rest_of_wildcards = stackp->ffs_wc_path; rest_of_wildcards = stackp->ffs_wc_path;
@@ -4660,7 +4670,10 @@ vim_findfile(void *search_ctx_arg)
if (*p > 0) if (*p > 0)
{ {
(*p)--; (*p)--;
if (len + 1 < MAXPATHL)
file_path[len++] = '*'; file_path[len++] = '*';
else
goto fail;
} }
if (*p == 0) if (*p == 0)
@@ -4688,7 +4701,10 @@ vim_findfile(void *search_ctx_arg)
*/ */
while (*rest_of_wildcards while (*rest_of_wildcards
&& !vim_ispathsep(*rest_of_wildcards)) && !vim_ispathsep(*rest_of_wildcards))
if (len + 1 < MAXPATHL)
file_path[len++] = *rest_of_wildcards++; file_path[len++] = *rest_of_wildcards++;
else
goto fail;
file_path[len] = NUL; file_path[len] = NUL;
if (vim_ispathsep(*rest_of_wildcards)) if (vim_ispathsep(*rest_of_wildcards))
@@ -4749,9 +4765,15 @@ vim_findfile(void *search_ctx_arg)
/* prepare the filename to be checked for existence /* prepare the filename to be checked for existence
* below */ * below */
if (STRLEN(stackp->ffs_filearray[i]) + 1
+ STRLEN(search_ctx->ffsc_file_to_search) < MAXPATHL)
{
STRCPY(file_path, stackp->ffs_filearray[i]); STRCPY(file_path, stackp->ffs_filearray[i]);
add_pathsep(file_path); add_pathsep(file_path);
STRCAT(file_path, search_ctx->ffsc_file_to_search); STRCAT(file_path, search_ctx->ffsc_file_to_search);
}
else
goto fail;
/* /*
* Try without extra suffix and then with suffixes * Try without extra suffix and then with suffixes
@@ -4924,9 +4946,15 @@ vim_findfile(void *search_ctx_arg)
if (*search_ctx->ffsc_start_dir == 0) if (*search_ctx->ffsc_start_dir == 0)
break; break;
if (STRLEN(search_ctx->ffsc_start_dir) + 1
+ STRLEN(search_ctx->ffsc_fix_path) < MAXPATHL)
{
STRCPY(file_path, search_ctx->ffsc_start_dir); STRCPY(file_path, search_ctx->ffsc_start_dir);
add_pathsep(file_path); add_pathsep(file_path);
STRCAT(file_path, search_ctx->ffsc_fix_path); STRCAT(file_path, search_ctx->ffsc_fix_path);
}
else
goto fail;
/* create a new stack entry */ /* create a new stack entry */
sptr = ff_create_stack_element(file_path, sptr = ff_create_stack_element(file_path,
@@ -4940,6 +4968,7 @@ vim_findfile(void *search_ctx_arg)
} }
#endif #endif
fail:
vim_free(file_path); vim_free(file_path);
return NULL; return NULL;
} }

View File

@@ -3,6 +3,7 @@
set belloff=all set belloff=all
source test_assign.vim source test_assign.vim
source test_cd.vim
source test_changedtick.vim source test_changedtick.vim
source test_cursor_func.vim source test_cursor_func.vim
source test_delete.vim source test_delete.vim

13
src/testdir/test_cd.vim Normal file
View File

@@ -0,0 +1,13 @@
" Test for :cd
func Test_cd_large_path()
" This used to crash with a heap write overflow.
call assert_fails('cd ' . repeat('x', 5000), 'E472:')
endfunc
func Test_cd_up_and_down()
let path = getcwd()
cd ..
exe 'cd ' . path
call assert_equal(path, getcwd())
endfunc

View File

@@ -764,6 +764,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 */
/**/
493,
/**/ /**/
492, 492,
/**/ /**/