comparison src/misc2.c @ 11213:290f5f6a2bac v8.0.0493

patch 8.0.0493: crash with cd command with very long argument commit https://github.com/vim/vim/commit/15618fa643867cf0d9c31f327022a22dff78a0cf Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 19 21:37:13 2017 +0100 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 https://github.com/vim/vim/issues/1576)
author Christian Brabandt <cb@256bit.org>
date Sun, 19 Mar 2017 21:45:05 +0100
parents f4d1fad4ac00
children 121d29004998
comparison
equal deleted inserted replaced
11212:22a64df8374b 11213:290f5f6a2bac
4635 4635
4636 /* if we have a start dir copy it in */ 4636 /* if we have a start dir copy it in */
4637 if (!vim_isAbsName(stackp->ffs_fix_path) 4637 if (!vim_isAbsName(stackp->ffs_fix_path)
4638 && search_ctx->ffsc_start_dir) 4638 && search_ctx->ffsc_start_dir)
4639 { 4639 {
4640 STRCPY(file_path, search_ctx->ffsc_start_dir); 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;
4647 }
4648
4649 /* append the fix part of the search path */
4650 if (STRLEN(file_path) + STRLEN(stackp->ffs_fix_path) + 1 < MAXPATHL)
4651 {
4652 STRCAT(file_path, stackp->ffs_fix_path);
4641 add_pathsep(file_path); 4653 add_pathsep(file_path);
4642 } 4654 }
4643 4655 else
4644 /* append the fix part of the search path */ 4656 goto fail;
4645 STRCAT(file_path, stackp->ffs_fix_path);
4646 add_pathsep(file_path);
4647 4657
4648 #ifdef FEAT_PATH_EXTRA 4658 #ifdef FEAT_PATH_EXTRA
4649 rest_of_wildcards = stackp->ffs_wc_path; 4659 rest_of_wildcards = stackp->ffs_wc_path;
4650 if (*rest_of_wildcards != NUL) 4660 if (*rest_of_wildcards != NUL)
4651 { 4661 {
4658 p = rest_of_wildcards + 2; 4668 p = rest_of_wildcards + 2;
4659 4669
4660 if (*p > 0) 4670 if (*p > 0)
4661 { 4671 {
4662 (*p)--; 4672 (*p)--;
4663 file_path[len++] = '*'; 4673 if (len + 1 < MAXPATHL)
4674 file_path[len++] = '*';
4675 else
4676 goto fail;
4664 } 4677 }
4665 4678
4666 if (*p == 0) 4679 if (*p == 0)
4667 { 4680 {
4668 /* remove '**<numb> from wildcards */ 4681 /* remove '**<numb> from wildcards */
4686 * pushing every directory returned from expand_wildcards() 4699 * pushing every directory returned from expand_wildcards()
4687 * on the stack again for further search. 4700 * on the stack again for further search.
4688 */ 4701 */
4689 while (*rest_of_wildcards 4702 while (*rest_of_wildcards
4690 && !vim_ispathsep(*rest_of_wildcards)) 4703 && !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;
4692 4708
4693 file_path[len] = NUL; 4709 file_path[len] = NUL;
4694 if (vim_ispathsep(*rest_of_wildcards)) 4710 if (vim_ispathsep(*rest_of_wildcards))
4695 rest_of_wildcards++; 4711 rest_of_wildcards++;
4696 } 4712 }
4747 && !mch_isdir(stackp->ffs_filearray[i])) 4763 && !mch_isdir(stackp->ffs_filearray[i]))
4748 continue; /* not a directory */ 4764 continue; /* not a directory */
4749 4765
4750 /* prepare the filename to be checked for existence 4766 /* prepare the filename to be checked for existence
4751 * below */ 4767 * below */
4752 STRCPY(file_path, stackp->ffs_filearray[i]); 4768 if (STRLEN(stackp->ffs_filearray[i]) + 1
4753 add_pathsep(file_path); 4769 + STRLEN(search_ctx->ffsc_file_to_search) < MAXPATHL)
4754 STRCAT(file_path, search_ctx->ffsc_file_to_search); 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;
4755 4777
4756 /* 4778 /*
4757 * Try without extra suffix and then with suffixes 4779 * Try without extra suffix and then with suffixes
4758 * from 'suffixesadd'. 4780 * from 'suffixesadd'.
4759 */ 4781 */
4922 path_end--; 4944 path_end--;
4923 4945
4924 if (*search_ctx->ffsc_start_dir == 0) 4946 if (*search_ctx->ffsc_start_dir == 0)
4925 break; 4947 break;
4926 4948
4927 STRCPY(file_path, search_ctx->ffsc_start_dir); 4949 if (STRLEN(search_ctx->ffsc_start_dir) + 1
4928 add_pathsep(file_path); 4950 + STRLEN(search_ctx->ffsc_fix_path) < MAXPATHL)
4929 STRCAT(file_path, search_ctx->ffsc_fix_path); 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;
4930 4958
4931 /* create a new stack entry */ 4959 /* create a new stack entry */
4932 sptr = ff_create_stack_element(file_path, 4960 sptr = ff_create_stack_element(file_path,
4933 search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); 4961 search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0);
4934 if (sptr == NULL) 4962 if (sptr == NULL)
4938 else 4966 else
4939 break; 4967 break;
4940 } 4968 }
4941 #endif 4969 #endif
4942 4970
4971 fail:
4943 vim_free(file_path); 4972 vim_free(file_path);
4944 return NULL; 4973 return NULL;
4945 } 4974 }
4946 4975
4947 /* 4976 /*