Mercurial > vim
comparison src/vim9compile.c @ 21979:a98211c3e14e v8.2.1539
patch 8.2.1539: using invalid script ID causes a crash
Commit: https://github.com/vim/vim/commit/e3d4685f1f716e0c516332101d85e0930f20fc59
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 29 13:39:17 2020 +0200
patch 8.2.1539: using invalid script ID causes a crash
Problem: Using invalid script ID causes a crash.
Solution: Check the script ID to be valid. (closes https://github.com/vim/vim/issues/6804)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 29 Aug 2020 13:45:03 +0200 |
parents | bf956766afa8 |
children | a9e60176dcd3 |
comparison
equal
deleted
inserted
replaced
21978:3c923f3b100f | 21979:a98211c3e14e |
---|---|
1659 dictitem_T *di; | 1659 dictitem_T *di; |
1660 scriptitem_T *si = SCRIPT_ITEM(sid); | 1660 scriptitem_T *si = SCRIPT_ITEM(sid); |
1661 int idx; | 1661 int idx; |
1662 | 1662 |
1663 // First look the name up in the hashtable. | 1663 // First look the name up in the hashtable. |
1664 if (sid <= 0 || sid > script_items.ga_len) | 1664 if (!SCRIPT_ID_VALID(sid)) |
1665 return -1; | 1665 return -1; |
1666 ht = &SCRIPT_VARS(sid); | 1666 ht = &SCRIPT_VARS(sid); |
1667 di = find_var_in_ht(ht, 0, name, TRUE); | 1667 di = find_var_in_ht(ht, 0, name, TRUE); |
1668 if (di == NULL) | 1668 if (di == NULL) |
1669 return -2; | 1669 return -2; |
1690 imported_T * | 1690 imported_T * |
1691 find_imported(char_u *name, size_t len, cctx_T *cctx) | 1691 find_imported(char_u *name, size_t len, cctx_T *cctx) |
1692 { | 1692 { |
1693 int idx; | 1693 int idx; |
1694 | 1694 |
1695 if (current_sctx.sc_sid <= 0) | 1695 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
1696 return NULL; | 1696 return NULL; |
1697 if (cctx != NULL) | 1697 if (cctx != NULL) |
1698 for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx) | 1698 for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx) |
1699 { | 1699 { |
1700 imported_T *import = ((imported_T *)cctx->ctx_imports.ga_data) | 1700 imported_T *import = ((imported_T *)cctx->ctx_imports.ga_data) |
1710 } | 1710 } |
1711 | 1711 |
1712 imported_T * | 1712 imported_T * |
1713 find_imported_in_script(char_u *name, size_t len, int sid) | 1713 find_imported_in_script(char_u *name, size_t len, int sid) |
1714 { | 1714 { |
1715 scriptitem_T *si = SCRIPT_ITEM(sid); | 1715 scriptitem_T *si; |
1716 int idx; | 1716 int idx; |
1717 | 1717 |
1718 if (!SCRIPT_ID_VALID(sid)) | |
1719 return NULL; | |
1720 si = SCRIPT_ITEM(sid); | |
1718 for (idx = 0; idx < si->sn_imports.ga_len; ++idx) | 1721 for (idx = 0; idx < si->sn_imports.ga_len; ++idx) |
1719 { | 1722 { |
1720 imported_T *import = ((imported_T *)si->sn_imports.ga_data) + idx; | 1723 imported_T *import = ((imported_T *)si->sn_imports.ga_data) + idx; |
1721 | 1724 |
1722 if (len == 0 ? STRCMP(name, import->imp_name) == 0 | 1725 if (len == 0 ? STRCMP(name, import->imp_name) == 0 |
1964 char_u *name, // variable NUL terminated | 1967 char_u *name, // variable NUL terminated |
1965 char_u *start, // start of variable | 1968 char_u *start, // start of variable |
1966 char_u **end, // end of variable | 1969 char_u **end, // end of variable |
1967 int error) // when TRUE may give error | 1970 int error) // when TRUE may give error |
1968 { | 1971 { |
1969 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); | 1972 scriptitem_T *si; |
1970 int idx = get_script_item_idx(current_sctx.sc_sid, name, FALSE); | 1973 int idx; |
1971 imported_T *import; | 1974 imported_T *import; |
1972 | 1975 |
1976 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) | |
1977 return FAIL; | |
1978 si = SCRIPT_ITEM(current_sctx.sc_sid); | |
1979 idx = get_script_item_idx(current_sctx.sc_sid, name, FALSE); | |
1973 if (idx == -1 || si->sn_version != SCRIPT_VERSION_VIM9) | 1980 if (idx == -1 || si->sn_version != SCRIPT_VERSION_VIM9) |
1974 { | 1981 { |
1975 // variable is not in sn_var_vals: old style script. | 1982 // variable is not in sn_var_vals: old style script. |
1976 return generate_OLDSCRIPT(cctx, ISN_LOADS, name, current_sctx.sc_sid, | 1983 return generate_OLDSCRIPT(cctx, ISN_LOADS, name, current_sctx.sc_sid, |
1977 &t_any); | 1984 &t_any); |
4748 | 4755 |
4749 // existing script-local variables should have a type | 4756 // existing script-local variables should have a type |
4750 scriptvar_sid = current_sctx.sc_sid; | 4757 scriptvar_sid = current_sctx.sc_sid; |
4751 if (import != NULL) | 4758 if (import != NULL) |
4752 scriptvar_sid = import->imp_sid; | 4759 scriptvar_sid = import->imp_sid; |
4753 scriptvar_idx = get_script_item_idx(scriptvar_sid, | 4760 if (SCRIPT_ID_VALID(scriptvar_sid)) |
4761 { | |
4762 scriptvar_idx = get_script_item_idx(scriptvar_sid, | |
4754 rawname, TRUE); | 4763 rawname, TRUE); |
4755 if (scriptvar_idx >= 0) | 4764 if (scriptvar_idx > 0) |
4756 { | 4765 { |
4757 scriptitem_T *si = SCRIPT_ITEM(scriptvar_sid); | 4766 scriptitem_T *si = SCRIPT_ITEM(scriptvar_sid); |
4758 svar_T *sv = | 4767 svar_T *sv = |
4759 ((svar_T *)si->sn_var_vals.ga_data) | 4768 ((svar_T *)si->sn_var_vals.ga_data) |
4760 + scriptvar_idx; | 4769 + scriptvar_idx; |
4761 type = sv->sv_type; | 4770 type = sv->sv_type; |
4771 } | |
4762 } | 4772 } |
4763 } | 4773 } |
4764 else if (name[1] == ':' && name[2] != NUL) | 4774 else if (name[1] == ':' && name[2] != NUL) |
4765 { | 4775 { |
4766 semsg(_(e_cannot_use_namespaced_variable), name); | 4776 semsg(_(e_cannot_use_namespaced_variable), name); |