@@ -4637,13 +4637,23 @@ vim_findfile(void *search_ctx_arg)
46374637 if (!vim_isAbsName (stackp -> ffs_fix_path )
46384638 && search_ctx -> ffsc_start_dir )
46394639 {
4640- STRCPY (file_path , search_ctx -> ffsc_start_dir );
4641- add_pathsep (file_path );
4640+ if (STRLEN (search_ctx -> ffsc_start_dir ) + 1 < MAXPATHL )
4641+ {
4642+ STRCPY (file_path , search_ctx -> ffsc_start_dir );
4643+ add_pathsep (file_path );
4644+ }
4645+ else
4646+ goto fail ;
46424647 }
46434648
46444649 /* append the fix part of the search path */
4645- STRCAT (file_path , stackp -> ffs_fix_path );
4646- add_pathsep (file_path );
4650+ if (STRLEN (file_path ) + STRLEN (stackp -> ffs_fix_path ) + 1 < MAXPATHL )
4651+ {
4652+ STRCAT (file_path , stackp -> ffs_fix_path );
4653+ add_pathsep (file_path );
4654+ }
4655+ else
4656+ goto fail ;
46474657
46484658#ifdef FEAT_PATH_EXTRA
46494659 rest_of_wildcards = stackp -> ffs_wc_path ;
@@ -4660,7 +4670,10 @@ vim_findfile(void *search_ctx_arg)
46604670 if (* p > 0 )
46614671 {
46624672 (* p )-- ;
4663- file_path [len ++ ] = '*' ;
4673+ if (len + 1 < MAXPATHL )
4674+ file_path [len ++ ] = '*' ;
4675+ else
4676+ goto fail ;
46644677 }
46654678
46664679 if (* p == 0 )
@@ -4688,7 +4701,10 @@ vim_findfile(void *search_ctx_arg)
46884701 */
46894702 while (* rest_of_wildcards
46904703 && !vim_ispathsep (* rest_of_wildcards ))
4691- file_path [len ++ ] = * rest_of_wildcards ++ ;
4704+ if (len + 1 < MAXPATHL )
4705+ file_path [len ++ ] = * rest_of_wildcards ++ ;
4706+ else
4707+ goto fail ;
46924708
46934709 file_path [len ] = NUL ;
46944710 if (vim_ispathsep (* rest_of_wildcards ))
@@ -4749,9 +4765,15 @@ vim_findfile(void *search_ctx_arg)
47494765
47504766 /* prepare the filename to be checked for existence
47514767 * below */
4752- STRCPY (file_path , stackp -> ffs_filearray [i ]);
4753- add_pathsep (file_path );
4754- STRCAT (file_path , search_ctx -> ffsc_file_to_search );
4768+ if (STRLEN (stackp -> ffs_filearray [i ]) + 1
4769+ + STRLEN (search_ctx -> ffsc_file_to_search ) < MAXPATHL )
4770+ {
4771+ STRCPY (file_path , stackp -> ffs_filearray [i ]);
4772+ add_pathsep (file_path );
4773+ STRCAT (file_path , search_ctx -> ffsc_file_to_search );
4774+ }
4775+ else
4776+ goto fail ;
47554777
47564778 /*
47574779 * Try without extra suffix and then with suffixes
@@ -4924,9 +4946,15 @@ vim_findfile(void *search_ctx_arg)
49244946 if (* search_ctx -> ffsc_start_dir == 0 )
49254947 break ;
49264948
4927- STRCPY (file_path , search_ctx -> ffsc_start_dir );
4928- add_pathsep (file_path );
4929- STRCAT (file_path , search_ctx -> ffsc_fix_path );
4949+ if (STRLEN (search_ctx -> ffsc_start_dir ) + 1
4950+ + STRLEN (search_ctx -> ffsc_fix_path ) < MAXPATHL )
4951+ {
4952+ STRCPY (file_path , search_ctx -> ffsc_start_dir );
4953+ add_pathsep (file_path );
4954+ STRCAT (file_path , search_ctx -> ffsc_fix_path );
4955+ }
4956+ else
4957+ goto fail ;
49304958
49314959 /* create a new stack entry */
49324960 sptr = ff_create_stack_element (file_path ,
@@ -4940,6 +4968,7 @@ vim_findfile(void *search_ctx_arg)
49404968 }
49414969#endif
49424970
4971+ fail :
49434972 vim_free (file_path );
49444973 return NULL ;
49454974}
0 commit comments