cve_id
stringlengths 13
16
| obtain_all_privilege
stringclasses 3
values | obtain_user_privilege
stringclasses 2
values | obtain_other_privilege
stringclasses 2
values | user_interaction_required
stringclasses 3
values | cvss2_vector_string
stringclasses 106
values | cvss2_access_vector
stringclasses 4
values | cvss2_access_complexity
stringclasses 4
values | cvss2_authentication
stringclasses 3
values | cvss2_confidentiality_impact
stringclasses 4
values | cvss2_integrity_impact
stringclasses 4
values | cvss2_availability_impact
stringclasses 4
values | cvss2_base_score
stringclasses 50
values | cvss3_vector_string
stringclasses 226
values | cvss3_attack_vector
stringclasses 5
values | cvss3_attack_complexity
stringclasses 3
values | cvss3_privileges_required
stringclasses 4
values | cvss3_user_interaction
stringclasses 3
values | cvss3_scope
stringclasses 3
values | cvss3_confidentiality_impact
stringclasses 4
values | cvss3_integrity_impact
stringclasses 4
values | cvss3_availability_impact
stringclasses 4
values | cvss3_base_score
stringclasses 55
values | cvss3_base_severity
stringclasses 5
values | exploitability_score
stringclasses 22
values | impact_score
stringclasses 15
values | ac_insuf_info
stringclasses 3
values | reference_json
stringlengths 221
23.3k
| problemtype_json
stringclasses 200
values | severity
stringclasses 4
values | cve_nodes
stringlengths 2
33.1k
| cve_description
stringlengths 64
1.99k
| cve_last_modified_date
stringlengths 17
17
| cve_published_date
stringlengths 17
17
| cwe_name
stringclasses 125
values | cwe_description
stringclasses 124
values | cwe_extended_description
stringclasses 95
values | cwe_url
stringclasses 124
values | cwe_is_category
int64 0
1
| commit_author
stringlengths 0
34
| commit_author_date
stringlengths 25
25
| commit_msg
stringlengths 0
13.3k
| commit_hash
stringlengths 40
40
| commit_is_merge
stringclasses 1
value | repo_name
stringclasses 467
values | repo_description
stringclasses 459
values | repo_date_created
stringclasses 467
values | repo_date_last_push
stringclasses 467
values | repo_homepage
stringclasses 294
values | repo_owner
stringclasses 470
values | repo_stars
stringclasses 406
values | repo_forks
stringclasses 352
values | function_name
stringlengths 3
120
| function_signature
stringlengths 6
640
| function_parameters
stringlengths 2
302
| function
stringlengths 12
114k
| function_token_count
stringlengths 1
5
| function_before_change
stringclasses 1
value | labels
int64 1
1
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CVE-2022-0417 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/fc86bc8d-c866-4ade-8b7f-e49cec306d1a', 'name': 'https://huntr.dev/bounties/fc86bc8d-c866-4ade-8b7f-e49cec306d1a', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/652dee448618589de5528a9e9a36995803f5557a', 'name': 'https://github.com/vim/vim/commit/652dee448618589de5528a9e9a36995803f5557a', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UFXFAILMLUIK4MBUEZO4HNBNKYZRJ5AP/', 'name': 'FEDORA-2022-da2fb07efb', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/06/msg00014.html', 'name': '[debian-lts-announce] 20220620 [SECURITY] [DLA 3053-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mitigation', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4245', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T17:35Z | 2022-02-01T13:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-01-28 20:47:49+00:00 | patch 8.2.4245: ":retab 0" may cause illegal memory access
Problem: ":retab 0" may cause illegal memory access.
Solution: Limit the value of 'tabstop' to 10000. | 652dee448618589de5528a9e9a36995803f5557a | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | buf_copy_options | buf_copy_options( buf_T * buf , int flags) | ['buf', 'flags'] | buf_copy_options(buf_T *buf, int flags)
{
int should_copy = TRUE;
char_u *save_p_isk = NULL; // init for GCC
int dont_do_help;
int did_isk = FALSE;
/*
* Skip this when the option defaults have not been set yet. Happens when
* main() allocates the first buffer.
*/
if (p_cpo != NULL)
{
/*
* Always copy when entering and 'cpo' contains 'S'.
* Don't copy when already initialized.
* Don't copy when 'cpo' contains 's' and not entering.
* 'S' BCO_ENTER initialized 's' should_copy
* yes yes X X TRUE
* yes no yes X FALSE
* no X yes X FALSE
* X no no yes FALSE
* X no no no TRUE
* no yes no X TRUE
*/
if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
&& (buf->b_p_initialized
|| (!(flags & BCO_ENTER)
&& vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
should_copy = FALSE;
if (should_copy || (flags & BCO_ALWAYS))
{
#ifdef FEAT_EVAL
CLEAR_FIELD(buf->b_p_script_ctx);
init_buf_opt_idx();
#endif
// Don't copy the options specific to a help buffer when
// BCO_NOHELP is given or the options were initialized already
// (jumping back to a help file with CTRL-T or CTRL-O)
dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
|| buf->b_p_initialized;
if (dont_do_help) // don't free b_p_isk
{
save_p_isk = buf->b_p_isk;
buf->b_p_isk = NULL;
}
/*
* Always free the allocated strings. If not already initialized,
* reset 'readonly' and copy 'fileformat'.
*/
if (!buf->b_p_initialized)
{
free_buf_options(buf, TRUE);
buf->b_p_ro = FALSE; // don't copy readonly
buf->b_p_tx = p_tx;
buf->b_p_fenc = vim_strsave(p_fenc);
switch (*p_ffs)
{
case 'm':
buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
case 'd':
buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
case 'u':
buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
default:
buf->b_p_ff = vim_strsave(p_ff);
}
if (buf->b_p_ff != NULL)
buf->b_start_ffc = *buf->b_p_ff;
buf->b_p_bh = empty_option;
buf->b_p_bt = empty_option;
}
else
free_buf_options(buf, FALSE);
buf->b_p_ai = p_ai;
COPY_OPT_SCTX(buf, BV_AI);
buf->b_p_ai_nopaste = p_ai_nopaste;
buf->b_p_sw = p_sw;
COPY_OPT_SCTX(buf, BV_SW);
buf->b_p_tw = p_tw;
COPY_OPT_SCTX(buf, BV_TW);
buf->b_p_tw_nopaste = p_tw_nopaste;
buf->b_p_tw_nobin = p_tw_nobin;
buf->b_p_wm = p_wm;
COPY_OPT_SCTX(buf, BV_WM);
buf->b_p_wm_nopaste = p_wm_nopaste;
buf->b_p_wm_nobin = p_wm_nobin;
buf->b_p_bin = p_bin;
COPY_OPT_SCTX(buf, BV_BIN);
buf->b_p_bomb = p_bomb;
COPY_OPT_SCTX(buf, BV_BOMB);
buf->b_p_fixeol = p_fixeol;
COPY_OPT_SCTX(buf, BV_FIXEOL);
buf->b_p_et = p_et;
COPY_OPT_SCTX(buf, BV_ET);
buf->b_p_et_nobin = p_et_nobin;
buf->b_p_et_nopaste = p_et_nopaste;
buf->b_p_ml = p_ml;
COPY_OPT_SCTX(buf, BV_ML);
buf->b_p_ml_nobin = p_ml_nobin;
buf->b_p_inf = p_inf;
COPY_OPT_SCTX(buf, BV_INF);
if (cmdmod.cmod_flags & CMOD_NOSWAPFILE)
buf->b_p_swf = FALSE;
else
{
buf->b_p_swf = p_swf;
COPY_OPT_SCTX(buf, BV_SWF);
}
buf->b_p_cpt = vim_strsave(p_cpt);
COPY_OPT_SCTX(buf, BV_CPT);
#ifdef BACKSLASH_IN_FILENAME
buf->b_p_csl = vim_strsave(p_csl);
COPY_OPT_SCTX(buf, BV_CSL);
#endif
#ifdef FEAT_COMPL_FUNC
buf->b_p_cfu = vim_strsave(p_cfu);
COPY_OPT_SCTX(buf, BV_CFU);
set_buflocal_cfu_callback(buf);
buf->b_p_ofu = vim_strsave(p_ofu);
COPY_OPT_SCTX(buf, BV_OFU);
set_buflocal_ofu_callback(buf);
#endif
#ifdef FEAT_EVAL
buf->b_p_tfu = vim_strsave(p_tfu);
COPY_OPT_SCTX(buf, BV_TFU);
set_buflocal_tfu_callback(buf);
#endif
buf->b_p_sts = p_sts;
COPY_OPT_SCTX(buf, BV_STS);
buf->b_p_sts_nopaste = p_sts_nopaste;
#ifdef FEAT_VARTABS
buf->b_p_vsts = vim_strsave(p_vsts);
COPY_OPT_SCTX(buf, BV_VSTS);
if (p_vsts && p_vsts != empty_option)
(void)tabstop_set(p_vsts, &buf->b_p_vsts_array);
else
buf->b_p_vsts_array = 0;
buf->b_p_vsts_nopaste = p_vsts_nopaste
? vim_strsave(p_vsts_nopaste) : NULL;
#endif
buf->b_p_sn = p_sn;
COPY_OPT_SCTX(buf, BV_SN);
buf->b_p_com = vim_strsave(p_com);
COPY_OPT_SCTX(buf, BV_COM);
#ifdef FEAT_FOLDING
buf->b_p_cms = vim_strsave(p_cms);
COPY_OPT_SCTX(buf, BV_CMS);
#endif
buf->b_p_fo = vim_strsave(p_fo);
COPY_OPT_SCTX(buf, BV_FO);
buf->b_p_flp = vim_strsave(p_flp);
COPY_OPT_SCTX(buf, BV_FLP);
// NOTE: Valgrind may report a bogus memory leak for 'nrformats'
// when it is set to 8 bytes in defaults.vim.
buf->b_p_nf = vim_strsave(p_nf);
COPY_OPT_SCTX(buf, BV_NF);
buf->b_p_mps = vim_strsave(p_mps);
COPY_OPT_SCTX(buf, BV_MPS);
#ifdef FEAT_SMARTINDENT
buf->b_p_si = p_si;
COPY_OPT_SCTX(buf, BV_SI);
#endif
buf->b_p_ci = p_ci;
COPY_OPT_SCTX(buf, BV_CI);
#ifdef FEAT_CINDENT
buf->b_p_cin = p_cin;
COPY_OPT_SCTX(buf, BV_CIN);
buf->b_p_cink = vim_strsave(p_cink);
COPY_OPT_SCTX(buf, BV_CINK);
buf->b_p_cino = vim_strsave(p_cino);
COPY_OPT_SCTX(buf, BV_CINO);
#endif
// Don't copy 'filetype', it must be detected
buf->b_p_ft = empty_option;
buf->b_p_pi = p_pi;
COPY_OPT_SCTX(buf, BV_PI);
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
buf->b_p_cinw = vim_strsave(p_cinw);
COPY_OPT_SCTX(buf, BV_CINW);
#endif
#ifdef FEAT_LISP
buf->b_p_lisp = p_lisp;
COPY_OPT_SCTX(buf, BV_LISP);
#endif
#ifdef FEAT_SYN_HL
// Don't copy 'syntax', it must be set
buf->b_p_syn = empty_option;
buf->b_p_smc = p_smc;
COPY_OPT_SCTX(buf, BV_SMC);
buf->b_s.b_syn_isk = empty_option;
#endif
#ifdef FEAT_SPELL
buf->b_s.b_p_spc = vim_strsave(p_spc);
COPY_OPT_SCTX(buf, BV_SPC);
(void)compile_cap_prog(&buf->b_s);
buf->b_s.b_p_spf = vim_strsave(p_spf);
COPY_OPT_SCTX(buf, BV_SPF);
buf->b_s.b_p_spl = vim_strsave(p_spl);
COPY_OPT_SCTX(buf, BV_SPL);
buf->b_s.b_p_spo = vim_strsave(p_spo);
COPY_OPT_SCTX(buf, BV_SPO);
#endif
#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
buf->b_p_inde = vim_strsave(p_inde);
COPY_OPT_SCTX(buf, BV_INDE);
buf->b_p_indk = vim_strsave(p_indk);
COPY_OPT_SCTX(buf, BV_INDK);
#endif
buf->b_p_fp = empty_option;
#if defined(FEAT_EVAL)
buf->b_p_fex = vim_strsave(p_fex);
COPY_OPT_SCTX(buf, BV_FEX);
#endif
#ifdef FEAT_CRYPT
buf->b_p_key = vim_strsave(p_key);
COPY_OPT_SCTX(buf, BV_KEY);
#endif
#ifdef FEAT_SEARCHPATH
buf->b_p_sua = vim_strsave(p_sua);
COPY_OPT_SCTX(buf, BV_SUA);
#endif
#ifdef FEAT_KEYMAP
buf->b_p_keymap = vim_strsave(p_keymap);
COPY_OPT_SCTX(buf, BV_KMAP);
buf->b_kmap_state |= KEYMAP_INIT;
#endif
#ifdef FEAT_TERMINAL
buf->b_p_twsl = p_twsl;
COPY_OPT_SCTX(buf, BV_TWSL);
#endif
// This isn't really an option, but copying the langmap and IME
// state from the current buffer is better than resetting it.
buf->b_p_iminsert = p_iminsert;
COPY_OPT_SCTX(buf, BV_IMI);
buf->b_p_imsearch = p_imsearch;
COPY_OPT_SCTX(buf, BV_IMS);
// options that are normally global but also have a local value
// are not copied, start using the global value
buf->b_p_ar = -1;
buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
buf->b_p_bkc = empty_option;
buf->b_bkc_flags = 0;
#ifdef FEAT_QUICKFIX
buf->b_p_gp = empty_option;
buf->b_p_mp = empty_option;
buf->b_p_efm = empty_option;
#endif
buf->b_p_ep = empty_option;
buf->b_p_kp = empty_option;
buf->b_p_path = empty_option;
buf->b_p_tags = empty_option;
buf->b_p_tc = empty_option;
buf->b_tc_flags = 0;
#ifdef FEAT_FIND_ID
buf->b_p_def = empty_option;
buf->b_p_inc = empty_option;
# ifdef FEAT_EVAL
buf->b_p_inex = vim_strsave(p_inex);
COPY_OPT_SCTX(buf, BV_INEX);
# endif
#endif
buf->b_p_dict = empty_option;
buf->b_p_tsr = empty_option;
#ifdef FEAT_COMPL_FUNC
buf->b_p_tsrfu = empty_option;
#endif
#ifdef FEAT_TEXTOBJ
buf->b_p_qe = vim_strsave(p_qe);
COPY_OPT_SCTX(buf, BV_QE);
#endif
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
buf->b_p_bexpr = empty_option;
#endif
#if defined(FEAT_CRYPT)
buf->b_p_cm = empty_option;
#endif
#ifdef FEAT_PERSISTENT_UNDO
buf->b_p_udf = p_udf;
COPY_OPT_SCTX(buf, BV_UDF);
#endif
#ifdef FEAT_LISP
buf->b_p_lw = empty_option;
#endif
buf->b_p_menc = empty_option;
/*
* Don't copy the options set by ex_help(), use the saved values,
* when going from a help buffer to a non-help buffer.
* Don't touch these at all when BCO_NOHELP is used and going from
* or to a help buffer.
*/
if (dont_do_help)
{
buf->b_p_isk = save_p_isk;
#ifdef FEAT_VARTABS
if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
(void)tabstop_set(p_vts, &buf->b_p_vts_array);
else
buf->b_p_vts_array = NULL;
#endif
}
else
{
buf->b_p_isk = vim_strsave(p_isk);
COPY_OPT_SCTX(buf, BV_ISK);
did_isk = TRUE;
buf->b_p_ts = p_ts;
COPY_OPT_SCTX(buf, BV_TS);
#ifdef FEAT_VARTABS
buf->b_p_vts = vim_strsave(p_vts);
COPY_OPT_SCTX(buf, BV_VTS);
if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
(void)tabstop_set(p_vts, &buf->b_p_vts_array);
else
buf->b_p_vts_array = NULL;
#endif
buf->b_help = FALSE;
if (buf->b_p_bt[0] == 'h')
clear_string_option(&buf->b_p_bt);
buf->b_p_ma = p_ma;
COPY_OPT_SCTX(buf, BV_MA);
}
}
/*
* When the options should be copied (ignoring BCO_ALWAYS), set the
* flag that indicates that the options have been initialized.
*/
if (should_copy)
buf->b_p_initialized = TRUE;
}
check_buf_options(buf); // make sure we don't have NULLs
if (did_isk)
(void)buf_init_chartab(buf, FALSE);
} | 1530 | True | 1 |
|
CVE-2022-0417 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/fc86bc8d-c866-4ade-8b7f-e49cec306d1a', 'name': 'https://huntr.dev/bounties/fc86bc8d-c866-4ade-8b7f-e49cec306d1a', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/652dee448618589de5528a9e9a36995803f5557a', 'name': 'https://github.com/vim/vim/commit/652dee448618589de5528a9e9a36995803f5557a', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UFXFAILMLUIK4MBUEZO4HNBNKYZRJ5AP/', 'name': 'FEDORA-2022-da2fb07efb', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/06/msg00014.html', 'name': '[debian-lts-announce] 20220620 [SECURITY] [DLA 3053-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mitigation', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4245', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T17:35Z | 2022-02-01T13:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-01-28 20:47:49+00:00 | patch 8.2.4245: ":retab 0" may cause illegal memory access
Problem: ":retab 0" may cause illegal memory access.
Solution: Limit the value of 'tabstop' to 10000. | 652dee448618589de5528a9e9a36995803f5557a | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | paste_option_changed | paste_option_changed( void) | ['void'] | paste_option_changed(void)
{
static int old_p_paste = FALSE;
static int save_sm = 0;
static int save_sta = 0;
#ifdef FEAT_CMDL_INFO
static int save_ru = 0;
#endif
#ifdef FEAT_RIGHTLEFT
static int save_ri = 0;
static int save_hkmap = 0;
#endif
buf_T *buf;
if (p_paste)
{
/*
* Paste switched from off to on.
* Save the current values, so they can be restored later.
*/
if (!old_p_paste)
{
// save options for each buffer
FOR_ALL_BUFFERS(buf)
{
buf->b_p_tw_nopaste = buf->b_p_tw;
buf->b_p_wm_nopaste = buf->b_p_wm;
buf->b_p_sts_nopaste = buf->b_p_sts;
buf->b_p_ai_nopaste = buf->b_p_ai;
buf->b_p_et_nopaste = buf->b_p_et;
#ifdef FEAT_VARTABS
if (buf->b_p_vsts_nopaste)
vim_free(buf->b_p_vsts_nopaste);
buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
? vim_strsave(buf->b_p_vsts) : NULL;
#endif
}
// save global options
save_sm = p_sm;
save_sta = p_sta;
#ifdef FEAT_CMDL_INFO
save_ru = p_ru;
#endif
#ifdef FEAT_RIGHTLEFT
save_ri = p_ri;
save_hkmap = p_hkmap;
#endif
// save global values for local buffer options
p_ai_nopaste = p_ai;
p_et_nopaste = p_et;
p_sts_nopaste = p_sts;
p_tw_nopaste = p_tw;
p_wm_nopaste = p_wm;
#ifdef FEAT_VARTABS
if (p_vsts_nopaste)
vim_free(p_vsts_nopaste);
p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
#endif
}
/*
* Always set the option values, also when 'paste' is set when it is
* already on.
*/
// set options for each buffer
FOR_ALL_BUFFERS(buf)
{
buf->b_p_tw = 0; // textwidth is 0
buf->b_p_wm = 0; // wrapmargin is 0
buf->b_p_sts = 0; // softtabstop is 0
buf->b_p_ai = 0; // no auto-indent
buf->b_p_et = 0; // no expandtab
#ifdef FEAT_VARTABS
if (buf->b_p_vsts)
free_string_option(buf->b_p_vsts);
buf->b_p_vsts = empty_option;
if (buf->b_p_vsts_array)
vim_free(buf->b_p_vsts_array);
buf->b_p_vsts_array = 0;
#endif
}
// set global options
p_sm = 0; // no showmatch
p_sta = 0; // no smarttab
#ifdef FEAT_CMDL_INFO
if (p_ru)
status_redraw_all(); // redraw to remove the ruler
p_ru = 0; // no ruler
#endif
#ifdef FEAT_RIGHTLEFT
p_ri = 0; // no reverse insert
p_hkmap = 0; // no Hebrew keyboard
#endif
// set global values for local buffer options
p_tw = 0;
p_wm = 0;
p_sts = 0;
p_ai = 0;
#ifdef FEAT_VARTABS
if (p_vsts)
free_string_option(p_vsts);
p_vsts = empty_option;
#endif
}
/*
* Paste switched from on to off: Restore saved values.
*/
else if (old_p_paste)
{
// restore options for each buffer
FOR_ALL_BUFFERS(buf)
{
buf->b_p_tw = buf->b_p_tw_nopaste;
buf->b_p_wm = buf->b_p_wm_nopaste;
buf->b_p_sts = buf->b_p_sts_nopaste;
buf->b_p_ai = buf->b_p_ai_nopaste;
buf->b_p_et = buf->b_p_et_nopaste;
#ifdef FEAT_VARTABS
if (buf->b_p_vsts)
free_string_option(buf->b_p_vsts);
buf->b_p_vsts = buf->b_p_vsts_nopaste
? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
if (buf->b_p_vsts_array)
vim_free(buf->b_p_vsts_array);
if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
(void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
else
buf->b_p_vsts_array = 0;
#endif
}
// restore global options
p_sm = save_sm;
p_sta = save_sta;
#ifdef FEAT_CMDL_INFO
if (p_ru != save_ru)
status_redraw_all(); // redraw to draw the ruler
p_ru = save_ru;
#endif
#ifdef FEAT_RIGHTLEFT
p_ri = save_ri;
p_hkmap = save_hkmap;
#endif
// set global values for local buffer options
p_ai = p_ai_nopaste;
p_et = p_et_nopaste;
p_sts = p_sts_nopaste;
p_tw = p_tw_nopaste;
p_wm = p_wm_nopaste;
#ifdef FEAT_VARTABS
if (p_vsts)
free_string_option(p_vsts);
p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
#endif
}
old_p_paste = p_paste;
} | 540 | True | 1 |
|
CVE-2022-0408 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/5e635bad-5cf6-46cd-aeac-34ef224e179d', 'name': 'https://huntr.dev/bounties/5e635bad-5cf6-46cd-aeac-34ef224e179d', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/06f15416bb8d5636200a10776f1752c4d6e49f31', 'name': 'https://github.com/vim/vim/commit/06f15416bb8d5636200a10776f1752c4d6e49f31', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UFXFAILMLUIK4MBUEZO4HNBNKYZRJ5AP/', 'name': 'FEDORA-2022-da2fb07efb', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/03/msg00018.html', 'name': '[debian-lts-announce] 20220311 [SECURITY] [DLA 2947-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-121'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4247', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Stack-based Buffer Overflow in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T17:35Z | 2022-01-30T15:15Z | Stack-based Buffer Overflow | A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function). | https://cwe.mitre.org/data/definitions/121.html | 0 | Bram Moolenaar | 2022-01-29 10:51:59+00:00 | patch 8.2.4247: stack corruption when looking for spell suggestions
Problem: Stack corruption when looking for spell suggestions.
Solution: Prevent the depth increased too much. Add a five second time
limit to finding suggestions. | 06f15416bb8d5636200a10776f1752c4d6e49f31 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | suggest_trie_walk | suggest_trie_walk( suginfo_T * su , langp_T * lp , char_u * fword , int soundfold) | ['su', 'lp', 'fword', 'soundfold'] | suggest_trie_walk(
suginfo_T *su,
langp_T *lp,
char_u *fword,
int soundfold)
{
char_u tword[MAXWLEN]; // good word collected so far
trystate_T stack[MAXWLEN];
char_u preword[MAXWLEN * 3]; // word found with proper case;
// concatenation of prefix compound
// words and split word. NUL terminated
// when going deeper but not when coming
// back.
char_u compflags[MAXWLEN]; // compound flags, one for each word
trystate_T *sp;
int newscore;
int score;
char_u *byts, *fbyts, *pbyts;
idx_T *idxs, *fidxs, *pidxs;
int depth;
int c, c2, c3;
int n = 0;
int flags;
garray_T *gap;
idx_T arridx;
int len;
char_u *p;
fromto_T *ftp;
int fl = 0, tl;
int repextra = 0; // extra bytes in fword[] from REP item
slang_T *slang = lp->lp_slang;
int fword_ends;
int goodword_ends;
#ifdef DEBUG_TRIEWALK
// Stores the name of the change made at each level.
char_u changename[MAXWLEN][80];
#endif
int breakcheckcount = 1000;
int compound_ok;
// Go through the whole case-fold tree, try changes at each node.
// "tword[]" contains the word collected from nodes in the tree.
// "fword[]" the word we are trying to match with (initially the bad
// word).
depth = 0;
sp = &stack[0];
CLEAR_POINTER(sp);
sp->ts_curi = 1;
if (soundfold)
{
// Going through the soundfold tree.
byts = fbyts = slang->sl_sbyts;
idxs = fidxs = slang->sl_sidxs;
pbyts = NULL;
pidxs = NULL;
sp->ts_prefixdepth = PFD_NOPREFIX;
sp->ts_state = STATE_START;
}
else
{
// When there are postponed prefixes we need to use these first. At
// the end of the prefix we continue in the case-fold tree.
fbyts = slang->sl_fbyts;
fidxs = slang->sl_fidxs;
pbyts = slang->sl_pbyts;
pidxs = slang->sl_pidxs;
if (pbyts != NULL)
{
byts = pbyts;
idxs = pidxs;
sp->ts_prefixdepth = PFD_PREFIXTREE;
sp->ts_state = STATE_NOPREFIX; // try without prefix first
}
else
{
byts = fbyts;
idxs = fidxs;
sp->ts_prefixdepth = PFD_NOPREFIX;
sp->ts_state = STATE_START;
}
}
// Loop to find all suggestions. At each round we either:
// - For the current state try one operation, advance "ts_curi",
// increase "depth".
// - When a state is done go to the next, set "ts_state".
// - When all states are tried decrease "depth".
while (depth >= 0 && !got_int)
{
sp = &stack[depth];
switch (sp->ts_state)
{
case STATE_START:
case STATE_NOPREFIX:
// Start of node: Deal with NUL bytes, which means
// tword[] may end here.
arridx = sp->ts_arridx; // current node in the tree
len = byts[arridx]; // bytes in this node
arridx += sp->ts_curi; // index of current byte
if (sp->ts_prefixdepth == PFD_PREFIXTREE)
{
// Skip over the NUL bytes, we use them later.
for (n = 0; n < len && byts[arridx + n] == 0; ++n)
;
sp->ts_curi += n;
// Always past NUL bytes now.
n = (int)sp->ts_state;
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_ENDNUL;
sp->ts_save_badflags = su->su_badflags;
// At end of a prefix or at start of prefixtree: check for
// following word.
if (byts[arridx] == 0 || n == (int)STATE_NOPREFIX)
{
// Set su->su_badflags to the caps type at this position.
// Use the caps type until here for the prefix itself.
if (has_mbyte)
n = nofold_len(fword, sp->ts_fidx, su->su_badptr);
else
n = sp->ts_fidx;
flags = badword_captype(su->su_badptr, su->su_badptr + n);
su->su_badflags = badword_captype(su->su_badptr + n,
su->su_badptr + su->su_badlen);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "prefix");
#endif
go_deeper(stack, depth, 0);
++depth;
sp = &stack[depth];
sp->ts_prefixdepth = depth - 1;
byts = fbyts;
idxs = fidxs;
sp->ts_arridx = 0;
// Move the prefix to preword[] with the right case
// and make find_keepcap_word() works.
tword[sp->ts_twordlen] = NUL;
make_case_word(tword + sp->ts_splitoff,
preword + sp->ts_prewordlen, flags);
sp->ts_prewordlen = (char_u)STRLEN(preword);
sp->ts_splitoff = sp->ts_twordlen;
}
break;
}
if (sp->ts_curi > len || byts[arridx] != 0)
{
// Past bytes in node and/or past NUL bytes.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_ENDNUL;
sp->ts_save_badflags = su->su_badflags;
break;
}
// End of word in tree.
++sp->ts_curi; // eat one NUL byte
flags = (int)idxs[arridx];
// Skip words with the NOSUGGEST flag.
if (flags & WF_NOSUGGEST)
break;
fword_ends = (fword[sp->ts_fidx] == NUL
|| (soundfold
? VIM_ISWHITE(fword[sp->ts_fidx])
: !spell_iswordp(fword + sp->ts_fidx, curwin)));
tword[sp->ts_twordlen] = NUL;
if (sp->ts_prefixdepth <= PFD_NOTSPECIAL
&& (sp->ts_flags & TSF_PREFIXOK) == 0
&& pbyts != NULL)
{
// There was a prefix before the word. Check that the prefix
// can be used with this word.
// Count the length of the NULs in the prefix. If there are
// none this must be the first try without a prefix.
n = stack[sp->ts_prefixdepth].ts_arridx;
len = pbyts[n++];
for (c = 0; c < len && pbyts[n + c] == 0; ++c)
;
if (c > 0)
{
c = valid_word_prefix(c, n, flags,
tword + sp->ts_splitoff, slang, FALSE);
if (c == 0)
break;
// Use the WF_RARE flag for a rare prefix.
if (c & WF_RAREPFX)
flags |= WF_RARE;
// Tricky: when checking for both prefix and compounding
// we run into the prefix flag first.
// Remember that it's OK, so that we accept the prefix
// when arriving at a compound flag.
sp->ts_flags |= TSF_PREFIXOK;
}
}
// Check NEEDCOMPOUND: can't use word without compounding. Do try
// appending another compound word below.
if (sp->ts_complen == sp->ts_compsplit && fword_ends
&& (flags & WF_NEEDCOMP))
goodword_ends = FALSE;
else
goodword_ends = TRUE;
p = NULL;
compound_ok = TRUE;
if (sp->ts_complen > sp->ts_compsplit)
{
if (slang->sl_nobreak)
{
// There was a word before this word. When there was no
// change in this word (it was correct) add the first word
// as a suggestion. If this word was corrected too, we
// need to check if a correct word follows.
if (sp->ts_fidx - sp->ts_splitfidx
== sp->ts_twordlen - sp->ts_splitoff
&& STRNCMP(fword + sp->ts_splitfidx,
tword + sp->ts_splitoff,
sp->ts_fidx - sp->ts_splitfidx) == 0)
{
preword[sp->ts_prewordlen] = NUL;
newscore = score_wordcount_adj(slang, sp->ts_score,
preword + sp->ts_prewordlen,
sp->ts_prewordlen > 0);
// Add the suggestion if the score isn't too bad.
if (newscore <= su->su_maxscore)
add_suggestion(su, &su->su_ga, preword,
sp->ts_splitfidx - repextra,
newscore, 0, FALSE,
lp->lp_sallang, FALSE);
break;
}
}
else
{
// There was a compound word before this word. If this
// word does not support compounding then give up
// (splitting is tried for the word without compound
// flag).
if (((unsigned)flags >> 24) == 0
|| sp->ts_twordlen - sp->ts_splitoff
< slang->sl_compminlen)
break;
// For multi-byte chars check character length against
// COMPOUNDMIN.
if (has_mbyte
&& slang->sl_compminlen > 0
&& mb_charlen(tword + sp->ts_splitoff)
< slang->sl_compminlen)
break;
compflags[sp->ts_complen] = ((unsigned)flags >> 24);
compflags[sp->ts_complen + 1] = NUL;
vim_strncpy(preword + sp->ts_prewordlen,
tword + sp->ts_splitoff,
sp->ts_twordlen - sp->ts_splitoff);
// Verify CHECKCOMPOUNDPATTERN rules.
if (match_checkcompoundpattern(preword, sp->ts_prewordlen,
&slang->sl_comppat))
compound_ok = FALSE;
if (compound_ok)
{
p = preword;
while (*skiptowhite(p) != NUL)
p = skipwhite(skiptowhite(p));
if (fword_ends && !can_compound(slang, p,
compflags + sp->ts_compsplit))
// Compound is not allowed. But it may still be
// possible if we add another (short) word.
compound_ok = FALSE;
}
// Get pointer to last char of previous word.
p = preword + sp->ts_prewordlen;
MB_PTR_BACK(preword, p);
}
}
// Form the word with proper case in preword.
// If there is a word from a previous split, append.
// For the soundfold tree don't change the case, simply append.
if (soundfold)
STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff);
else if (flags & WF_KEEPCAP)
// Must find the word in the keep-case tree.
find_keepcap_word(slang, tword + sp->ts_splitoff,
preword + sp->ts_prewordlen);
else
{
// Include badflags: If the badword is onecap or allcap
// use that for the goodword too. But if the badword is
// allcap and it's only one char long use onecap.
c = su->su_badflags;
if ((c & WF_ALLCAP)
&& su->su_badlen == (*mb_ptr2len)(su->su_badptr))
c = WF_ONECAP;
c |= flags;
// When appending a compound word after a word character don't
// use Onecap.
if (p != NULL && spell_iswordp_nmw(p, curwin))
c &= ~WF_ONECAP;
make_case_word(tword + sp->ts_splitoff,
preword + sp->ts_prewordlen, c);
}
if (!soundfold)
{
// Don't use a banned word. It may appear again as a good
// word, thus remember it.
if (flags & WF_BANNED)
{
add_banned(su, preword + sp->ts_prewordlen);
break;
}
if ((sp->ts_complen == sp->ts_compsplit
&& WAS_BANNED(su, preword + sp->ts_prewordlen))
|| WAS_BANNED(su, preword))
{
if (slang->sl_compprog == NULL)
break;
// the word so far was banned but we may try compounding
goodword_ends = FALSE;
}
}
newscore = 0;
if (!soundfold) // soundfold words don't have flags
{
if ((flags & WF_REGION)
&& (((unsigned)flags >> 16) & lp->lp_region) == 0)
newscore += SCORE_REGION;
if (flags & WF_RARE)
newscore += SCORE_RARE;
if (!spell_valid_case(su->su_badflags,
captype(preword + sp->ts_prewordlen, NULL)))
newscore += SCORE_ICASE;
}
// TODO: how about splitting in the soundfold tree?
if (fword_ends
&& goodword_ends
&& sp->ts_fidx >= sp->ts_fidxtry
&& compound_ok)
{
// The badword also ends: add suggestions.
#ifdef DEBUG_TRIEWALK
if (soundfold && STRCMP(preword, "smwrd") == 0)
{
int j;
// print the stack of changes that brought us here
smsg("------ %s -------", fword);
for (j = 0; j < depth; ++j)
smsg("%s", changename[j]);
}
#endif
if (soundfold)
{
// For soundfolded words we need to find the original
// words, the edit distance and then add them.
add_sound_suggest(su, preword, sp->ts_score, lp);
}
else if (sp->ts_fidx > 0)
{
// Give a penalty when changing non-word char to word
// char, e.g., "thes," -> "these".
p = fword + sp->ts_fidx;
MB_PTR_BACK(fword, p);
if (!spell_iswordp(p, curwin) && *preword != NUL)
{
p = preword + STRLEN(preword);
MB_PTR_BACK(preword, p);
if (spell_iswordp(p, curwin))
newscore += SCORE_NONWORD;
}
// Give a bonus to words seen before.
score = score_wordcount_adj(slang,
sp->ts_score + newscore,
preword + sp->ts_prewordlen,
sp->ts_prewordlen > 0);
// Add the suggestion if the score isn't too bad.
if (score <= su->su_maxscore)
{
add_suggestion(su, &su->su_ga, preword,
sp->ts_fidx - repextra,
score, 0, FALSE, lp->lp_sallang, FALSE);
if (su->su_badflags & WF_MIXCAP)
{
// We really don't know if the word should be
// upper or lower case, add both.
c = captype(preword, NULL);
if (c == 0 || c == WF_ALLCAP)
{
make_case_word(tword + sp->ts_splitoff,
preword + sp->ts_prewordlen,
c == 0 ? WF_ALLCAP : 0);
add_suggestion(su, &su->su_ga, preword,
sp->ts_fidx - repextra,
score + SCORE_ICASE, 0, FALSE,
lp->lp_sallang, FALSE);
}
}
}
}
}
// Try word split and/or compounding.
if ((sp->ts_fidx >= sp->ts_fidxtry || fword_ends)
// Don't split halfway a character.
&& (!has_mbyte || sp->ts_tcharlen == 0))
{
int try_compound;
int try_split;
// If past the end of the bad word don't try a split.
// Otherwise try changing the next word. E.g., find
// suggestions for "the the" where the second "the" is
// different. It's done like a split.
// TODO: word split for soundfold words
try_split = (sp->ts_fidx - repextra < su->su_badlen)
&& !soundfold;
// Get here in several situations:
// 1. The word in the tree ends:
// If the word allows compounding try that. Otherwise try
// a split by inserting a space. For both check that a
// valid words starts at fword[sp->ts_fidx].
// For NOBREAK do like compounding to be able to check if
// the next word is valid.
// 2. The badword does end, but it was due to a change (e.g.,
// a swap). No need to split, but do check that the
// following word is valid.
// 3. The badword and the word in the tree end. It may still
// be possible to compound another (short) word.
try_compound = FALSE;
if (!soundfold
&& !slang->sl_nocompoundsugs
&& slang->sl_compprog != NULL
&& ((unsigned)flags >> 24) != 0
&& sp->ts_twordlen - sp->ts_splitoff
>= slang->sl_compminlen
&& (!has_mbyte
|| slang->sl_compminlen == 0
|| mb_charlen(tword + sp->ts_splitoff)
>= slang->sl_compminlen)
&& (slang->sl_compsylmax < MAXWLEN
|| sp->ts_complen + 1 - sp->ts_compsplit
< slang->sl_compmax)
&& (can_be_compound(sp, slang,
compflags, ((unsigned)flags >> 24))))
{
try_compound = TRUE;
compflags[sp->ts_complen] = ((unsigned)flags >> 24);
compflags[sp->ts_complen + 1] = NUL;
}
// For NOBREAK we never try splitting, it won't make any word
// valid.
if (slang->sl_nobreak && !slang->sl_nocompoundsugs)
try_compound = TRUE;
// If we could add a compound word, and it's also possible to
// split at this point, do the split first and set
// TSF_DIDSPLIT to avoid doing it again.
else if (!fword_ends
&& try_compound
&& (sp->ts_flags & TSF_DIDSPLIT) == 0)
{
try_compound = FALSE;
sp->ts_flags |= TSF_DIDSPLIT;
--sp->ts_curi; // do the same NUL again
compflags[sp->ts_complen] = NUL;
}
else
sp->ts_flags &= ~TSF_DIDSPLIT;
if (try_split || try_compound)
{
if (!try_compound && (!fword_ends || !goodword_ends))
{
// If we're going to split need to check that the
// words so far are valid for compounding. If there
// is only one word it must not have the NEEDCOMPOUND
// flag.
if (sp->ts_complen == sp->ts_compsplit
&& (flags & WF_NEEDCOMP))
break;
p = preword;
while (*skiptowhite(p) != NUL)
p = skipwhite(skiptowhite(p));
if (sp->ts_complen > sp->ts_compsplit
&& !can_compound(slang, p,
compflags + sp->ts_compsplit))
break;
if (slang->sl_nosplitsugs)
newscore += SCORE_SPLIT_NO;
else
newscore += SCORE_SPLIT;
// Give a bonus to words seen before.
newscore = score_wordcount_adj(slang, newscore,
preword + sp->ts_prewordlen, TRUE);
}
if (TRY_DEEPER(su, stack, depth, newscore))
{
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
if (!try_compound && !fword_ends)
sprintf(changename[depth], "%.*s-%s: split",
sp->ts_twordlen, tword, fword + sp->ts_fidx);
else
sprintf(changename[depth], "%.*s-%s: compound",
sp->ts_twordlen, tword, fword + sp->ts_fidx);
#endif
// Save things to be restored at STATE_SPLITUNDO.
sp->ts_save_badflags = su->su_badflags;
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SPLITUNDO;
++depth;
sp = &stack[depth];
// Append a space to preword when splitting.
if (!try_compound && !fword_ends)
STRCAT(preword, " ");
sp->ts_prewordlen = (char_u)STRLEN(preword);
sp->ts_splitoff = sp->ts_twordlen;
sp->ts_splitfidx = sp->ts_fidx;
// If the badword has a non-word character at this
// position skip it. That means replacing the
// non-word character with a space. Always skip a
// character when the word ends. But only when the
// good word can end.
if (((!try_compound && !spell_iswordp_nmw(fword
+ sp->ts_fidx,
curwin))
|| fword_ends)
&& fword[sp->ts_fidx] != NUL
&& goodword_ends)
{
int l;
l = mb_ptr2len(fword + sp->ts_fidx);
if (fword_ends)
{
// Copy the skipped character to preword.
mch_memmove(preword + sp->ts_prewordlen,
fword + sp->ts_fidx, l);
sp->ts_prewordlen += l;
preword[sp->ts_prewordlen] = NUL;
}
else
sp->ts_score -= SCORE_SPLIT - SCORE_SUBST;
sp->ts_fidx += l;
}
// When compounding include compound flag in
// compflags[] (already set above). When splitting we
// may start compounding over again.
if (try_compound)
++sp->ts_complen;
else
sp->ts_compsplit = sp->ts_complen;
sp->ts_prefixdepth = PFD_NOPREFIX;
// set su->su_badflags to the caps type at this
// position
if (has_mbyte)
n = nofold_len(fword, sp->ts_fidx, su->su_badptr);
else
n = sp->ts_fidx;
su->su_badflags = badword_captype(su->su_badptr + n,
su->su_badptr + su->su_badlen);
// Restart at top of the tree.
sp->ts_arridx = 0;
// If there are postponed prefixes, try these too.
if (pbyts != NULL)
{
byts = pbyts;
idxs = pidxs;
sp->ts_prefixdepth = PFD_PREFIXTREE;
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_NOPREFIX;
}
}
}
}
break;
case STATE_SPLITUNDO:
// Undo the changes done for word split or compound word.
su->su_badflags = sp->ts_save_badflags;
// Continue looking for NUL bytes.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_START;
// In case we went into the prefix tree.
byts = fbyts;
idxs = fidxs;
break;
case STATE_ENDNUL:
// Past the NUL bytes in the node.
su->su_badflags = sp->ts_save_badflags;
if (fword[sp->ts_fidx] == NUL && sp->ts_tcharlen == 0)
{
// The badword ends, can't use STATE_PLAIN.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_DEL;
break;
}
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_PLAIN;
// FALLTHROUGH
case STATE_PLAIN:
// Go over all possible bytes at this node, add each to tword[]
// and use child node. "ts_curi" is the index.
arridx = sp->ts_arridx;
if (sp->ts_curi > byts[arridx])
{
// Done all bytes at this node, do next state. When still at
// already changed bytes skip the other tricks.
PROF_STORE(sp->ts_state)
if (sp->ts_fidx >= sp->ts_fidxtry)
sp->ts_state = STATE_DEL;
else
sp->ts_state = STATE_FINAL;
}
else
{
arridx += sp->ts_curi++;
c = byts[arridx];
// Normal byte, go one level deeper. If it's not equal to the
// byte in the bad word adjust the score. But don't even try
// when the byte was already changed. And don't try when we
// just deleted this byte, accepting it is always cheaper than
// delete + substitute.
if (c == fword[sp->ts_fidx]
|| (sp->ts_tcharlen > 0 && sp->ts_isdiff != DIFF_NONE))
newscore = 0;
else
newscore = SCORE_SUBST;
if ((newscore == 0
|| (sp->ts_fidx >= sp->ts_fidxtry
&& ((sp->ts_flags & TSF_DIDDEL) == 0
|| c != fword[sp->ts_delidx])))
&& TRY_DEEPER(su, stack, depth, newscore))
{
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
if (newscore > 0)
sprintf(changename[depth], "%.*s-%s: subst %c to %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
fword[sp->ts_fidx], c);
else
sprintf(changename[depth], "%.*s-%s: accept %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
fword[sp->ts_fidx]);
#endif
++depth;
sp = &stack[depth];
++sp->ts_fidx;
tword[sp->ts_twordlen++] = c;
sp->ts_arridx = idxs[arridx];
if (newscore == SCORE_SUBST)
sp->ts_isdiff = DIFF_YES;
if (has_mbyte)
{
// Multi-byte characters are a bit complicated to
// handle: They differ when any of the bytes differ
// and then their length may also differ.
if (sp->ts_tcharlen == 0)
{
// First byte.
sp->ts_tcharidx = 0;
sp->ts_tcharlen = MB_BYTE2LEN(c);
sp->ts_fcharstart = sp->ts_fidx - 1;
sp->ts_isdiff = (newscore != 0)
? DIFF_YES : DIFF_NONE;
}
else if (sp->ts_isdiff == DIFF_INSERT)
// When inserting trail bytes don't advance in the
// bad word.
--sp->ts_fidx;
if (++sp->ts_tcharidx == sp->ts_tcharlen)
{
// Last byte of character.
if (sp->ts_isdiff == DIFF_YES)
{
// Correct ts_fidx for the byte length of the
// character (we didn't check that before).
sp->ts_fidx = sp->ts_fcharstart
+ mb_ptr2len(
fword + sp->ts_fcharstart);
// For changing a composing character adjust
// the score from SCORE_SUBST to
// SCORE_SUBCOMP.
if (enc_utf8
&& utf_iscomposing(
utf_ptr2char(tword
+ sp->ts_twordlen
- sp->ts_tcharlen))
&& utf_iscomposing(
utf_ptr2char(fword
+ sp->ts_fcharstart)))
sp->ts_score -=
SCORE_SUBST - SCORE_SUBCOMP;
// For a similar character adjust score from
// SCORE_SUBST to SCORE_SIMILAR.
else if (!soundfold
&& slang->sl_has_map
&& similar_chars(slang,
mb_ptr2char(tword
+ sp->ts_twordlen
- sp->ts_tcharlen),
mb_ptr2char(fword
+ sp->ts_fcharstart)))
sp->ts_score -=
SCORE_SUBST - SCORE_SIMILAR;
}
else if (sp->ts_isdiff == DIFF_INSERT
&& sp->ts_twordlen > sp->ts_tcharlen)
{
p = tword + sp->ts_twordlen - sp->ts_tcharlen;
c = mb_ptr2char(p);
if (enc_utf8 && utf_iscomposing(c))
{
// Inserting a composing char doesn't
// count that much.
sp->ts_score -= SCORE_INS - SCORE_INSCOMP;
}
else
{
// If the previous character was the same,
// thus doubling a character, give a bonus
// to the score. Also for the soundfold
// tree (might seem illogical but does
// give better scores).
MB_PTR_BACK(tword, p);
if (c == mb_ptr2char(p))
sp->ts_score -= SCORE_INS
- SCORE_INSDUP;
}
}
// Starting a new char, reset the length.
sp->ts_tcharlen = 0;
}
}
else
{
// If we found a similar char adjust the score.
// We do this after calling go_deeper() because
// it's slow.
if (newscore != 0
&& !soundfold
&& slang->sl_has_map
&& similar_chars(slang,
c, fword[sp->ts_fidx - 1]))
sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
}
}
}
break;
case STATE_DEL:
// When past the first byte of a multi-byte char don't try
// delete/insert/swap a character.
if (has_mbyte && sp->ts_tcharlen > 0)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
break;
}
// Try skipping one character in the bad word (delete it).
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_INS_PREP;
sp->ts_curi = 1;
if (soundfold && sp->ts_fidx == 0 && fword[sp->ts_fidx] == '*')
// Deleting a vowel at the start of a word counts less, see
// soundalike_score().
newscore = 2 * SCORE_DEL / 3;
else
newscore = SCORE_DEL;
if (fword[sp->ts_fidx] != NUL
&& TRY_DEEPER(su, stack, depth, newscore))
{
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: delete %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
fword[sp->ts_fidx]);
#endif
++depth;
// Remember what character we deleted, so that we can avoid
// inserting it again.
stack[depth].ts_flags |= TSF_DIDDEL;
stack[depth].ts_delidx = sp->ts_fidx;
// Advance over the character in fword[]. Give a bonus to the
// score if the same character is following "nn" -> "n". It's
// a bit illogical for soundfold tree but it does give better
// results.
if (has_mbyte)
{
c = mb_ptr2char(fword + sp->ts_fidx);
stack[depth].ts_fidx += mb_ptr2len(fword + sp->ts_fidx);
if (enc_utf8 && utf_iscomposing(c))
stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP;
else if (c == mb_ptr2char(fword + stack[depth].ts_fidx))
stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
}
else
{
++stack[depth].ts_fidx;
if (fword[sp->ts_fidx] == fword[sp->ts_fidx + 1])
stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
}
break;
}
// FALLTHROUGH
case STATE_INS_PREP:
if (sp->ts_flags & TSF_DIDDEL)
{
// If we just deleted a byte then inserting won't make sense,
// a substitute is always cheaper.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SWAP;
break;
}
// skip over NUL bytes
n = sp->ts_arridx;
for (;;)
{
if (sp->ts_curi > byts[n])
{
// Only NUL bytes at this node, go to next state.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SWAP;
break;
}
if (byts[n + sp->ts_curi] != NUL)
{
// Found a byte to insert.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_INS;
break;
}
++sp->ts_curi;
}
break;
// FALLTHROUGH
case STATE_INS:
// Insert one byte. Repeat this for each possible byte at this
// node.
n = sp->ts_arridx;
if (sp->ts_curi > byts[n])
{
// Done all bytes at this node, go to next state.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SWAP;
break;
}
// Do one more byte at this node, but:
// - Skip NUL bytes.
// - Skip the byte if it's equal to the byte in the word,
// accepting that byte is always better.
n += sp->ts_curi++;
c = byts[n];
if (soundfold && sp->ts_twordlen == 0 && c == '*')
// Inserting a vowel at the start of a word counts less,
// see soundalike_score().
newscore = 2 * SCORE_INS / 3;
else
newscore = SCORE_INS;
if (c != fword[sp->ts_fidx]
&& TRY_DEEPER(su, stack, depth, newscore))
{
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: insert %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
c);
#endif
++depth;
sp = &stack[depth];
tword[sp->ts_twordlen++] = c;
sp->ts_arridx = idxs[n];
if (has_mbyte)
{
fl = MB_BYTE2LEN(c);
if (fl > 1)
{
// There are following bytes for the same character.
// We must find all bytes before trying
// delete/insert/swap/etc.
sp->ts_tcharlen = fl;
sp->ts_tcharidx = 1;
sp->ts_isdiff = DIFF_INSERT;
}
}
else
fl = 1;
if (fl == 1)
{
// If the previous character was the same, thus doubling a
// character, give a bonus to the score. Also for
// soundfold words (illogical but does give a better
// score).
if (sp->ts_twordlen >= 2
&& tword[sp->ts_twordlen - 2] == c)
sp->ts_score -= SCORE_INS - SCORE_INSDUP;
}
}
break;
case STATE_SWAP:
// Swap two bytes in the bad word: "12" -> "21".
// We change "fword" here, it's changed back afterwards at
// STATE_UNSWAP.
p = fword + sp->ts_fidx;
c = *p;
if (c == NUL)
{
// End of word, can't swap or replace.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
break;
}
// Don't swap if the first character is not a word character.
// SWAP3 etc. also don't make sense then.
if (!soundfold && !spell_iswordp(p, curwin))
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
if (has_mbyte)
{
n = MB_CPTR2LEN(p);
c = mb_ptr2char(p);
if (p[n] == NUL)
c2 = NUL;
else if (!soundfold && !spell_iswordp(p + n, curwin))
c2 = c; // don't swap non-word char
else
c2 = mb_ptr2char(p + n);
}
else
{
if (p[1] == NUL)
c2 = NUL;
else if (!soundfold && !spell_iswordp(p + 1, curwin))
c2 = c; // don't swap non-word char
else
c2 = p[1];
}
// When the second character is NUL we can't swap.
if (c2 == NUL)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
// When characters are identical, swap won't do anything.
// Also get here if the second char is not a word character.
if (c == c2)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SWAP3;
break;
}
if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP))
{
go_deeper(stack, depth, SCORE_SWAP);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: swap %c and %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
c, c2);
#endif
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNSWAP;
++depth;
if (has_mbyte)
{
fl = mb_char2len(c2);
mch_memmove(p, p + n, fl);
mb_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
}
else
{
p[0] = c2;
p[1] = c;
stack[depth].ts_fidxtry = sp->ts_fidx + 2;
}
}
else
{
// If this swap doesn't work then SWAP3 won't either.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
}
break;
case STATE_UNSWAP:
// Undo the STATE_SWAP swap: "21" -> "12".
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = mb_ptr2len(p);
c = mb_ptr2char(p + n);
mch_memmove(p + mb_ptr2len(p + n), p, n);
mb_char2bytes(c, p);
}
else
{
c = *p;
*p = p[1];
p[1] = c;
}
// FALLTHROUGH
case STATE_SWAP3:
// Swap two bytes, skipping one: "123" -> "321". We change
// "fword" here, it's changed back afterwards at STATE_UNSWAP3.
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = MB_CPTR2LEN(p);
c = mb_ptr2char(p);
fl = MB_CPTR2LEN(p + n);
c2 = mb_ptr2char(p + n);
if (!soundfold && !spell_iswordp(p + n + fl, curwin))
c3 = c; // don't swap non-word char
else
c3 = mb_ptr2char(p + n + fl);
}
else
{
c = *p;
c2 = p[1];
if (!soundfold && !spell_iswordp(p + 2, curwin))
c3 = c; // don't swap non-word char
else
c3 = p[2];
}
// When characters are identical: "121" then SWAP3 result is
// identical, ROT3L result is same as SWAP: "211", ROT3L result is
// same as SWAP on next char: "112". Thus skip all swapping.
// Also skip when c3 is NUL.
// Also get here when the third character is not a word character.
// Second character may any char: "a.b" -> "b.a"
if (c == c3 || c3 == NUL)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
{
go_deeper(stack, depth, SCORE_SWAP3);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: swap3 %c and %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
c, c3);
#endif
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNSWAP3;
++depth;
if (has_mbyte)
{
tl = mb_char2len(c3);
mch_memmove(p, p + n + fl, tl);
mb_char2bytes(c2, p + tl);
mb_char2bytes(c, p + fl + tl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl;
}
else
{
p[0] = p[2];
p[2] = c;
stack[depth].ts_fidxtry = sp->ts_fidx + 3;
}
}
else
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
}
break;
case STATE_UNSWAP3:
// Undo STATE_SWAP3: "321" -> "123"
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = mb_ptr2len(p);
c2 = mb_ptr2char(p + n);
fl = mb_ptr2len(p + n);
c = mb_ptr2char(p + n + fl);
tl = mb_ptr2len(p + n + fl);
mch_memmove(p + fl + tl, p, n);
mb_char2bytes(c, p);
mb_char2bytes(c2, p + tl);
p = p + tl;
}
else
{
c = *p;
*p = p[2];
p[2] = c;
++p;
}
if (!soundfold && !spell_iswordp(p, curwin))
{
// Middle char is not a word char, skip the rotate. First and
// third char were already checked at swap and swap3.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
// Rotate three characters left: "123" -> "231". We change
// "fword" here, it's changed back afterwards at STATE_UNROT3L.
if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
{
go_deeper(stack, depth, SCORE_SWAP3);
#ifdef DEBUG_TRIEWALK
p = fword + sp->ts_fidx;
sprintf(changename[depth], "%.*s-%s: rotate left %c%c%c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
p[0], p[1], p[2]);
#endif
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNROT3L;
++depth;
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = MB_CPTR2LEN(p);
c = mb_ptr2char(p);
fl = MB_CPTR2LEN(p + n);
fl += MB_CPTR2LEN(p + n + fl);
mch_memmove(p, p + n, fl);
mb_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
}
else
{
c = *p;
*p = p[1];
p[1] = p[2];
p[2] = c;
stack[depth].ts_fidxtry = sp->ts_fidx + 3;
}
}
else
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
}
break;
case STATE_UNROT3L:
// Undo ROT3L: "231" -> "123"
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = mb_ptr2len(p);
n += mb_ptr2len(p + n);
c = mb_ptr2char(p + n);
tl = mb_ptr2len(p + n);
mch_memmove(p + tl, p, n);
mb_char2bytes(c, p);
}
else
{
c = p[2];
p[2] = p[1];
p[1] = *p;
*p = c;
}
// Rotate three bytes right: "123" -> "312". We change "fword"
// here, it's changed back afterwards at STATE_UNROT3R.
if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
{
go_deeper(stack, depth, SCORE_SWAP3);
#ifdef DEBUG_TRIEWALK
p = fword + sp->ts_fidx;
sprintf(changename[depth], "%.*s-%s: rotate right %c%c%c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
p[0], p[1], p[2]);
#endif
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNROT3R;
++depth;
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = MB_CPTR2LEN(p);
n += MB_CPTR2LEN(p + n);
c = mb_ptr2char(p + n);
tl = MB_CPTR2LEN(p + n);
mch_memmove(p + tl, p, n);
mb_char2bytes(c, p);
stack[depth].ts_fidxtry = sp->ts_fidx + n + tl;
}
else
{
c = p[2];
p[2] = p[1];
p[1] = *p;
*p = c;
stack[depth].ts_fidxtry = sp->ts_fidx + 3;
}
}
else
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
}
break;
case STATE_UNROT3R:
// Undo ROT3R: "312" -> "123"
p = fword + sp->ts_fidx;
if (has_mbyte)
{
c = mb_ptr2char(p);
tl = mb_ptr2len(p);
n = mb_ptr2len(p + tl);
n += mb_ptr2len(p + tl + n);
mch_memmove(p, p + tl, n);
mb_char2bytes(c, p + n);
}
else
{
c = *p;
*p = p[1];
p[1] = p[2];
p[2] = c;
}
// FALLTHROUGH
case STATE_REP_INI:
// Check if matching with REP items from the .aff file would work.
// Quickly skip if:
// - there are no REP items and we are not in the soundfold trie
// - the score is going to be too high anyway
// - already applied a REP item or swapped here
if ((lp->lp_replang == NULL && !soundfold)
|| sp->ts_score + SCORE_REP >= su->su_maxscore
|| sp->ts_fidx < sp->ts_fidxtry)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
break;
}
// Use the first byte to quickly find the first entry that may
// match. If the index is -1 there is none.
if (soundfold)
sp->ts_curi = slang->sl_repsal_first[fword[sp->ts_fidx]];
else
sp->ts_curi = lp->lp_replang->sl_rep_first[fword[sp->ts_fidx]];
if (sp->ts_curi < 0)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
break;
}
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP;
// FALLTHROUGH
case STATE_REP:
// Try matching with REP items from the .aff file. For each match
// replace the characters and check if the resulting word is
// valid.
p = fword + sp->ts_fidx;
if (soundfold)
gap = &slang->sl_repsal;
else
gap = &lp->lp_replang->sl_rep;
while (sp->ts_curi < gap->ga_len)
{
ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
if (*ftp->ft_from != *p)
{
// past possible matching entries
sp->ts_curi = gap->ga_len;
break;
}
if (STRNCMP(ftp->ft_from, p, STRLEN(ftp->ft_from)) == 0
&& TRY_DEEPER(su, stack, depth, SCORE_REP))
{
go_deeper(stack, depth, SCORE_REP);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: replace %s with %s",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
ftp->ft_from, ftp->ft_to);
#endif
// Need to undo this afterwards.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_UNDO;
// Change the "from" to the "to" string.
++depth;
fl = (int)STRLEN(ftp->ft_from);
tl = (int)STRLEN(ftp->ft_to);
if (fl != tl)
{
STRMOVE(p + tl, p + fl);
repextra += tl - fl;
}
mch_memmove(p, ftp->ft_to, tl);
stack[depth].ts_fidxtry = sp->ts_fidx + tl;
stack[depth].ts_tcharlen = 0;
break;
}
}
if (sp->ts_curi >= gap->ga_len && sp->ts_state == STATE_REP)
{
// No (more) matches.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
}
break;
case STATE_REP_UNDO:
// Undo a REP replacement and continue with the next one.
if (soundfold)
gap = &slang->sl_repsal;
else
gap = &lp->lp_replang->sl_rep;
ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1;
fl = (int)STRLEN(ftp->ft_from);
tl = (int)STRLEN(ftp->ft_to);
p = fword + sp->ts_fidx;
if (fl != tl)
{
STRMOVE(p + fl, p + tl);
repextra -= tl - fl;
}
mch_memmove(p, ftp->ft_from, fl);
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP;
break;
default:
// Did all possible states at this level, go up one level.
--depth;
if (depth >= 0 && stack[depth].ts_prefixdepth == PFD_PREFIXTREE)
{
// Continue in or go back to the prefix tree.
byts = pbyts;
idxs = pidxs;
}
// Don't check for CTRL-C too often, it takes time.
if (--breakcheckcount == 0)
{
ui_breakcheck();
breakcheckcount = 1000;
}
}
}
} | 6029 | True | 1 |
|
CVE-2022-0413 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/37f47958b8a2a44abc60614271d9537e7f14e51a', 'name': 'https://github.com/vim/vim/commit/37f47958b8a2a44abc60614271d9537e7f14e51a', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/563d1e8f-5c3d-4669-941c-3216f4a87c38', 'name': 'https://huntr.dev/bounties/563d1e8f-5c3d-4669-941c-3216f4a87c38', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UFXFAILMLUIK4MBUEZO4HNBNKYZRJ5AP/', 'name': 'FEDORA-2022-da2fb07efb', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/05/msg00022.html', 'name': '[debian-lts-announce] 20220516 [SECURITY] [DLA 3011-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4253', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T17:35Z | 2022-01-30T15:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-01-29 14:21:51+00:00 | patch 8.2.4253: using freed memory when substitute with function call
Problem: Using freed memory when substitute uses a recursive function call.
Solution: Make a copy of the substitute text. | 37f47958b8a2a44abc60614271d9537e7f14e51a | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ex_substitute | ex_substitute( exarg_T * eap) | ['eap'] | ex_substitute(exarg_T *eap)
{
linenr_T lnum;
long i = 0;
regmmatch_T regmatch;
static subflags_T subflags = {FALSE, FALSE, FALSE, TRUE, FALSE,
FALSE, FALSE, 0};
#ifdef FEAT_EVAL
subflags_T subflags_save;
#endif
int save_do_all; // remember user specified 'g' flag
int save_do_ask; // remember user specified 'c' flag
char_u *pat = NULL, *sub = NULL; // init for GCC
int delimiter;
int sublen;
int got_quit = FALSE;
int got_match = FALSE;
int temp;
int which_pat;
char_u *cmd;
int save_State;
linenr_T first_line = 0; // first changed line
linenr_T last_line= 0; // below last changed line AFTER the
// change
linenr_T old_line_count = curbuf->b_ml.ml_line_count;
linenr_T line2;
long nmatch; // number of lines in match
char_u *sub_firstline; // allocated copy of first sub line
int endcolumn = FALSE; // cursor in last column when done
pos_T old_cursor = curwin->w_cursor;
int start_nsubs;
#ifdef FEAT_EVAL
int save_ma = 0;
#endif
cmd = eap->arg;
if (!global_busy)
{
sub_nsubs = 0;
sub_nlines = 0;
}
start_nsubs = sub_nsubs;
if (eap->cmdidx == CMD_tilde)
which_pat = RE_LAST; // use last used regexp
else
which_pat = RE_SUBST; // use last substitute regexp
// new pattern and substitution
if (eap->cmd[0] == 's' && *cmd != NUL && !VIM_ISWHITE(*cmd)
&& vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL)
{
// don't accept alphanumeric for separator
if (check_regexp_delim(*cmd) == FAIL)
return;
#ifdef FEAT_EVAL
if (in_vim9script() && check_global_and_subst(eap->cmd, eap->arg)
== FAIL)
return;
#endif
/*
* undocumented vi feature:
* "\/sub/" and "\?sub?" use last used search pattern (almost like
* //sub/r). "\&sub&" use last substitute pattern (like //sub/).
*/
if (*cmd == '\\')
{
++cmd;
if (vim_strchr((char_u *)"/?&", *cmd) == NULL)
{
emsg(_(e_backslash_should_be_followed_by));
return;
}
if (*cmd != '&')
which_pat = RE_SEARCH; // use last '/' pattern
pat = (char_u *)""; // empty search pattern
delimiter = *cmd++; // remember delimiter character
}
else // find the end of the regexp
{
which_pat = RE_LAST; // use last used regexp
delimiter = *cmd++; // remember delimiter character
pat = cmd; // remember start of search pat
cmd = skip_regexp_ex(cmd, delimiter, magic_isset(),
&eap->arg, NULL, NULL);
if (cmd[0] == delimiter) // end delimiter found
*cmd++ = NUL; // replace it with a NUL
}
/*
* Small incompatibility: vi sees '\n' as end of the command, but in
* Vim we want to use '\n' to find/substitute a NUL.
*/
sub = cmd; // remember the start of the substitution
cmd = skip_substitute(cmd, delimiter);
if (!eap->skip)
{
// In POSIX vi ":s/pat/%/" uses the previous subst. string.
if (STRCMP(sub, "%") == 0
&& vim_strchr(p_cpo, CPO_SUBPERCENT) != NULL)
{
if (old_sub == NULL) // there is no previous command
{
emsg(_(e_no_previous_substitute_regular_expression));
return;
}
sub = old_sub;
}
else
{
vim_free(old_sub);
old_sub = vim_strsave(sub);
}
}
}
else if (!eap->skip) // use previous pattern and substitution
{
if (old_sub == NULL) // there is no previous command
{
emsg(_(e_no_previous_substitute_regular_expression));
return;
}
pat = NULL; // search_regcomp() will use previous pattern
sub = old_sub;
// Vi compatibility quirk: repeating with ":s" keeps the cursor in the
// last column after using "$".
endcolumn = (curwin->w_curswant == MAXCOL);
}
// Recognize ":%s/\n//" and turn it into a join command, which is much
// more efficient.
// TODO: find a generic solution to make line-joining operations more
// efficient, avoid allocating a string that grows in size.
if (pat != NULL && STRCMP(pat, "\\n") == 0
&& *sub == NUL
&& (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l'
|| *cmd == 'p' || *cmd == '#'))))
{
linenr_T joined_lines_count;
if (eap->skip)
return;
curwin->w_cursor.lnum = eap->line1;
if (*cmd == 'l')
eap->flags = EXFLAG_LIST;
else if (*cmd == '#')
eap->flags = EXFLAG_NR;
else if (*cmd == 'p')
eap->flags = EXFLAG_PRINT;
// The number of lines joined is the number of lines in the range plus
// one. One less when the last line is included.
joined_lines_count = eap->line2 - eap->line1 + 1;
if (eap->line2 < curbuf->b_ml.ml_line_count)
++joined_lines_count;
if (joined_lines_count > 1)
{
(void)do_join(joined_lines_count, FALSE, TRUE, FALSE, TRUE);
sub_nsubs = joined_lines_count - 1;
sub_nlines = 1;
(void)do_sub_msg(FALSE);
ex_may_print(eap);
}
if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0)
save_re_pat(RE_SUBST, pat, magic_isset());
// put pattern in history
add_to_history(HIST_SEARCH, pat, TRUE, NUL);
return;
}
/*
* Find trailing options. When '&' is used, keep old options.
*/
if (*cmd == '&')
++cmd;
else
{
#ifdef FEAT_EVAL
if (in_vim9script())
{
// ignore 'gdefault' and 'edcompatible'
subflags.do_all = FALSE;
subflags.do_ask = FALSE;
}
else
#endif
if (!p_ed)
{
if (p_gd) // default is global on
subflags.do_all = TRUE;
else
subflags.do_all = FALSE;
subflags.do_ask = FALSE;
}
subflags.do_error = TRUE;
subflags.do_print = FALSE;
subflags.do_list = FALSE;
subflags.do_count = FALSE;
subflags.do_number = FALSE;
subflags.do_ic = 0;
}
while (*cmd)
{
/*
* Note that 'g' and 'c' are always inverted, also when p_ed is off.
* 'r' is never inverted.
*/
if (*cmd == 'g')
subflags.do_all = !subflags.do_all;
else if (*cmd == 'c')
subflags.do_ask = !subflags.do_ask;
else if (*cmd == 'n')
subflags.do_count = TRUE;
else if (*cmd == 'e')
subflags.do_error = !subflags.do_error;
else if (*cmd == 'r') // use last used regexp
which_pat = RE_LAST;
else if (*cmd == 'p')
subflags.do_print = TRUE;
else if (*cmd == '#')
{
subflags.do_print = TRUE;
subflags.do_number = TRUE;
}
else if (*cmd == 'l')
{
subflags.do_print = TRUE;
subflags.do_list = TRUE;
}
else if (*cmd == 'i') // ignore case
subflags.do_ic = 'i';
else if (*cmd == 'I') // don't ignore case
subflags.do_ic = 'I';
else
break;
++cmd;
}
if (subflags.do_count)
subflags.do_ask = FALSE;
save_do_all = subflags.do_all;
save_do_ask = subflags.do_ask;
/*
* check for a trailing count
*/
cmd = skipwhite(cmd);
if (VIM_ISDIGIT(*cmd))
{
i = getdigits(&cmd);
if (i <= 0 && !eap->skip && subflags.do_error)
{
emsg(_(e_positive_count_required));
return;
}
eap->line1 = eap->line2;
eap->line2 += i - 1;
if (eap->line2 > curbuf->b_ml.ml_line_count)
eap->line2 = curbuf->b_ml.ml_line_count;
}
/*
* check for trailing command or garbage
*/
cmd = skipwhite(cmd);
if (*cmd && *cmd != '"') // if not end-of-line or comment
{
set_nextcmd(eap, cmd);
if (eap->nextcmd == NULL)
{
semsg(_(e_trailing_characters_str), cmd);
return;
}
}
if (eap->skip) // not executing commands, only parsing
return;
if (!subflags.do_count && !curbuf->b_p_ma)
{
// Substitution is not allowed in non-'modifiable' buffer
emsg(_(e_cannot_make_changes_modifiable_is_off));
return;
}
if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, ®match) == FAIL)
{
if (subflags.do_error)
emsg(_(e_invalid_command));
return;
}
// the 'i' or 'I' flag overrules 'ignorecase' and 'smartcase'
if (subflags.do_ic == 'i')
regmatch.rmm_ic = TRUE;
else if (subflags.do_ic == 'I')
regmatch.rmm_ic = FALSE;
sub_firstline = NULL;
/*
* ~ in the substitute pattern is replaced with the old pattern.
* We do it here once to avoid it to be replaced over and over again.
* But don't do it when it starts with "\=", then it's an expression.
*/
if (!(sub[0] == '\\' && sub[1] == '='))
sub = regtilde(sub, magic_isset());
/*
* Check for a match on each line.
*/
line2 = eap->line2;
for (lnum = eap->line1; lnum <= line2 && !(got_quit
#if defined(FEAT_EVAL)
|| aborting()
#endif
); ++lnum)
{
nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum,
(colnr_T)0, NULL, NULL);
if (nmatch)
{
colnr_T copycol;
colnr_T matchcol;
colnr_T prev_matchcol = MAXCOL;
char_u *new_end, *new_start = NULL;
unsigned new_start_len = 0;
char_u *p1;
int did_sub = FALSE;
int lastone;
int len, copy_len, needed_len;
long nmatch_tl = 0; // nr of lines matched below lnum
int do_again; // do it again after joining lines
int skip_match = FALSE;
linenr_T sub_firstlnum; // nr of first sub line
#ifdef FEAT_PROP_POPUP
int apc_flags = APC_SAVE_FOR_UNDO | APC_SUBSTITUTE;
colnr_T total_added = 0;
#endif
/*
* The new text is build up step by step, to avoid too much
* copying. There are these pieces:
* sub_firstline The old text, unmodified.
* copycol Column in the old text where we started
* looking for a match; from here old text still
* needs to be copied to the new text.
* matchcol Column number of the old text where to look
* for the next match. It's just after the
* previous match or one further.
* prev_matchcol Column just after the previous match (if any).
* Mostly equal to matchcol, except for the first
* match and after skipping an empty match.
* regmatch.*pos Where the pattern matched in the old text.
* new_start The new text, all that has been produced so
* far.
* new_end The new text, where to append new text.
*
* lnum The line number where we found the start of
* the match. Can be below the line we searched
* when there is a \n before a \zs in the
* pattern.
* sub_firstlnum The line number in the buffer where to look
* for a match. Can be different from "lnum"
* when the pattern or substitute string contains
* line breaks.
*
* Special situations:
* - When the substitute string contains a line break, the part up
* to the line break is inserted in the text, but the copy of
* the original line is kept. "sub_firstlnum" is adjusted for
* the inserted lines.
* - When the matched pattern contains a line break, the old line
* is taken from the line at the end of the pattern. The lines
* in the match are deleted later, "sub_firstlnum" is adjusted
* accordingly.
*
* The new text is built up in new_start[]. It has some extra
* room to avoid using alloc()/free() too often. new_start_len is
* the length of the allocated memory at new_start.
*
* Make a copy of the old line, so it won't be taken away when
* updating the screen or handling a multi-line match. The "old_"
* pointers point into this copy.
*/
sub_firstlnum = lnum;
copycol = 0;
matchcol = 0;
// At first match, remember current cursor position.
if (!got_match)
{
setpcmark();
got_match = TRUE;
}
/*
* Loop until nothing more to replace in this line.
* 1. Handle match with empty string.
* 2. If do_ask is set, ask for confirmation.
* 3. substitute the string.
* 4. if do_all is set, find next match
* 5. break if there isn't another match in this line
*/
for (;;)
{
// Advance "lnum" to the line where the match starts. The
// match does not start in the first line when there is a line
// break before \zs.
if (regmatch.startpos[0].lnum > 0)
{
lnum += regmatch.startpos[0].lnum;
sub_firstlnum += regmatch.startpos[0].lnum;
nmatch -= regmatch.startpos[0].lnum;
VIM_CLEAR(sub_firstline);
}
// Match might be after the last line for "\n\zs" matching at
// the end of the last line.
if (lnum > curbuf->b_ml.ml_line_count)
break;
if (sub_firstline == NULL)
{
sub_firstline = vim_strsave(ml_get(sub_firstlnum));
if (sub_firstline == NULL)
{
vim_free(new_start);
goto outofmem;
}
}
// Save the line number of the last change for the final
// cursor position (just like Vi).
curwin->w_cursor.lnum = lnum;
do_again = FALSE;
/*
* 1. Match empty string does not count, except for first
* match. This reproduces the strange vi behaviour.
* This also catches endless loops.
*/
if (matchcol == prev_matchcol
&& regmatch.endpos[0].lnum == 0
&& matchcol == regmatch.endpos[0].col)
{
if (sub_firstline[matchcol] == NUL)
// We already were at the end of the line. Don't look
// for a match in this line again.
skip_match = TRUE;
else
{
// search for a match at next column
if (has_mbyte)
matchcol += mb_ptr2len(sub_firstline + matchcol);
else
++matchcol;
}
goto skip;
}
// Normally we continue searching for a match just after the
// previous match.
matchcol = regmatch.endpos[0].col;
prev_matchcol = matchcol;
/*
* 2. If do_count is set only increase the counter.
* If do_ask is set, ask for confirmation.
*/
if (subflags.do_count)
{
// For a multi-line match, put matchcol at the NUL at
// the end of the line and set nmatch to one, so that
// we continue looking for a match on the next line.
// Avoids that ":s/\nB\@=//gc" get stuck.
if (nmatch > 1)
{
matchcol = (colnr_T)STRLEN(sub_firstline);
nmatch = 1;
skip_match = TRUE;
}
sub_nsubs++;
did_sub = TRUE;
#ifdef FEAT_EVAL
// Skip the substitution, unless an expression is used,
// then it is evaluated in the sandbox.
if (!(sub[0] == '\\' && sub[1] == '='))
#endif
goto skip;
}
if (subflags.do_ask)
{
int typed = 0;
// change State to CONFIRM, so that the mouse works
// properly
save_State = State;
State = CONFIRM;
setmouse(); // disable mouse in xterm
curwin->w_cursor.col = regmatch.startpos[0].col;
if (curwin->w_p_crb)
do_check_cursorbind();
// When 'cpoptions' contains "u" don't sync undo when
// asking for confirmation.
if (vim_strchr(p_cpo, CPO_UNDO) != NULL)
++no_u_sync;
/*
* Loop until 'y', 'n', 'q', CTRL-E or CTRL-Y typed.
*/
while (subflags.do_ask)
{
if (exmode_active)
{
char_u *resp;
colnr_T sc, ec;
print_line_no_prefix(lnum,
subflags.do_number, subflags.do_list);
getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL);
curwin->w_cursor.col = regmatch.endpos[0].col - 1;
if (curwin->w_cursor.col < 0)
curwin->w_cursor.col = 0;
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &ec);
curwin->w_cursor.col = regmatch.startpos[0].col;
if (subflags.do_number || curwin->w_p_nu)
{
int numw = number_width(curwin) + 1;
sc += numw;
ec += numw;
}
msg_start();
for (i = 0; i < (long)sc; ++i)
msg_putchar(' ');
for ( ; i <= (long)ec; ++i)
msg_putchar('^');
resp = getexmodeline('?', NULL, 0, TRUE);
if (resp != NULL)
{
typed = *resp;
vim_free(resp);
}
}
else
{
char_u *orig_line = NULL;
int len_change = 0;
int save_p_lz = p_lz;
#ifdef FEAT_FOLDING
int save_p_fen = curwin->w_p_fen;
curwin->w_p_fen = FALSE;
#endif
// Invert the matched string.
// Remove the inversion afterwards.
temp = RedrawingDisabled;
RedrawingDisabled = 0;
// avoid calling update_screen() in vgetorpeek()
p_lz = FALSE;
if (new_start != NULL)
{
// There already was a substitution, we would
// like to show this to the user. We cannot
// really update the line, it would change
// what matches. Temporarily replace the line
// and change it back afterwards.
orig_line = vim_strsave(ml_get(lnum));
if (orig_line != NULL)
{
char_u *new_line = concat_str(new_start,
sub_firstline + copycol);
if (new_line == NULL)
VIM_CLEAR(orig_line);
else
{
// Position the cursor relative to the
// end of the line, the previous
// substitute may have inserted or
// deleted characters before the
// cursor.
len_change = (int)STRLEN(new_line)
- (int)STRLEN(orig_line);
curwin->w_cursor.col += len_change;
ml_replace(lnum, new_line, FALSE);
}
}
}
search_match_lines = regmatch.endpos[0].lnum
- regmatch.startpos[0].lnum;
search_match_endcol = regmatch.endpos[0].col
+ len_change;
highlight_match = TRUE;
update_topline();
validate_cursor();
update_screen(SOME_VALID);
highlight_match = FALSE;
redraw_later(SOME_VALID);
#ifdef FEAT_FOLDING
curwin->w_p_fen = save_p_fen;
#endif
if (msg_row == Rows - 1)
msg_didout = FALSE; // avoid a scroll-up
msg_starthere();
i = msg_scroll;
msg_scroll = 0; // truncate msg when
// needed
msg_no_more = TRUE;
// write message same highlighting as for
// wait_return
smsg_attr(HL_ATTR(HLF_R),
_("replace with %s (y/n/a/q/l/^E/^Y)?"), sub);
msg_no_more = FALSE;
msg_scroll = i;
showruler(TRUE);
windgoto(msg_row, msg_col);
RedrawingDisabled = temp;
#ifdef USE_ON_FLY_SCROLL
dont_scroll = FALSE; // allow scrolling here
#endif
++no_mapping; // don't map this key
++allow_keys; // allow special keys
typed = plain_vgetc();
--allow_keys;
--no_mapping;
// clear the question
msg_didout = FALSE; // don't scroll up
msg_col = 0;
gotocmdline(TRUE);
p_lz = save_p_lz;
// restore the line
if (orig_line != NULL)
ml_replace(lnum, orig_line, FALSE);
}
need_wait_return = FALSE; // no hit-return prompt
if (typed == 'q' || typed == ESC || typed == Ctrl_C
#ifdef UNIX
|| typed == intr_char
#endif
)
{
got_quit = TRUE;
break;
}
if (typed == 'n')
break;
if (typed == 'y')
break;
if (typed == 'l')
{
// last: replace and then stop
subflags.do_all = FALSE;
line2 = lnum;
break;
}
if (typed == 'a')
{
subflags.do_ask = FALSE;
break;
}
if (typed == Ctrl_E)
scrollup_clamp();
else if (typed == Ctrl_Y)
scrolldown_clamp();
}
State = save_State;
setmouse();
if (vim_strchr(p_cpo, CPO_UNDO) != NULL)
--no_u_sync;
if (typed == 'n')
{
// For a multi-line match, put matchcol at the NUL at
// the end of the line and set nmatch to one, so that
// we continue looking for a match on the next line.
// Avoids that ":%s/\nB\@=//gc" and ":%s/\n/,\r/gc"
// get stuck when pressing 'n'.
if (nmatch > 1)
{
matchcol = (colnr_T)STRLEN(sub_firstline);
skip_match = TRUE;
}
goto skip;
}
if (got_quit)
goto skip;
}
// Move the cursor to the start of the match, so that we can
// use "\=col(".").
curwin->w_cursor.col = regmatch.startpos[0].col;
/*
* 3. substitute the string.
*/
#ifdef FEAT_EVAL
save_ma = curbuf->b_p_ma;
if (subflags.do_count)
{
// prevent accidentally changing the buffer by a function
curbuf->b_p_ma = FALSE;
sandbox++;
}
// Save flags for recursion. They can change for e.g.
// :s/^/\=execute("s#^##gn")
subflags_save = subflags;
#endif
// get length of substitution part
sublen = vim_regsub_multi(®match,
sub_firstlnum - regmatch.startpos[0].lnum,
sub, sub_firstline, FALSE, magic_isset(), TRUE);
#ifdef FEAT_EVAL
// If getting the substitute string caused an error, don't do
// the replacement.
// Don't keep flags set by a recursive call.
subflags = subflags_save;
if (aborting() || subflags.do_count)
{
curbuf->b_p_ma = save_ma;
if (sandbox > 0)
sandbox--;
goto skip;
}
#endif
// When the match included the "$" of the last line it may
// go beyond the last line of the buffer.
if (nmatch > curbuf->b_ml.ml_line_count - sub_firstlnum + 1)
{
nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1;
skip_match = TRUE;
}
// Need room for:
// - result so far in new_start (not for first sub in line)
// - original text up to match
// - length of substituted part
// - original text after match
// Adjust text properties here, since we have all information
// needed.
if (nmatch == 1)
{
p1 = sub_firstline;
#ifdef FEAT_PROP_POPUP
if (curbuf->b_has_textprop)
{
int bytes_added = sublen - 1 - (regmatch.endpos[0].col
- regmatch.startpos[0].col);
// When text properties are changed, need to save for
// undo first, unless done already.
if (adjust_prop_columns(lnum,
total_added + regmatch.startpos[0].col,
bytes_added, apc_flags))
apc_flags &= ~APC_SAVE_FOR_UNDO;
// Offset for column byte number of the text property
// in the resulting buffer afterwards.
total_added += bytes_added;
}
#endif
}
else
{
p1 = ml_get(sub_firstlnum + nmatch - 1);
nmatch_tl += nmatch - 1;
}
copy_len = regmatch.startpos[0].col - copycol;
needed_len = copy_len + ((unsigned)STRLEN(p1)
- regmatch.endpos[0].col) + sublen + 1;
if (new_start == NULL)
{
/*
* Get some space for a temporary buffer to do the
* substitution into (and some extra space to avoid
* too many calls to alloc()/free()).
*/
new_start_len = needed_len + 50;
if ((new_start = alloc(new_start_len)) == NULL)
goto outofmem;
*new_start = NUL;
new_end = new_start;
}
else
{
/*
* Check if the temporary buffer is long enough to do the
* substitution into. If not, make it larger (with a bit
* extra to avoid too many calls to alloc()/free()).
*/
len = (unsigned)STRLEN(new_start);
needed_len += len;
if (needed_len > (int)new_start_len)
{
new_start_len = needed_len + 50;
if ((p1 = alloc(new_start_len)) == NULL)
{
vim_free(new_start);
goto outofmem;
}
mch_memmove(p1, new_start, (size_t)(len + 1));
vim_free(new_start);
new_start = p1;
}
new_end = new_start + len;
}
/*
* copy the text up to the part that matched
*/
mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len);
new_end += copy_len;
(void)vim_regsub_multi(®match,
sub_firstlnum - regmatch.startpos[0].lnum,
sub, new_end, TRUE, magic_isset(), TRUE);
sub_nsubs++;
did_sub = TRUE;
// Move the cursor to the start of the line, to avoid that it
// is beyond the end of the line after the substitution.
curwin->w_cursor.col = 0;
// For a multi-line match, make a copy of the last matched
// line and continue in that one.
if (nmatch > 1)
{
sub_firstlnum += nmatch - 1;
vim_free(sub_firstline);
sub_firstline = vim_strsave(ml_get(sub_firstlnum));
// When going beyond the last line, stop substituting.
if (sub_firstlnum <= line2)
do_again = TRUE;
else
subflags.do_all = FALSE;
}
// Remember next character to be copied.
copycol = regmatch.endpos[0].col;
if (skip_match)
{
// Already hit end of the buffer, sub_firstlnum is one
// less than what it ought to be.
vim_free(sub_firstline);
sub_firstline = vim_strsave((char_u *)"");
copycol = 0;
}
/*
* Now the trick is to replace CTRL-M chars with a real line
* break. This would make it impossible to insert a CTRL-M in
* the text. The line break can be avoided by preceding the
* CTRL-M with a backslash. To be able to insert a backslash,
* they must be doubled in the string and are halved here.
* That is Vi compatible.
*/
for (p1 = new_end; *p1; ++p1)
{
if (p1[0] == '\\' && p1[1] != NUL) // remove backslash
{
STRMOVE(p1, p1 + 1);
#ifdef FEAT_PROP_POPUP
if (curbuf->b_has_textprop)
{
// When text properties are changed, need to save
// for undo first, unless done already.
if (adjust_prop_columns(lnum,
(colnr_T)(p1 - new_start), -1,
apc_flags))
apc_flags &= ~APC_SAVE_FOR_UNDO;
}
#endif
}
else if (*p1 == CAR)
{
if (u_inssub(lnum) == OK) // prepare for undo
{
colnr_T plen = (colnr_T)(p1 - new_start + 1);
*p1 = NUL; // truncate up to the CR
ml_append(lnum - 1, new_start, plen, FALSE);
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
if (subflags.do_ask)
appended_lines(lnum - 1, 1L);
else
{
if (first_line == 0)
first_line = lnum;
last_line = lnum + 1;
}
#ifdef FEAT_PROP_POPUP
adjust_props_for_split(lnum + 1, lnum, plen, 1);
#endif
// all line numbers increase
++sub_firstlnum;
++lnum;
++line2;
// move the cursor to the new line, like Vi
++curwin->w_cursor.lnum;
// copy the rest
STRMOVE(new_start, p1 + 1);
p1 = new_start - 1;
}
}
else if (has_mbyte)
p1 += (*mb_ptr2len)(p1) - 1;
}
/*
* 4. If do_all is set, find next match.
* Prevent endless loop with patterns that match empty
* strings, e.g. :s/$/pat/g or :s/[a-z]* /(&)/g.
* But ":s/\n/#/" is OK.
*/
skip:
// We already know that we did the last subst when we are at
// the end of the line, except that a pattern like
// "bar\|\nfoo" may match at the NUL. "lnum" can be below
// "line2" when there is a \zs in the pattern after a line
// break.
lastone = (skip_match
|| got_int
|| got_quit
|| lnum > line2
|| !(subflags.do_all || do_again)
|| (sub_firstline[matchcol] == NUL && nmatch <= 1
&& !re_multiline(regmatch.regprog)));
nmatch = -1;
/*
* Replace the line in the buffer when needed. This is
* skipped when there are more matches.
* The check for nmatch_tl is needed for when multi-line
* matching must replace the lines before trying to do another
* match, otherwise "\@<=" won't work.
* When the match starts below where we start searching also
* need to replace the line first (using \zs after \n).
*/
if (lastone
|| nmatch_tl > 0
|| (nmatch = vim_regexec_multi(®match, curwin,
curbuf, sub_firstlnum,
matchcol, NULL, NULL)) == 0
|| regmatch.startpos[0].lnum > 0)
{
if (new_start != NULL)
{
/*
* Copy the rest of the line, that didn't match.
* "matchcol" has to be adjusted, we use the end of
* the line as reference, because the substitute may
* have changed the number of characters. Same for
* "prev_matchcol".
*/
STRCAT(new_start, sub_firstline + copycol);
matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol;
prev_matchcol = (colnr_T)STRLEN(sub_firstline)
- prev_matchcol;
if (u_savesub(lnum) != OK)
break;
ml_replace(lnum, new_start, TRUE);
if (nmatch_tl > 0)
{
/*
* Matched lines have now been substituted and are
* useless, delete them. The part after the match
* has been appended to new_start, we don't need
* it in the buffer.
*/
++lnum;
if (u_savedel(lnum, nmatch_tl) != OK)
break;
for (i = 0; i < nmatch_tl; ++i)
ml_delete(lnum);
mark_adjust(lnum, lnum + nmatch_tl - 1,
(long)MAXLNUM, -nmatch_tl);
if (subflags.do_ask)
deleted_lines(lnum, nmatch_tl);
--lnum;
line2 -= nmatch_tl; // nr of lines decreases
nmatch_tl = 0;
}
// When asking, undo is saved each time, must also set
// changed flag each time.
if (subflags.do_ask)
changed_bytes(lnum, 0);
else
{
if (first_line == 0)
first_line = lnum;
last_line = lnum + 1;
}
sub_firstlnum = lnum;
vim_free(sub_firstline); // free the temp buffer
sub_firstline = new_start;
new_start = NULL;
matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol;
prev_matchcol = (colnr_T)STRLEN(sub_firstline)
- prev_matchcol;
copycol = 0;
}
if (nmatch == -1 && !lastone)
nmatch = vim_regexec_multi(®match, curwin, curbuf,
sub_firstlnum, matchcol, NULL, NULL);
/*
* 5. break if there isn't another match in this line
*/
if (nmatch <= 0)
{
// If the match found didn't start where we were
// searching, do the next search in the line where we
// found the match.
if (nmatch == -1)
lnum -= regmatch.startpos[0].lnum;
break;
}
}
line_breakcheck();
}
if (did_sub)
++sub_nlines;
vim_free(new_start); // for when substitute was cancelled
VIM_CLEAR(sub_firstline); // free the copy of the original line
}
line_breakcheck();
}
if (first_line != 0)
{
// Need to subtract the number of added lines from "last_line" to get
// the line number before the change (same as adding the number of
// deleted lines).
i = curbuf->b_ml.ml_line_count - old_line_count;
changed_lines(first_line, 0, last_line - i, i);
}
outofmem:
vim_free(sub_firstline); // may have to free allocated copy of the line
// ":s/pat//n" doesn't move the cursor
if (subflags.do_count)
curwin->w_cursor = old_cursor;
if (sub_nsubs > start_nsubs)
{
if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
{
// Set the '[ and '] marks.
curbuf->b_op_start.lnum = eap->line1;
curbuf->b_op_end.lnum = line2;
curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
}
if (!global_busy)
{
// when interactive leave cursor on the match
if (!subflags.do_ask)
{
if (endcolumn)
coladvance((colnr_T)MAXCOL);
else
beginline(BL_WHITE | BL_FIX);
}
if (!do_sub_msg(subflags.do_count) && subflags.do_ask)
msg("");
}
else
global_need_beginline = TRUE;
if (subflags.do_print)
print_line(curwin->w_cursor.lnum,
subflags.do_number, subflags.do_list);
}
else if (!global_busy)
{
if (got_int) // interrupted
emsg(_(e_interrupted));
else if (got_match) // did find something but nothing substituted
msg("");
else if (subflags.do_error) // nothing found
semsg(_(e_pattern_not_found_str), get_search_pat());
}
#ifdef FEAT_FOLDING
if (subflags.do_ask && hasAnyFolding(curwin))
// Cursor position may require updating
changed_window_setting();
#endif
vim_regfree(regmatch.regprog);
// Restore the flag values, they can be used for ":&&".
subflags.do_all = save_do_all;
subflags.do_ask = save_do_ask;
} | 3953 | True | 1 |
CVE-2022-0443 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/9b4a80a66544f2782040b641498754bcb5b8d461', 'name': 'https://github.com/vim/vim/commit/9b4a80a66544f2782040b641498754bcb5b8d461', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/b987c8cb-bbbe-4601-8a6c-54ff907c6b51', 'name': 'https://huntr.dev/bounties/b987c8cb-bbbe-4601-8a6c-54ff907c6b51', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UFXFAILMLUIK4MBUEZO4HNBNKYZRJ5AP/', 'name': 'FEDORA-2022-da2fb07efb', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/05/msg00022.html', 'name': '[debian-lts-announce] 20220516 [SECURITY] [DLA 3011-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4281', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T08:15Z | 2022-02-02T21:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-02-01 13:54:17+00:00 | patch 8.2.4281: using freed memory with :lopen and :bwipe
Problem: Using freed memory with :lopen and :bwipe.
Solution: Do not use a wiped out buffer. | 9b4a80a66544f2782040b641498754bcb5b8d461 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | free_buf_options | free_buf_options( buf_T * buf , int free_p_ff) | ['buf', 'free_p_ff'] | free_buf_options(
buf_T *buf,
int free_p_ff)
{
if (free_p_ff)
{
clear_string_option(&buf->b_p_fenc);
clear_string_option(&buf->b_p_ff);
clear_string_option(&buf->b_p_bh);
clear_string_option(&buf->b_p_bt);
}
#ifdef FEAT_FIND_ID
clear_string_option(&buf->b_p_def);
clear_string_option(&buf->b_p_inc);
# ifdef FEAT_EVAL
clear_string_option(&buf->b_p_inex);
# endif
#endif
#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
clear_string_option(&buf->b_p_inde);
clear_string_option(&buf->b_p_indk);
#endif
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
clear_string_option(&buf->b_p_bexpr);
#endif
#if defined(FEAT_CRYPT)
clear_string_option(&buf->b_p_cm);
#endif
clear_string_option(&buf->b_p_fp);
#if defined(FEAT_EVAL)
clear_string_option(&buf->b_p_fex);
#endif
#ifdef FEAT_CRYPT
# ifdef FEAT_SODIUM
if ((buf->b_p_key != NULL) && (*buf->b_p_key != NUL) &&
(crypt_get_method_nr(buf) == CRYPT_M_SOD))
crypt_sodium_munlock(buf->b_p_key, STRLEN(buf->b_p_key));
# endif
clear_string_option(&buf->b_p_key);
#endif
clear_string_option(&buf->b_p_kp);
clear_string_option(&buf->b_p_mps);
clear_string_option(&buf->b_p_fo);
clear_string_option(&buf->b_p_flp);
clear_string_option(&buf->b_p_isk);
#ifdef FEAT_VARTABS
clear_string_option(&buf->b_p_vsts);
vim_free(buf->b_p_vsts_nopaste);
buf->b_p_vsts_nopaste = NULL;
vim_free(buf->b_p_vsts_array);
buf->b_p_vsts_array = NULL;
clear_string_option(&buf->b_p_vts);
VIM_CLEAR(buf->b_p_vts_array);
#endif
#ifdef FEAT_KEYMAP
clear_string_option(&buf->b_p_keymap);
keymap_clear(&buf->b_kmap_ga);
ga_clear(&buf->b_kmap_ga);
#endif
clear_string_option(&buf->b_p_com);
#ifdef FEAT_FOLDING
clear_string_option(&buf->b_p_cms);
#endif
clear_string_option(&buf->b_p_nf);
#ifdef FEAT_SYN_HL
clear_string_option(&buf->b_p_syn);
clear_string_option(&buf->b_s.b_syn_isk);
#endif
#ifdef FEAT_SPELL
clear_string_option(&buf->b_s.b_p_spc);
clear_string_option(&buf->b_s.b_p_spf);
vim_regfree(buf->b_s.b_cap_prog);
buf->b_s.b_cap_prog = NULL;
clear_string_option(&buf->b_s.b_p_spl);
clear_string_option(&buf->b_s.b_p_spo);
#endif
#ifdef FEAT_SEARCHPATH
clear_string_option(&buf->b_p_sua);
#endif
clear_string_option(&buf->b_p_ft);
#ifdef FEAT_CINDENT
clear_string_option(&buf->b_p_cink);
clear_string_option(&buf->b_p_cino);
#endif
#if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
clear_string_option(&buf->b_p_cinw);
#endif
clear_string_option(&buf->b_p_cpt);
#ifdef FEAT_COMPL_FUNC
clear_string_option(&buf->b_p_cfu);
free_callback(&buf->b_cfu_cb);
clear_string_option(&buf->b_p_ofu);
free_callback(&buf->b_ofu_cb);
clear_string_option(&buf->b_p_tsrfu);
free_callback(&buf->b_tsrfu_cb);
#endif
#ifdef FEAT_QUICKFIX
clear_string_option(&buf->b_p_gp);
clear_string_option(&buf->b_p_mp);
clear_string_option(&buf->b_p_efm);
#endif
clear_string_option(&buf->b_p_ep);
clear_string_option(&buf->b_p_path);
clear_string_option(&buf->b_p_tags);
clear_string_option(&buf->b_p_tc);
#ifdef FEAT_EVAL
clear_string_option(&buf->b_p_tfu);
free_callback(&buf->b_tfu_cb);
#endif
clear_string_option(&buf->b_p_dict);
clear_string_option(&buf->b_p_tsr);
#ifdef FEAT_TEXTOBJ
clear_string_option(&buf->b_p_qe);
#endif
buf->b_p_ar = -1;
buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
#ifdef FEAT_LISP
clear_string_option(&buf->b_p_lw);
#endif
clear_string_option(&buf->b_p_bkc);
clear_string_option(&buf->b_p_menc);
} | 612 | True | 1 |
CVE-2022-0443 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/9b4a80a66544f2782040b641498754bcb5b8d461', 'name': 'https://github.com/vim/vim/commit/9b4a80a66544f2782040b641498754bcb5b8d461', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/b987c8cb-bbbe-4601-8a6c-54ff907c6b51', 'name': 'https://huntr.dev/bounties/b987c8cb-bbbe-4601-8a6c-54ff907c6b51', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UFXFAILMLUIK4MBUEZO4HNBNKYZRJ5AP/', 'name': 'FEDORA-2022-da2fb07efb', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/05/msg00022.html', 'name': '[debian-lts-announce] 20220516 [SECURITY] [DLA 3011-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4281', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T08:15Z | 2022-02-02T21:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-02-01 13:54:17+00:00 | patch 8.2.4281: using freed memory with :lopen and :bwipe
Problem: Using freed memory with :lopen and :bwipe.
Solution: Do not use a wiped out buffer. | 9b4a80a66544f2782040b641498754bcb5b8d461 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | set_curbuf | set_curbuf( buf_T * buf , int action) | ['buf', 'action'] | set_curbuf(buf_T *buf, int action)
{
buf_T *prevbuf;
int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
|| action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE);
#ifdef FEAT_SYN_HL
long old_tw = curbuf->b_p_tw;
#endif
bufref_T newbufref;
bufref_T prevbufref;
setpcmark();
if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0)
curwin->w_alt_fnum = curbuf->b_fnum; // remember alternate file
buflist_altfpos(curwin); // remember curpos
// Don't restart Select mode after switching to another buffer.
VIsual_reselect = FALSE;
// close_windows() or apply_autocmds() may change curbuf and wipe out "buf"
prevbuf = curbuf;
set_bufref(&prevbufref, prevbuf);
set_bufref(&newbufref, buf);
// Autocommands may delete the current buffer and/or the buffer we want to
// go to. In those cases don't close the buffer.
if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf)
|| (bufref_valid(&prevbufref)
&& bufref_valid(&newbufref)
#ifdef FEAT_EVAL
&& !aborting()
#endif
))
{
#ifdef FEAT_SYN_HL
if (prevbuf == curwin->w_buffer)
reset_synblock(curwin);
#endif
if (unload)
close_windows(prevbuf, FALSE);
#if defined(FEAT_EVAL)
if (bufref_valid(&prevbufref) && !aborting())
#else
if (bufref_valid(&prevbufref))
#endif
{
win_T *previouswin = curwin;
// Do not sync when in Insert mode and the buffer is open in
// another window, might be a timer doing something in another
// window.
if (prevbuf == curbuf
&& ((State & INSERT) == 0 || curbuf->b_nwindows <= 1))
u_sync(FALSE);
close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf,
unload ? action : (action == DOBUF_GOTO
&& !buf_hide(prevbuf)
&& !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0,
FALSE, FALSE);
if (curwin != previouswin && win_valid(previouswin))
// autocommands changed curwin, Grr!
curwin = previouswin;
}
}
// An autocommand may have deleted "buf", already entered it (e.g., when
// it did ":bunload") or aborted the script processing.
// If curwin->w_buffer is null, enter_buffer() will make it valid again
if ((buf_valid(buf) && buf != curbuf
#ifdef FEAT_EVAL
&& !aborting()
#endif
) || curwin->w_buffer == NULL)
{
enter_buffer(buf);
#ifdef FEAT_SYN_HL
if (old_tw != curbuf->b_p_tw)
check_colorcolumn(curwin);
#endif
}
} | 323 | True | 1 |
CVE-2022-0554 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/e3537aec2f8d6470010547af28dcbd83d41461b8', 'name': 'https://github.com/vim/vim/commit/e3537aec2f8d6470010547af28dcbd83d41461b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7e8f6cd0-b5ee-48a2-8255-6a86f4c46c71', 'name': 'https://huntr.dev/bounties/7e8f6cd0-b5ee-48a2-8255-6a86f4c46c71', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/03/msg00018.html', 'name': '[debian-lts-announce] 20220311 [SECURITY] [DLA 2947-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-823'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4327', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use of Out-of-range Pointer Offset in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T17:31Z | 2022-02-10T22:15Z | Use of Out-of-range Pointer Offset | The program performs pointer arithmetic on a valid pointer, but it uses an offset that can point outside of the intended range of valid memory locations for the resulting pointer. |
While a pointer can contain a reference to any arbitrary memory location, a program typically only intends to use the pointer to access limited portions of memory, such as contiguous memory used to access an individual array.
Programs may use offsets in order to access fields or sub-elements stored within structured data. The offset might be out-of-range if it comes from an untrusted source, is the result of an incorrect calculation, or occurs because of another error.
If an attacker can control or influence the offset so that it points outside of the intended boundaries of the structure, then the attacker may be able to read or write to memory locations that are used elsewhere in the program. As a result, the attack might change the state of the software as accessed through program variables, cause a crash or instable behavior, and possibly lead to code execution.
| https://cwe.mitre.org/data/definitions/823.html | 0 | Bram Moolenaar | 2022-02-08 15:05:20+00:00 | patch 8.2.4327: may end up with no current buffer
Problem: May end up with no current buffer.
Solution: When deleting the current buffer to not pick a quickfix buffer as
the new current buffer. | e3537aec2f8d6470010547af28dcbd83d41461b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | do_buffer_ext | do_buffer_ext( int action , int start , int dir , int count , int flags) | ['action', 'start', 'dir', 'count', 'flags'] | do_buffer_ext(
int action,
int start,
int dir, // FORWARD or BACKWARD
int count, // buffer number or number of buffers
int flags) // DOBUF_FORCEIT etc.
{
buf_T *buf;
buf_T *bp;
int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
|| action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE);
switch (start)
{
case DOBUF_FIRST: buf = firstbuf; break;
case DOBUF_LAST: buf = lastbuf; break;
default: buf = curbuf; break;
}
if (start == DOBUF_MOD) // find next modified buffer
{
while (count-- > 0)
{
do
{
buf = buf->b_next;
if (buf == NULL)
buf = firstbuf;
}
while (buf != curbuf && !bufIsChanged(buf));
}
if (!bufIsChanged(buf))
{
emsg(_(e_no_modified_buffer_found));
return FAIL;
}
}
else if (start == DOBUF_FIRST && count) // find specified buffer number
{
while (buf != NULL && buf->b_fnum != count)
buf = buf->b_next;
}
else
{
bp = NULL;
while (count > 0 || (!unload && !buf->b_p_bl && bp != buf))
{
// remember the buffer where we start, we come back there when all
// buffers are unlisted.
if (bp == NULL)
bp = buf;
if (dir == FORWARD)
{
buf = buf->b_next;
if (buf == NULL)
buf = firstbuf;
}
else
{
buf = buf->b_prev;
if (buf == NULL)
buf = lastbuf;
}
// don't count unlisted buffers
if (unload || buf->b_p_bl)
{
--count;
bp = NULL; // use this buffer as new starting point
}
if (bp == buf)
{
// back where we started, didn't find anything.
emsg(_(e_there_is_no_listed_buffer));
return FAIL;
}
}
}
if (buf == NULL) // could not find it
{
if (start == DOBUF_FIRST)
{
// don't warn when deleting
if (!unload)
semsg(_(e_buffer_nr_does_not_exist), count);
}
else if (dir == FORWARD)
emsg(_(e_cannot_go_beyond_last_buffer));
else
emsg(_(e_cannot_go_before_first_buffer));
return FAIL;
}
#ifdef FEAT_PROP_POPUP
if ((flags & DOBUF_NOPOPUP) && bt_popup(buf)
# ifdef FEAT_TERMINAL
&& !bt_terminal(buf)
#endif
)
return OK;
#endif
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
/*
* delete buffer "buf" from memory and/or the list
*/
if (unload)
{
int forward;
bufref_T bufref;
if (!can_unload_buffer(buf))
return FAIL;
set_bufref(&bufref, buf);
// When unloading or deleting a buffer that's already unloaded and
// unlisted: fail silently.
if (action != DOBUF_WIPE && action != DOBUF_WIPE_REUSE
&& buf->b_ml.ml_mfp == NULL && !buf->b_p_bl)
return FAIL;
if ((flags & DOBUF_FORCEIT) == 0 && bufIsChanged(buf))
{
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write)
{
dialog_changed(buf, FALSE);
if (!bufref_valid(&bufref))
// Autocommand deleted buffer, oops! It's not changed
// now.
return FAIL;
// If it's still changed fail silently, the dialog already
// mentioned why it fails.
if (bufIsChanged(buf))
return FAIL;
}
else
#endif
{
semsg(_(e_no_write_since_last_change_for_buffer_nr_add_bang_to_override),
buf->b_fnum);
return FAIL;
}
}
// When closing the current buffer stop Visual mode.
if (buf == curbuf && VIsual_active)
end_visual_mode();
// If deleting the last (listed) buffer, make it empty.
// The last (listed) buffer cannot be unloaded.
FOR_ALL_BUFFERS(bp)
if (bp->b_p_bl && bp != buf)
break;
if (bp == NULL && buf == curbuf)
return empty_curbuf(TRUE, (flags & DOBUF_FORCEIT), action);
// If the deleted buffer is the current one, close the current window
// (unless it's the only window). Repeat this so long as we end up in
// a window with this buffer.
while (buf == curbuf
&& !(curwin->w_closing || curwin->w_buffer->b_locked > 0)
&& (!ONE_WINDOW || first_tabpage->tp_next != NULL))
{
if (win_close(curwin, FALSE) == FAIL)
break;
}
// If the buffer to be deleted is not the current one, delete it here.
if (buf != curbuf)
{
close_windows(buf, FALSE);
if (buf != curbuf && bufref_valid(&bufref) && buf->b_nwindows <= 0)
close_buffer(NULL, buf, action, FALSE, FALSE);
return OK;
}
/*
* Deleting the current buffer: Need to find another buffer to go to.
* There should be another, otherwise it would have been handled
* above. However, autocommands may have deleted all buffers.
* First use au_new_curbuf.br_buf, if it is valid.
* Then prefer the buffer we most recently visited.
* Else try to find one that is loaded, after the current buffer,
* then before the current buffer.
* Finally use any buffer.
*/
buf = NULL; // selected buffer
bp = NULL; // used when no loaded buffer found
if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf))
buf = au_new_curbuf.br_buf;
else if (curwin->w_jumplistlen > 0)
{
int jumpidx;
jumpidx = curwin->w_jumplistidx - 1;
if (jumpidx < 0)
jumpidx = curwin->w_jumplistlen - 1;
forward = jumpidx;
while (jumpidx != curwin->w_jumplistidx)
{
buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum);
if (buf != NULL)
{
if (buf == curbuf || !buf->b_p_bl)
buf = NULL; // skip current and unlisted bufs
else if (buf->b_ml.ml_mfp == NULL)
{
// skip unloaded buf, but may keep it for later
if (bp == NULL)
bp = buf;
buf = NULL;
}
}
if (buf != NULL) // found a valid buffer: stop searching
break;
// advance to older entry in jump list
if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen)
break;
if (--jumpidx < 0)
jumpidx = curwin->w_jumplistlen - 1;
if (jumpidx == forward) // List exhausted for sure
break;
}
}
if (buf == NULL) // No previous buffer, Try 2'nd approach
{
forward = TRUE;
buf = curbuf->b_next;
for (;;)
{
if (buf == NULL)
{
if (!forward) // tried both directions
break;
buf = curbuf->b_prev;
forward = FALSE;
continue;
}
// in non-help buffer, try to skip help buffers, and vv
if (buf->b_help == curbuf->b_help && buf->b_p_bl)
{
if (buf->b_ml.ml_mfp != NULL) // found loaded buffer
break;
if (bp == NULL) // remember unloaded buf for later
bp = buf;
}
if (forward)
buf = buf->b_next;
else
buf = buf->b_prev;
}
}
if (buf == NULL) // No loaded buffer, use unloaded one
buf = bp;
if (buf == NULL) // No loaded buffer, find listed one
{
FOR_ALL_BUFFERS(buf)
if (buf->b_p_bl && buf != curbuf)
break;
}
if (buf == NULL) // Still no buffer, just take one
{
if (curbuf->b_next != NULL)
buf = curbuf->b_next;
else
buf = curbuf->b_prev;
}
}
if (buf == NULL)
{
// Autocommands must have wiped out all other buffers. Only option
// now is to make the current buffer empty.
return empty_curbuf(FALSE, (flags & DOBUF_FORCEIT), action);
}
/*
* make "buf" the current buffer
*/
if (action == DOBUF_SPLIT) // split window first
{
// If 'switchbuf' contains "useopen": jump to first window containing
// "buf" if one exists
if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf))
return OK;
// If 'switchbuf' contains "usetab": jump to first window in any tab
// page containing "buf" if one exists
if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf))
return OK;
if (win_split(0, 0) == FAIL)
return FAIL;
}
// go to current buffer - nothing to do
if (buf == curbuf)
return OK;
// Check if the current buffer may be abandoned.
if (action == DOBUF_GOTO && !can_abandon(curbuf, (flags & DOBUF_FORCEIT)))
{
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write)
{
bufref_T bufref;
set_bufref(&bufref, buf);
dialog_changed(curbuf, FALSE);
if (!bufref_valid(&bufref))
// Autocommand deleted buffer, oops!
return FAIL;
}
if (bufIsChanged(curbuf))
#endif
{
no_write_message();
return FAIL;
}
}
// Go to the other buffer.
set_curbuf(buf, action);
if (action == DOBUF_SPLIT)
RESET_BINDING(curwin); // reset 'scrollbind' and 'cursorbind'
#if defined(FEAT_EVAL)
if (aborting()) // autocmds may abort script processing
return FAIL;
#endif
return OK;
} | 1227 | True | 1 |
CVE-2022-0629 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/34f8117dec685ace52cd9e578e2729db278163fc', 'name': 'https://github.com/vim/vim/commit/34f8117dec685ace52cd9e578e2729db278163fc', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/95e2b0da-e480-4ee8-9324-a93a2ab0a877', 'name': 'https://huntr.dev/bounties/95e2b0da-e480-4ee8-9324-a93a2ab0a877', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UURGABNDL77YR5FRQKTFBYNBDQX2KO7Q/', 'name': 'FEDORA-2022-8622ebdebb', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-121'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4397', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Stack-based Buffer Overflow in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T17:32Z | 2022-02-17T12:15Z | Stack-based Buffer Overflow | A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function). | https://cwe.mitre.org/data/definitions/121.html | 0 | Bram Moolenaar | 2022-02-16 12:16:19+00:00 | patch 8.2.4397: crash when using many composing characters in error message
Problem: Crash when using many composing characters in error message.
Solution: Use mb_cptr2char_adv() instead of mb_ptr2char_adv(). | 34f8117dec685ace52cd9e578e2729db278163fc | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ga_concat_shorten_esc | ga_concat_shorten_esc( garray_T * gap , char_u * str) | ['gap', 'str'] | ga_concat_shorten_esc(garray_T *gap, char_u *str)
{
char_u *p;
char_u *s;
int c;
int clen;
char_u buf[NUMBUFLEN];
int same_len;
if (str == NULL)
{
ga_concat(gap, (char_u *)"NULL");
return;
}
for (p = str; *p != NUL; ++p)
{
same_len = 1;
s = p;
c = mb_ptr2char_adv(&s);
clen = s - p;
while (*s != NUL && c == mb_ptr2char(s))
{
++same_len;
s += clen;
}
if (same_len > 20)
{
ga_concat(gap, (char_u *)"\\[");
ga_concat_esc(gap, p, clen);
ga_concat(gap, (char_u *)" occurs ");
vim_snprintf((char *)buf, NUMBUFLEN, "%d", same_len);
ga_concat(gap, buf);
ga_concat(gap, (char_u *)" times]");
p = s - 1;
}
else
ga_concat_esc(gap, p, clen);
}
} | 205 | True | 1 |
|
CVE-2022-0685 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/27230da3-9b1a-4d5d-8cdf-4b1e62fcd782', 'name': 'https://huntr.dev/bounties/27230da3-9b1a-4d5d-8cdf-4b1e62fcd782', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/5921aeb5741fc6e84c870d68c7c35b93ad0c9f87', 'name': 'https://github.com/vim/vim/commit/5921aeb5741fc6e84c870d68c7c35b93ad0c9f87', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/03/msg00018.html', 'name': '[debian-lts-announce] 20220311 [SECURITY] [DLA 2947-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-823'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4418', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use of Out-of-range Pointer Offset in GitHub repository vim/vim prior to 8.2.4418.'}] | 2022-08-26T17:32Z | 2022-02-20T11:15Z | Use of Out-of-range Pointer Offset | The program performs pointer arithmetic on a valid pointer, but it uses an offset that can point outside of the intended range of valid memory locations for the resulting pointer. |
While a pointer can contain a reference to any arbitrary memory location, a program typically only intends to use the pointer to access limited portions of memory, such as contiguous memory used to access an individual array.
Programs may use offsets in order to access fields or sub-elements stored within structured data. The offset might be out-of-range if it comes from an untrusted source, is the result of an incorrect calculation, or occurs because of another error.
If an attacker can control or influence the offset so that it points outside of the intended boundaries of the structure, then the attacker may be able to read or write to memory locations that are used elsewhere in the program. As a result, the attack might change the state of the software as accessed through program variables, cause a crash or instable behavior, and possibly lead to code execution.
| https://cwe.mitre.org/data/definitions/823.html | 0 | Bram Moolenaar | 2022-02-19 11:20:12+00:00 | patch 8.2.4418: crash when using special multi-byte character
Problem: Crash when using special multi-byte character.
Solution: Don't use isalpha() for an arbitrary character. | 5921aeb5741fc6e84c870d68c7c35b93ad0c9f87 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | unix_expandpath | unix_expandpath( garray_T * gap , char_u * path , int wildoff , int flags , int didstar) | ['gap', 'path', 'wildoff', 'flags', 'didstar'] | unix_expandpath(
garray_T *gap,
char_u *path,
int wildoff,
int flags, // EW_* flags
int didstar) // expanded "**" once already
{
char_u *buf;
char_u *path_end;
char_u *p, *s, *e;
int start_len = gap->ga_len;
char_u *pat;
regmatch_T regmatch;
int starts_with_dot;
int matches;
int len;
int starstar = FALSE;
static int stardepth = 0; // depth for "**" expansion
DIR *dirp;
struct dirent *dp;
// Expanding "**" may take a long time, check for CTRL-C.
if (stardepth > 0)
{
ui_breakcheck();
if (got_int)
return 0;
}
// make room for file name
buf = alloc(STRLEN(path) + BASENAMELEN + 5);
if (buf == NULL)
return 0;
/*
* Find the first part in the path name that contains a wildcard.
* When EW_ICASE is set every letter is considered to be a wildcard.
* Copy it into "buf", including the preceding characters.
*/
p = buf;
s = buf;
e = NULL;
path_end = path;
while (*path_end != NUL)
{
// May ignore a wildcard that has a backslash before it; it will
// be removed by rem_backslash() or file_pat_to_reg_pat() below.
if (path_end >= path + wildoff && rem_backslash(path_end))
*p++ = *path_end++;
else if (*path_end == '/')
{
if (e != NULL)
break;
s = p + 1;
}
else if (path_end >= path + wildoff
&& (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL
|| (!p_fic && (flags & EW_ICASE)
&& isalpha(PTR2CHAR(path_end)))))
e = p;
if (has_mbyte)
{
len = (*mb_ptr2len)(path_end);
STRNCPY(p, path_end, len);
p += len;
path_end += len;
}
else
*p++ = *path_end++;
}
e = p;
*e = NUL;
// Now we have one wildcard component between "s" and "e".
// Remove backslashes between "wildoff" and the start of the wildcard
// component.
for (p = buf + wildoff; p < s; ++p)
if (rem_backslash(p))
{
STRMOVE(p, p + 1);
--e;
--s;
}
// Check for "**" between "s" and "e".
for (p = s; p < e; ++p)
if (p[0] == '*' && p[1] == '*')
starstar = TRUE;
// convert the file pattern to a regexp pattern
starts_with_dot = *s == '.';
pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
if (pat == NULL)
{
vim_free(buf);
return 0;
}
// compile the regexp into a program
if (flags & EW_ICASE)
regmatch.rm_ic = TRUE; // 'wildignorecase' set
else
regmatch.rm_ic = p_fic; // ignore case when 'fileignorecase' is set
if (flags & (EW_NOERROR | EW_NOTWILD))
++emsg_silent;
regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
if (flags & (EW_NOERROR | EW_NOTWILD))
--emsg_silent;
vim_free(pat);
if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0)
{
vim_free(buf);
return 0;
}
// If "**" is by itself, this is the first time we encounter it and more
// is following then find matches without any directory.
if (!didstar && stardepth < 100 && starstar && e - s == 2
&& *path_end == '/')
{
STRCPY(s, path_end + 1);
++stardepth;
(void)unix_expandpath(gap, buf, (int)(s - buf), flags, TRUE);
--stardepth;
}
// open the directory for scanning
*s = NUL;
dirp = opendir(*buf == NUL ? "." : (char *)buf);
// Find all matching entries
if (dirp != NULL)
{
for (;;)
{
dp = readdir(dirp);
if (dp == NULL)
break;
if ((dp->d_name[0] != '.' || starts_with_dot
|| ((flags & EW_DODOT)
&& dp->d_name[1] != NUL
&& (dp->d_name[1] != '.' || dp->d_name[2] != NUL)))
&& ((regmatch.regprog != NULL && vim_regexec(®match,
(char_u *)dp->d_name, (colnr_T)0))
|| ((flags & EW_NOTWILD)
&& fnamencmp(path + (s - buf), dp->d_name, e - s) == 0)))
{
STRCPY(s, dp->d_name);
len = STRLEN(buf);
if (starstar && stardepth < 100)
{
// For "**" in the pattern first go deeper in the tree to
// find matches.
STRCPY(buf + len, "/**");
STRCPY(buf + len + 3, path_end);
++stardepth;
(void)unix_expandpath(gap, buf, len + 1, flags, TRUE);
--stardepth;
}
STRCPY(buf + len, path_end);
if (mch_has_exp_wildcard(path_end)) // handle more wildcards
{
// need to expand another component of the path
// remove backslashes for the remaining components only
(void)unix_expandpath(gap, buf, len + 1, flags, FALSE);
}
else
{
stat_T sb;
// no more wildcards, check if there is a match
// remove backslashes for the remaining components only
if (*path_end != NUL)
backslash_halve(buf + len + 1);
// add existing file or symbolic link
if ((flags & EW_ALLLINKS) ? mch_lstat((char *)buf, &sb) >= 0
: mch_getperm(buf) >= 0)
{
#ifdef MACOS_CONVERT
size_t precomp_len = STRLEN(buf)+1;
char_u *precomp_buf =
mac_precompose_path(buf, precomp_len, &precomp_len);
if (precomp_buf)
{
mch_memmove(buf, precomp_buf, precomp_len);
vim_free(precomp_buf);
}
#endif
addfile(gap, buf, flags);
}
}
}
}
closedir(dirp);
}
vim_free(buf);
vim_regfree(regmatch.regprog);
matches = gap->ga_len - start_len;
if (matches > 0)
qsort(((char_u **)gap->ga_data) + start_len, matches,
sizeof(char_u *), pstrcmp);
return matches;
} | 986 | True | 1 |
CVE-2022-0696 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'name': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'name': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}, {'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4428', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 8.2.4428.'}] | 2022-03-01T23:04Z | 2022-02-21T20:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-02-20 20:49:35+00:00 | patch 8.2.4428: crash when switching tabpage while in the cmdline window
Problem: Crash when switching tabpage while in the cmdline window.
Solution: Disallow switching tabpage when in the cmdline window. | 0f6e28f686dbb59ab3b562408ab9b2234797b9b1 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | get_user_var_name | get_user_var_name( expand_T * xp , int idx) | ['xp', 'idx'] | get_user_var_name(expand_T *xp, int idx)
{
static long_u gdone;
static long_u bdone;
static long_u wdone;
static long_u tdone;
static int vidx;
static hashitem_T *hi;
hashtab_T *ht;
if (idx == 0)
{
gdone = bdone = wdone = vidx = 0;
tdone = 0;
}
// Global variables
if (gdone < globvarht.ht_used)
{
if (gdone++ == 0)
hi = globvarht.ht_array;
else
++hi;
while (HASHITEM_EMPTY(hi))
++hi;
if (STRNCMP("g:", xp->xp_pattern, 2) == 0)
return cat_prefix_varname('g', hi->hi_key);
return hi->hi_key;
}
// b: variables
ht =
#ifdef FEAT_CMDWIN
// In cmdwin, the alternative buffer should be used.
is_in_cmdwin() ? &prevwin->w_buffer->b_vars->dv_hashtab :
#endif
&curbuf->b_vars->dv_hashtab;
if (bdone < ht->ht_used)
{
if (bdone++ == 0)
hi = ht->ht_array;
else
++hi;
while (HASHITEM_EMPTY(hi))
++hi;
return cat_prefix_varname('b', hi->hi_key);
}
// w: variables
ht =
#ifdef FEAT_CMDWIN
// In cmdwin, the alternative window should be used.
is_in_cmdwin() ? &prevwin->w_vars->dv_hashtab :
#endif
&curwin->w_vars->dv_hashtab;
if (wdone < ht->ht_used)
{
if (wdone++ == 0)
hi = ht->ht_array;
else
++hi;
while (HASHITEM_EMPTY(hi))
++hi;
return cat_prefix_varname('w', hi->hi_key);
}
// t: variables
ht = &curtab->tp_vars->dv_hashtab;
if (tdone < ht->ht_used)
{
if (tdone++ == 0)
hi = ht->ht_array;
else
++hi;
while (HASHITEM_EMPTY(hi))
++hi;
return cat_prefix_varname('t', hi->hi_key);
}
// v: variables
if (vidx < VV_LEN)
return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name);
VIM_CLEAR(varnamebuf);
varnamebuflen = 0;
return NULL;
} | 357 | True | 1 |
CVE-2022-0696 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'name': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'name': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}, {'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4428', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 8.2.4428.'}] | 2022-03-01T23:04Z | 2022-02-21T20:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-02-20 20:49:35+00:00 | patch 8.2.4428: crash when switching tabpage while in the cmdline window
Problem: Crash when switching tabpage while in the cmdline window.
Solution: Disallow switching tabpage when in the cmdline window. | 0f6e28f686dbb59ab3b562408ab9b2234797b9b1 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | find_ucmd | find_ucmd( exarg_T * eap , char_u * p , int * full , expand_T * xp , int * complp) | ['eap', 'p', 'full', 'xp', 'complp'] | find_ucmd(
exarg_T *eap,
char_u *p, // end of the command (possibly including count)
int *full, // set to TRUE for a full match
expand_T *xp, // used for completion, NULL otherwise
int *complp) // completion flags or NULL
{
int len = (int)(p - eap->cmd);
int j, k, matchlen = 0;
ucmd_T *uc;
int found = FALSE;
int possible = FALSE;
char_u *cp, *np; // Point into typed cmd and test name
garray_T *gap;
int amb_local = FALSE; // Found ambiguous buffer-local command,
// only full match global is accepted.
/*
* Look for buffer-local user commands first, then global ones.
*/
gap =
#ifdef FEAT_CMDWIN
is_in_cmdwin() ? &prevwin->w_buffer->b_ucmds :
#endif
&curbuf->b_ucmds;
for (;;)
{
for (j = 0; j < gap->ga_len; ++j)
{
uc = USER_CMD_GA(gap, j);
cp = eap->cmd;
np = uc->uc_name;
k = 0;
while (k < len && *np != NUL && *cp++ == *np++)
k++;
if (k == len || (*np == NUL && vim_isdigit(eap->cmd[k])))
{
// If finding a second match, the command is ambiguous. But
// not if a buffer-local command wasn't a full match and a
// global command is a full match.
if (k == len && found && *np != NUL)
{
if (gap == &ucmds)
return NULL;
amb_local = TRUE;
}
if (!found || (k == len && *np == NUL))
{
// If we matched up to a digit, then there could
// be another command including the digit that we
// should use instead.
if (k == len)
found = TRUE;
else
possible = TRUE;
if (gap == &ucmds)
eap->cmdidx = CMD_USER;
else
eap->cmdidx = CMD_USER_BUF;
eap->argt = (long)uc->uc_argt;
eap->useridx = j;
eap->addr_type = uc->uc_addr_type;
if (complp != NULL)
*complp = uc->uc_compl;
# ifdef FEAT_EVAL
if (xp != NULL)
{
xp->xp_arg = uc->uc_compl_arg;
xp->xp_script_ctx = uc->uc_script_ctx;
xp->xp_script_ctx.sc_lnum += SOURCING_LNUM;
}
# endif
// Do not search for further abbreviations
// if this is an exact match.
matchlen = k;
if (k == len && *np == NUL)
{
if (full != NULL)
*full = TRUE;
amb_local = FALSE;
break;
}
}
}
}
// Stop if we found a full match or searched all.
if (j < gap->ga_len || gap == &ucmds)
break;
gap = &ucmds;
}
// Only found ambiguous matches.
if (amb_local)
{
if (xp != NULL)
xp->xp_context = EXPAND_UNSUCCESSFUL;
return NULL;
}
// The match we found may be followed immediately by a number. Move "p"
// back to point to it.
if (found || possible)
return p + (matchlen - len);
return p;
} | 436 | True | 1 |
CVE-2022-0696 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'name': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'name': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}, {'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4428', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 8.2.4428.'}] | 2022-03-01T23:04Z | 2022-02-21T20:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-02-20 20:49:35+00:00 | patch 8.2.4428: crash when switching tabpage while in the cmdline window
Problem: Crash when switching tabpage while in the cmdline window.
Solution: Disallow switching tabpage when in the cmdline window. | 0f6e28f686dbb59ab3b562408ab9b2234797b9b1 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | get_user_command_name | get_user_command_name( int idx , int cmdidx) | ['idx', 'cmdidx'] | get_user_command_name(int idx, int cmdidx)
{
if (cmdidx == CMD_USER && idx < ucmds.ga_len)
return USER_CMD(idx)->uc_name;
if (cmdidx == CMD_USER_BUF)
{
// In cmdwin, the alternative buffer should be used.
buf_T *buf =
#ifdef FEAT_CMDWIN
is_in_cmdwin() ? prevwin->w_buffer :
#endif
curbuf;
if (idx < buf->b_ucmds.ga_len)
return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
}
return NULL;
} | 78 | True | 1 |
CVE-2022-0696 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'name': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'name': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}, {'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4428', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 8.2.4428.'}] | 2022-03-01T23:04Z | 2022-02-21T20:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-02-20 20:49:35+00:00 | patch 8.2.4428: crash when switching tabpage while in the cmdline window
Problem: Crash when switching tabpage while in the cmdline window.
Solution: Disallow switching tabpage when in the cmdline window. | 0f6e28f686dbb59ab3b562408ab9b2234797b9b1 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | get_user_commands | get_user_commands( expand_T * xp UNUSED , int idx) | ['UNUSED', 'idx'] | get_user_commands(expand_T *xp UNUSED, int idx)
{
// In cmdwin, the alternative buffer should be used.
buf_T *buf =
#ifdef FEAT_CMDWIN
is_in_cmdwin() ? prevwin->w_buffer :
#endif
curbuf;
if (idx < buf->b_ucmds.ga_len)
return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
idx -= buf->b_ucmds.ga_len;
if (idx < ucmds.ga_len)
return USER_CMD(idx)->uc_name;
return NULL;
} | 76 | True | 1 |
CVE-2022-0696 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'name': 'https://github.com/vim/vim/commit/0f6e28f686dbb59ab3b562408ab9b2234797b9b1', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'name': 'https://huntr.dev/bounties/7416c2cb-1809-4834-8989-e84ff033f15f', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/7ZLEHVP4LNAGER4ZDGUDS5V5YVQD6INF/', 'name': 'FEDORA-2022-48bf3cb1c4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}, {'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4428', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 8.2.4428.'}] | 2022-03-01T23:04Z | 2022-02-21T20:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-02-20 20:49:35+00:00 | patch 8.2.4428: crash when switching tabpage while in the cmdline window
Problem: Crash when switching tabpage while in the cmdline window.
Solution: Disallow switching tabpage when in the cmdline window. | 0f6e28f686dbb59ab3b562408ab9b2234797b9b1 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | uc_list | uc_list( char_u * name , size_t name_len) | ['name', 'name_len'] | uc_list(char_u *name, size_t name_len)
{
int i, j;
int found = FALSE;
ucmd_T *cmd;
int len;
int over;
long a;
garray_T *gap;
// In cmdwin, the alternative buffer should be used.
gap =
#ifdef FEAT_CMDWIN
is_in_cmdwin() ? &prevwin->w_buffer->b_ucmds :
#endif
&curbuf->b_ucmds;
for (;;)
{
for (i = 0; i < gap->ga_len; ++i)
{
cmd = USER_CMD_GA(gap, i);
a = (long)cmd->uc_argt;
// Skip commands which don't match the requested prefix and
// commands filtered out.
if (STRNCMP(name, cmd->uc_name, name_len) != 0
|| message_filtered(cmd->uc_name))
continue;
// Put out the title first time
if (!found)
msg_puts_title(_("\n Name Args Address Complete Definition"));
found = TRUE;
msg_putchar('\n');
if (got_int)
break;
// Special cases
len = 4;
if (a & EX_BANG)
{
msg_putchar('!');
--len;
}
if (a & EX_REGSTR)
{
msg_putchar('"');
--len;
}
if (gap != &ucmds)
{
msg_putchar('b');
--len;
}
if (a & EX_TRLBAR)
{
msg_putchar('|');
--len;
}
while (len-- > 0)
msg_putchar(' ');
msg_outtrans_attr(cmd->uc_name, HL_ATTR(HLF_D));
len = (int)STRLEN(cmd->uc_name) + 4;
do {
msg_putchar(' ');
++len;
} while (len < 22);
// "over" is how much longer the name is than the column width for
// the name, we'll try to align what comes after.
over = len - 22;
len = 0;
// Arguments
switch ((int)(a & (EX_EXTRA|EX_NOSPC|EX_NEEDARG)))
{
case 0: IObuff[len++] = '0'; break;
case (EX_EXTRA): IObuff[len++] = '*'; break;
case (EX_EXTRA|EX_NOSPC): IObuff[len++] = '?'; break;
case (EX_EXTRA|EX_NEEDARG): IObuff[len++] = '+'; break;
case (EX_EXTRA|EX_NOSPC|EX_NEEDARG): IObuff[len++] = '1'; break;
}
do {
IObuff[len++] = ' ';
} while (len < 5 - over);
// Address / Range
if (a & (EX_RANGE|EX_COUNT))
{
if (a & EX_COUNT)
{
// -count=N
sprintf((char *)IObuff + len, "%ldc", cmd->uc_def);
len += (int)STRLEN(IObuff + len);
}
else if (a & EX_DFLALL)
IObuff[len++] = '%';
else if (cmd->uc_def >= 0)
{
// -range=N
sprintf((char *)IObuff + len, "%ld", cmd->uc_def);
len += (int)STRLEN(IObuff + len);
}
else
IObuff[len++] = '.';
}
do {
IObuff[len++] = ' ';
} while (len < 8 - over);
// Address Type
for (j = 0; addr_type_complete[j].expand != ADDR_NONE; ++j)
if (addr_type_complete[j].expand != ADDR_LINES
&& addr_type_complete[j].expand == cmd->uc_addr_type)
{
STRCPY(IObuff + len, addr_type_complete[j].shortname);
len += (int)STRLEN(IObuff + len);
break;
}
do {
IObuff[len++] = ' ';
} while (len < 13 - over);
// Completion
for (j = 0; command_complete[j].expand != 0; ++j)
if (command_complete[j].expand == cmd->uc_compl)
{
STRCPY(IObuff + len, command_complete[j].name);
len += (int)STRLEN(IObuff + len);
#ifdef FEAT_EVAL
if (p_verbose > 0 && cmd->uc_compl_arg != NULL
&& STRLEN(cmd->uc_compl_arg) < 200)
{
IObuff[len] = ',';
STRCPY(IObuff + len + 1, cmd->uc_compl_arg);
len += (int)STRLEN(IObuff + len);
}
#endif
break;
}
do {
IObuff[len++] = ' ';
} while (len < 25 - over);
IObuff[len] = '\0';
msg_outtrans(IObuff);
msg_outtrans_special(cmd->uc_rep, FALSE,
name_len == 0 ? Columns - 47 : 0);
#ifdef FEAT_EVAL
if (p_verbose > 0)
last_set_msg(cmd->uc_script_ctx);
#endif
out_flush();
ui_breakcheck();
if (got_int)
break;
}
if (gap == &ucmds || i < gap->ga_len)
break;
gap = &ucmds;
}
if (!found)
msg(_("No user-defined commands found"));
} | 855 | True | 1 |
CVE-2022-1420 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://github.com/vim/vim/commit/8b91e71441069b1dde9ac9ff9d9a829b1b4aecca', 'name': 'https://github.com/vim/vim/commit/8b91e71441069b1dde9ac9ff9d9a829b1b4aecca', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/a4323ef8-90ea-4e1c-90e9-c778f0ecf326', 'name': 'https://huntr.dev/bounties/a4323ef8-90ea-4e1c-90e9-c778f0ecf326', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Issue Tracking', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/X6E457NYOIRWBJHKB7ON44UY5AVTG4HU/', 'name': 'FEDORA-2022-e304fffd34', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/KVPZVE2CIE2NGCHZDMEHPBWN3LK2UQAA/', 'name': 'FEDORA-2022-b605768c94', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-823'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4774', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use of Out-of-range Pointer Offset in GitHub repository vim/vim prior to 8.2.4774.'}] | 2022-08-21T06:15Z | 2022-04-21T11:15Z | Use of Out-of-range Pointer Offset | The program performs pointer arithmetic on a valid pointer, but it uses an offset that can point outside of the intended range of valid memory locations for the resulting pointer. |
While a pointer can contain a reference to any arbitrary memory location, a program typically only intends to use the pointer to access limited portions of memory, such as contiguous memory used to access an individual array.
Programs may use offsets in order to access fields or sub-elements stored within structured data. The offset might be out-of-range if it comes from an untrusted source, is the result of an incorrect calculation, or occurs because of another error.
If an attacker can control or influence the offset so that it points outside of the intended boundaries of the structure, then the attacker may be able to read or write to memory locations that are used elsewhere in the program. As a result, the attack might change the state of the software as accessed through program variables, cause a crash or instable behavior, and possibly lead to code execution.
| https://cwe.mitre.org/data/definitions/823.html | 0 | Bram Moolenaar | 2022-04-17 15:06:35+01:00 | patch 8.2.4774: crash when using a number for lambda name
Problem: Crash when using a number for lambda name.
Solution: Check the type of the lambda reference. | 8b91e71441069b1dde9ac9ff9d9a829b1b4aecca | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | eval_lambda | eval_lambda( char_u ** arg , typval_T * rettv , evalarg_T * evalarg , int verbose) | ['arg', 'rettv', 'evalarg', 'verbose'] | eval_lambda(
char_u **arg,
typval_T *rettv,
evalarg_T *evalarg,
int verbose) // give error messages
{
int evaluate = evalarg != NULL
&& (evalarg->eval_flags & EVAL_EVALUATE);
typval_T base = *rettv;
int ret;
rettv->v_type = VAR_UNKNOWN;
if (**arg == '{')
{
// ->{lambda}()
ret = get_lambda_tv(arg, rettv, FALSE, evalarg);
}
else
{
// ->(lambda)()
++*arg;
ret = eval1(arg, rettv, evalarg);
*arg = skipwhite_and_linebreak(*arg, evalarg);
if (**arg == ')')
{
++*arg;
}
else
{
emsg(_(e_missing_closing_paren));
ret = FAIL;
}
}
if (ret != OK)
return FAIL;
else if (**arg != '(')
{
if (verbose)
{
if (*skipwhite(*arg) == '(')
emsg(_(e_no_white_space_allowed_before_parenthesis));
else
semsg(_(e_missing_parenthesis_str), "lambda");
}
clear_tv(rettv);
ret = FAIL;
}
else
ret = call_func_rettv(arg, evalarg, rettv, evaluate, NULL, &base);
// Clear the funcref afterwards, so that deleting it while
// evaluating the arguments is possible (see test55).
if (evaluate)
clear_tv(&base);
return ret;
} | 224 | True | 1 |
CVE-2022-1619 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/b3200483-624e-4c76-a070-e246f62a7450', 'name': 'https://huntr.dev/bounties/b3200483-624e-4c76-a070-e246f62a7450', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/ef02f16609ff0a26ffc6e20263523424980898fe', 'name': 'https://github.com/vim/vim/commit/ef02f16609ff0a26ffc6e20263523424980898fe', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/A6BY5P7ERZS7KXSBCGFCOXLMLGWUUJIH/', 'name': 'FEDORA-2022-e92c3ce170', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/JUN33257RUM4RS2I4GZETKFSAXPETATG/', 'name': 'FEDORA-2022-f0db3943d9', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/05/msg00022.html', 'name': '[debian-lts-announce] 20220516 [SECURITY] [DLA 3011-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/HIP7KG7TVS5YF3QREAY2GOGUT3YUBZAI/', 'name': 'FEDORA-2022-8df66cdbef', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4899', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in function cmdline_erase_chars in GitHub repository vim/vim prior to 8.2.4899. This vulnerabilities are capable of crashing software, modify memory, and possible remote execution'}] | 2022-08-26T20:20Z | 2022-05-08T10:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-05-07 10:49:10+01:00 | patch 8.2.4899: with latin1 encoding CTRL-W might go before the cmdline
Problem: With latin1 encoding CTRL-W might go before the start of the
command line.
Solution: Check already being at the start of the command line. | ef02f16609ff0a26ffc6e20263523424980898fe | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | cmdline_erase_chars | cmdline_erase_chars( int c , int indent , incsearch_state_T * isp) | ['c', 'indent', 'isp'] | cmdline_erase_chars(
int c,
int indent
#ifdef FEAT_SEARCH_EXTRA
, incsearch_state_T *isp
#endif
)
{
int i;
int j;
if (c == K_KDEL)
c = K_DEL;
/*
* Delete current character is the same as backspace on next
* character, except at end of line.
*/
if (c == K_DEL && ccline.cmdpos != ccline.cmdlen)
++ccline.cmdpos;
if (has_mbyte && c == K_DEL)
ccline.cmdpos += mb_off_next(ccline.cmdbuff,
ccline.cmdbuff + ccline.cmdpos);
if (ccline.cmdpos > 0)
{
char_u *p;
j = ccline.cmdpos;
p = ccline.cmdbuff + j;
if (has_mbyte)
{
p = mb_prevptr(ccline.cmdbuff, p);
if (c == Ctrl_W)
{
while (p > ccline.cmdbuff && vim_isspace(*p))
p = mb_prevptr(ccline.cmdbuff, p);
i = mb_get_class(p);
while (p > ccline.cmdbuff && mb_get_class(p) == i)
p = mb_prevptr(ccline.cmdbuff, p);
if (mb_get_class(p) != i)
p += (*mb_ptr2len)(p);
}
}
else if (c == Ctrl_W)
{
while (p > ccline.cmdbuff && vim_isspace(p[-1]))
--p;
i = vim_iswordc(p[-1]);
while (p > ccline.cmdbuff && !vim_isspace(p[-1])
&& vim_iswordc(p[-1]) == i)
--p;
}
else
--p;
ccline.cmdpos = (int)(p - ccline.cmdbuff);
ccline.cmdlen -= j - ccline.cmdpos;
i = ccline.cmdpos;
while (i < ccline.cmdlen)
ccline.cmdbuff[i++] = ccline.cmdbuff[j++];
// Truncate at the end, required for multi-byte chars.
ccline.cmdbuff[ccline.cmdlen] = NUL;
#ifdef FEAT_SEARCH_EXTRA
if (ccline.cmdlen == 0)
{
isp->search_start = isp->save_cursor;
// save view settings, so that the screen
// won't be restored at the wrong position
isp->old_viewstate = isp->init_viewstate;
}
#endif
redrawcmd();
}
else if (ccline.cmdlen == 0 && c != Ctrl_W
&& ccline.cmdprompt == NULL && indent == 0)
{
// In ex and debug mode it doesn't make sense to return.
if (exmode_active
#ifdef FEAT_EVAL
|| ccline.cmdfirstc == '>'
#endif
)
return CMDLINE_NOT_CHANGED;
VIM_CLEAR(ccline.cmdbuff); // no commandline to return
if (!cmd_silent)
{
#ifdef FEAT_RIGHTLEFT
if (cmdmsg_rl)
msg_col = Columns;
else
#endif
msg_col = 0;
msg_putchar(' '); // delete ':'
}
#ifdef FEAT_SEARCH_EXTRA
if (ccline.cmdlen == 0)
isp->search_start = isp->save_cursor;
#endif
redraw_cmdline = TRUE;
return GOTO_NORMAL_MODE;
}
return CMDLINE_CHANGED;
} | 474 | True | 1 |
|
CVE-2022-1620 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://huntr.dev/bounties/7a4c59f3-fcc0-4496-995d-5ca6acd2da51', 'name': 'https://huntr.dev/bounties/7a4c59f3-fcc0-4496-995d-5ca6acd2da51', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/8e4b76da1d7e987d43ca960dfbc372d1c617466f', 'name': 'https://github.com/vim/vim/commit/8e4b76da1d7e987d43ca960dfbc372d1c617466f', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/A6BY5P7ERZS7KXSBCGFCOXLMLGWUUJIH/', 'name': 'FEDORA-2022-e92c3ce170', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/JUN33257RUM4RS2I4GZETKFSAXPETATG/', 'name': 'FEDORA-2022-f0db3943d9', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/HIP7KG7TVS5YF3QREAY2GOGUT3YUBZAI/', 'name': 'FEDORA-2022-8df66cdbef', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4901', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in function vim_regexec_string at regexp.c:2729 in GitHub repository vim/vim prior to 8.2.4901. NULL Pointer Dereference in function vim_regexec_string at regexp.c:2729 allows attackers to cause a denial of service (application crash) via a crafted input.'}] | 2022-08-21T07:15Z | 2022-05-08T11:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-05-07 11:28:06+01:00 | patch 8.2.4901: NULL pointer access when using invalid pattern
Problem: NULL pointer access when using invalid pattern.
Solution: Check for failed regexp program. | 8e4b76da1d7e987d43ca960dfbc372d1c617466f | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | fname_match | fname_match( regmatch_T * rmp , char_u * name , int ignore_case) | ['rmp', 'name', 'ignore_case'] | fname_match(
regmatch_T *rmp,
char_u *name,
int ignore_case) // when TRUE ignore case, when FALSE use 'fic'
{
char_u *match = NULL;
char_u *p;
if (name != NULL)
{
// Ignore case when 'fileignorecase' or the argument is set.
rmp->rm_ic = p_fic || ignore_case;
if (vim_regexec(rmp, name, (colnr_T)0))
match = name;
else
{
// Replace $(HOME) with '~' and try matching again.
p = home_replace_save(NULL, name);
if (p != NULL && vim_regexec(rmp, p, (colnr_T)0))
match = name;
vim_free(p);
}
}
return match;
} | 101 | True | 1 |
CVE-2022-1674 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://huntr.dev/bounties/a74ba4a4-7a39-4a22-bde3-d2f8ee07b385', 'name': 'https://huntr.dev/bounties/a74ba4a4-7a39-4a22-bde3-d2f8ee07b385', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/a59f2dfd0cf9ee1a584d3de5b7c2d47648e79060', 'name': 'https://github.com/vim/vim/commit/a59f2dfd0cf9ee1a584d3de5b7c2d47648e79060', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/ODXVYZC5Z4XRRZK7CK6B6IURYVYHA25U/', 'name': 'FEDORA-2022-d20b51de9c', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/IUPOLEX5GXC733HL4EFYMHFU7NISJJZG/', 'name': 'FEDORA-2022-74b9e404c1', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/BFAZTAT5CZC2R6KYDYA2HBAVEDSIX6MW/', 'name': 'FEDORA-2022-d044e7e0b4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4938', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in function vim_regexec_string at regexp.c:2733 in GitHub repository vim/vim prior to 8.2.4938. NULL Pointer Dereference in function vim_regexec_string at regexp.c:2733 allows attackers to cause a denial of service (application crash) via a crafted input.'}] | 2022-08-21T06:15Z | 2022-05-12T11:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-05-11 11:42:28+01:00 | patch 8.2.4938: crash when matching buffer with invalid pattern
Problem: Crash when matching buffer with invalid pattern.
Solution: Check for NULL regprog. | a59f2dfd0cf9ee1a584d3de5b7c2d47648e79060 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | buflist_match | buflist_match( regmatch_T * rmp , buf_T * buf , int ignore_case) | ['rmp', 'buf', 'ignore_case'] | buflist_match(
regmatch_T *rmp,
buf_T *buf,
int ignore_case) // when TRUE ignore case, when FALSE use 'fic'
{
char_u *match;
// First try the short file name, then the long file name.
match = fname_match(rmp, buf->b_sfname, ignore_case);
if (match == NULL)
match = fname_match(rmp, buf->b_ffname, ignore_case);
return match;
} | 54 | True | 1 |
CVE-2022-1720 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/395bd1f6d3edc9f7edb5d1f2d7deaf5a9e3ab93c', 'name': 'https://github.com/vim/vim/commit/395bd1f6d3edc9f7edb5d1f2d7deaf5a9e3ab93c', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/5ccfb386-7eb9-46e5-98e5-243ea4b358a8', 'name': 'https://huntr.dev/bounties/5ccfb386-7eb9-46e5-98e5-243ea4b358a8', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/06/msg00014.html', 'name': '[debian-lts-announce] 20220620 [SECURITY] [DLA 3053-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-126'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4956', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Buffer Over-read in function grab_file_name in GitHub repository vim/vim prior to 8.2.4956. This vulnerability is capable of crashing the software, memory modification, and possible remote execution.'}] | 2022-08-21T07:15Z | 2022-06-20T15:15Z | Buffer Over-read | The software reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations after the targeted buffer. | This typically occurs when the pointer or its index is incremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in exposure of sensitive information or possibly a crash.
| https://cwe.mitre.org/data/definitions/126.html | 0 | Bram Moolenaar | 2022-05-14 21:29:44+01:00 | patch 8.2.4956: reading past end of line with "gf" in Visual block mode
Problem: Reading past end of line with "gf" in Visual block mode.
Solution: Do not include the NUL in the length. | 395bd1f6d3edc9f7edb5d1f2d7deaf5a9e3ab93c | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | get_visual_text | get_visual_text( cmdarg_T * cap , char_u ** pp , int * lenp) | ['cap', 'pp', 'lenp'] | get_visual_text(
cmdarg_T *cap,
char_u **pp, // return: start of selected text
int *lenp) // return: length of selected text
{
if (VIsual_mode != 'V')
unadjust_for_sel();
if (VIsual.lnum != curwin->w_cursor.lnum)
{
if (cap != NULL)
clearopbeep(cap->oap);
return FAIL;
}
if (VIsual_mode == 'V')
{
*pp = ml_get_curline();
*lenp = (int)STRLEN(*pp);
}
else
{
if (LT_POS(curwin->w_cursor, VIsual))
{
*pp = ml_get_pos(&curwin->w_cursor);
*lenp = VIsual.col - curwin->w_cursor.col + 1;
}
else
{
*pp = ml_get_pos(&VIsual);
*lenp = curwin->w_cursor.col - VIsual.col + 1;
}
if (**pp == NUL)
*lenp = 0;
if (has_mbyte && *lenp > 0)
// Correct the length to include all bytes of the last character.
*lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1;
}
reset_VIsual_and_resel();
return OK;
} | 201 | True | 1 |
CVE-2022-1733 | False | False | False | False | AV:L/AC:L/Au:N/C:P/I:P/A:P | LOCAL | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 4.6 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H | LOCAL | LOW | LOW | NONE | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/6ff03b27-472b-4bef-a2bf-410fae65ff0a', 'name': 'https://huntr.dev/bounties/6ff03b27-472b-4bef-a2bf-410fae65ff0a', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/60ae0e71490c97f2871a6344aca61cacf220f813', 'name': 'https://github.com/vim/vim/commit/60ae0e71490c97f2871a6344aca61cacf220f813', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/QKIX5HYKWXWG6QBCPPTPQ53GNOFHSAIS/', 'name': 'FEDORA-2022-d6d1ac4ca7', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/IUPOLEX5GXC733HL4EFYMHFU7NISJJZG/', 'name': 'FEDORA-2022-74b9e404c1', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/BFAZTAT5CZC2R6KYDYA2HBAVEDSIX6MW/', 'name': 'FEDORA-2022-d044e7e0b4', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-787'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4968', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 8.2.4968.'}] | 2022-08-21T07:15Z | 2022-05-17T17:15Z | Out-of-bounds Write | The software writes data past the end, or before the beginning, of the intended buffer. | Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/787.html | 0 | Bram Moolenaar | 2022-05-16 18:06:15+01:00 | patch 8.2.4968: reading past end of the line when C-indenting
Problem: Reading past end of the line when C-indenting.
Solution: Check for NUL. | 60ae0e71490c97f2871a6344aca61cacf220f813 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | skip_string | skip_string( char_u * p) | ['p'] | skip_string(char_u *p)
{
int i;
// We loop, because strings may be concatenated: "date""time".
for ( ; ; ++p)
{
if (p[0] == '\'') // 'c' or '\n' or '\000'
{
if (p[1] == NUL) // ' at end of line
break;
i = 2;
if (p[1] == '\\' && p[2] != NUL) // '\n' or '\000'
{
++i;
while (vim_isdigit(p[i - 1])) // '\000'
++i;
}
if (p[i] == '\'') // check for trailing '
{
p += i;
continue;
}
}
else if (p[0] == '"') // start of string
{
for (++p; p[0]; ++p)
{
if (p[0] == '\\' && p[1] != NUL)
++p;
else if (p[0] == '"') // end of string
break;
}
if (p[0] == '"')
continue; // continue for another string
}
else if (p[0] == 'R' && p[1] == '"')
{
// Raw string: R"[delim](...)[delim]"
char_u *delim = p + 2;
char_u *paren = vim_strchr(delim, '(');
if (paren != NULL)
{
size_t delim_len = paren - delim;
for (p += 3; *p; ++p)
if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0
&& p[delim_len + 1] == '"')
{
p += delim_len + 1;
break;
}
if (p[0] == '"')
continue; // continue for another string
}
}
break; // no string found
}
if (!*p)
--p; // backup from NUL
return p;
} | 299 | True | 1 |
CVE-2022-1735 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97', 'name': 'https://github.com/vim/vim/commit/7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/c9f85608-ff11-48e4-933d-53d1759d44d9', 'name': 'https://huntr.dev/bounties/c9f85608-ff11-48e4-933d-53d1759d44d9', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-120'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4969', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Classic Buffer Overflow in GitHub repository vim/vim prior to 8.2.4969.'}] | 2022-08-26T19:14Z | 2022-05-17T19:15Z | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
| https://cwe.mitre.org/data/definitions/120.html | 0 | Bram Moolenaar | 2022-05-16 19:40:59+01:00 | patch 8.2.4969: changing text in Visual mode may cause invalid memory access
Problem: Changing text in Visual mode may cause invalid memory access.
Solution: Check the Visual position after making a change. | 7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | stop_insert | stop_insert( pos_T * end_insert_pos , int esc , int nomove) | ['end_insert_pos', 'esc', 'nomove'] | stop_insert(
pos_T *end_insert_pos,
int esc, // called by ins_esc()
int nomove) // <c-\><c-o>, don't move cursor
{
int cc;
char_u *ptr;
stop_redo_ins();
replace_flush(); // abandon replace stack
/*
* Save the inserted text for later redo with ^@ and CTRL-A.
* Don't do it when "restart_edit" was set and nothing was inserted,
* otherwise CTRL-O w and then <Left> will clear "last_insert".
*/
ptr = get_inserted();
if (did_restart_edit == 0 || (ptr != NULL
&& (int)STRLEN(ptr) > new_insert_skip))
{
vim_free(last_insert);
last_insert = ptr;
last_insert_skip = new_insert_skip;
}
else
vim_free(ptr);
if (!arrow_used && end_insert_pos != NULL)
{
// Auto-format now. It may seem strange to do this when stopping an
// insertion (or moving the cursor), but it's required when appending
// a line and having it end in a space. But only do it when something
// was actually inserted, otherwise undo won't work.
if (!ins_need_undo && has_format_option(FO_AUTO))
{
pos_T tpos = curwin->w_cursor;
// When the cursor is at the end of the line after a space the
// formatting will move it to the following word. Avoid that by
// moving the cursor onto the space.
cc = 'x';
if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
{
dec_cursor();
cc = gchar_cursor();
if (!VIM_ISWHITE(cc))
curwin->w_cursor = tpos;
}
auto_format(TRUE, FALSE);
if (VIM_ISWHITE(cc))
{
if (gchar_cursor() != NUL)
inc_cursor();
// If the cursor is still at the same character, also keep
// the "coladd".
if (gchar_cursor() == NUL
&& curwin->w_cursor.lnum == tpos.lnum
&& curwin->w_cursor.col == tpos.col)
curwin->w_cursor.coladd = tpos.coladd;
}
}
// If a space was inserted for auto-formatting, remove it now.
check_auto_format(TRUE);
// If we just did an auto-indent, remove the white space from the end
// of the line, and put the cursor back.
// Do this when ESC was used or moving the cursor up/down.
// Check for the old position still being valid, just in case the text
// got changed unexpectedly.
if (!nomove && did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL
&& curwin->w_cursor.lnum != end_insert_pos->lnum))
&& end_insert_pos->lnum <= curbuf->b_ml.ml_line_count)
{
pos_T tpos = curwin->w_cursor;
curwin->w_cursor = *end_insert_pos;
check_cursor_col(); // make sure it is not past the line
for (;;)
{
if (gchar_cursor() == NUL && curwin->w_cursor.col > 0)
--curwin->w_cursor.col;
cc = gchar_cursor();
if (!VIM_ISWHITE(cc))
break;
if (del_char(TRUE) == FAIL)
break; // should not happen
}
if (curwin->w_cursor.lnum != tpos.lnum)
curwin->w_cursor = tpos;
else
{
// reset tpos, could have been invalidated in the loop above
tpos = curwin->w_cursor;
tpos.col++;
if (cc != NUL && gchar_pos(&tpos) == NUL)
++curwin->w_cursor.col; // put cursor back on the NUL
}
// <C-S-Right> may have started Visual mode, adjust the position for
// deleted characters.
if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum)
{
int len = (int)STRLEN(ml_get_curline());
if (VIsual.col > len)
{
VIsual.col = len;
VIsual.coladd = 0;
}
}
}
}
did_ai = FALSE;
#ifdef FEAT_SMARTINDENT
did_si = FALSE;
can_si = FALSE;
can_si_back = FALSE;
#endif
// Set '[ and '] to the inserted text. When end_insert_pos is NULL we are
// now in a different buffer.
if (end_insert_pos != NULL)
{
curbuf->b_op_start = Insstart;
curbuf->b_op_start_orig = Insstart_orig;
curbuf->b_op_end = *end_insert_pos;
}
} | 491 | True | 1 |
CVE-2022-1769 | False | False | False | False | AV:L/AC:L/Au:N/C:P/I:P/A:P | LOCAL | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 4.6 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H | LOCAL | LOW | LOW | NONE | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/522076b2-96cb-4df6-a504-e6e2f64c171c', 'name': 'https://huntr.dev/bounties/522076b2-96cb-4df6-a504-e6e2f64c171c', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/4748c4bd64610cf943a431d215bb1aad51f8d0b4', 'name': 'https://github.com/vim/vim/commit/4748c4bd64610cf943a431d215bb1aad51f8d0b4', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/QKIX5HYKWXWG6QBCPPTPQ53GNOFHSAIS/', 'name': 'FEDORA-2022-d6d1ac4ca7', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/IUPOLEX5GXC733HL4EFYMHFU7NISJJZG/', 'name': 'FEDORA-2022-74b9e404c1', 'refsource': 'FEDORA', 'tags': ['Mailing List']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/BFAZTAT5CZC2R6KYDYA2HBAVEDSIX6MW/', 'name': 'FEDORA-2022-d044e7e0b4', 'refsource': 'FEDORA', 'tags': ['Mailing List']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-126'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.4974', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Buffer Over-read in GitHub repository vim/vim prior to 8.2.4974.'}] | 2022-08-21T08:15Z | 2022-05-17T17:15Z | Buffer Over-read | The software reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations after the targeted buffer. | This typically occurs when the pointer or its index is incremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in exposure of sensitive information or possibly a crash.
| https://cwe.mitre.org/data/definitions/126.html | 0 | Bram Moolenaar | 2022-05-17 17:47:07+01:00 | patch 8.2.4974: ":so" command may read after end of buffer
Problem: ":so" command may read after end of buffer.
Solution: Compute length of text properly. | 4748c4bd64610cf943a431d215bb1aad51f8d0b4 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | get_one_sourceline | get_one_sourceline( source_cookie_T * sp) | ['sp'] | get_one_sourceline(source_cookie_T *sp)
{
garray_T ga;
int len;
int c;
char_u *buf;
#ifdef USE_CRNL
int has_cr; // CR-LF found
#endif
int have_read = FALSE;
// use a growarray to store the sourced line
ga_init2(&ga, 1, 250);
// Loop until there is a finished line (or end-of-file).
++sp->sourcing_lnum;
for (;;)
{
// make room to read at least 120 (more) characters
if (ga_grow(&ga, 120) == FAIL)
break;
if (sp->source_from_buf)
{
if (sp->buf_lnum >= sp->buflines.ga_len)
break; // all the lines are processed
ga_concat(&ga, ((char_u **)sp->buflines.ga_data)[sp->buf_lnum]);
sp->buf_lnum++;
if (ga_grow(&ga, 1) == FAIL)
break;
buf = (char_u *)ga.ga_data;
buf[ga.ga_len++] = NUL;
}
else
{
buf = (char_u *)ga.ga_data;
if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
sp->fp) == NULL)
break;
}
len = ga.ga_len + (int)STRLEN(buf + ga.ga_len);
#ifdef USE_CRNL
// Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the
// CTRL-Z by its own, or after a NL.
if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n'))
&& sp->fileformat == EOL_DOS
&& buf[len - 1] == Ctrl_Z)
{
buf[len - 1] = NUL;
break;
}
#endif
have_read = TRUE;
ga.ga_len = len;
// If the line was longer than the buffer, read more.
if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n')
continue;
if (len >= 1 && buf[len - 1] == '\n') // remove trailing NL
{
#ifdef USE_CRNL
has_cr = (len >= 2 && buf[len - 2] == '\r');
if (sp->fileformat == EOL_UNKNOWN)
{
if (has_cr)
sp->fileformat = EOL_DOS;
else
sp->fileformat = EOL_UNIX;
}
if (sp->fileformat == EOL_DOS)
{
if (has_cr) // replace trailing CR
{
buf[len - 2] = '\n';
--len;
--ga.ga_len;
}
else // lines like ":map xx yy^M" will have failed
{
if (!sp->error)
{
msg_source(HL_ATTR(HLF_W));
emsg(_("W15: Warning: Wrong line separator, ^M may be missing"));
}
sp->error = TRUE;
sp->fileformat = EOL_UNIX;
}
}
#endif
// The '\n' is escaped if there is an odd number of ^V's just
// before it, first set "c" just before the 'V's and then check
// len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo
for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--)
;
if ((len & 1) != (c & 1)) // escaped NL, read more
{
++sp->sourcing_lnum;
continue;
}
buf[len - 1] = NUL; // remove the NL
}
// Check for ^C here now and then, so recursive :so can be broken.
line_breakcheck();
break;
}
if (have_read)
return (char_u *)ga.ga_data;
vim_free(ga.ga_data);
return NULL;
} | 513 | True | 1 |
CVE-2022-1886 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/fa0ad526-b608-45b3-9ebc-f2b607834d6a', 'name': 'https://huntr.dev/bounties/fa0ad526-b608-45b3-9ebc-f2b607834d6a', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/2a585c85013be22f59f184d49612074fd9b115d7', 'name': 'https://github.com/vim/vim/commit/2a585c85013be22f59f184d49612074fd9b115d7', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/TYNK6SDCMOLQJOI3B4AOE66P2G2IH4ZM/', 'name': 'FEDORA-2022-bb2daad935', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5016', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T06:15Z | 2022-05-26T15:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-05-25 15:15:38+01:00 | patch 8.2.5016: access before start of text with a put command
Problem: Access before start of text with a put command.
Solution: Check the length is more than zero. | 2a585c85013be22f59f184d49612074fd9b115d7 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | do_put | do_put( int regname , char_u * expr_result , int dir , long count , int flags) | ['regname', 'expr_result', 'dir', 'count', 'flags'] | do_put(
int regname,
char_u *expr_result, // result for regname "=" when compiled
int dir, // BACKWARD for 'P', FORWARD for 'p'
long count,
int flags)
{
char_u *ptr;
char_u *newp, *oldp;
int yanklen;
int totlen = 0; // init for gcc
linenr_T lnum;
colnr_T col;
long i; // index in y_array[]
int y_type;
long y_size;
int oldlen;
long y_width = 0;
colnr_T vcol;
int delcount;
int incr = 0;
long j;
struct block_def bd;
char_u **y_array = NULL;
yankreg_T *y_current_used = NULL;
long nr_lines = 0;
pos_T new_cursor;
int indent;
int orig_indent = 0; // init for gcc
int indent_diff = 0; // init for gcc
int first_indent = TRUE;
int lendiff = 0;
pos_T old_pos;
char_u *insert_string = NULL;
int allocated = FALSE;
long cnt;
pos_T orig_start = curbuf->b_op_start;
pos_T orig_end = curbuf->b_op_end;
unsigned int cur_ve_flags = get_ve_flags();
#ifdef FEAT_CLIPBOARD
// Adjust register name for "unnamed" in 'clipboard'.
adjust_clip_reg(®name);
(void)may_get_selection(regname);
#endif
if (flags & PUT_FIXINDENT)
orig_indent = get_indent();
curbuf->b_op_start = curwin->w_cursor; // default for '[ mark
curbuf->b_op_end = curwin->w_cursor; // default for '] mark
// Using inserted text works differently, because the register includes
// special characters (newlines, etc.).
if (regname == '.')
{
if (VIsual_active)
stuffcharReadbuff(VIsual_mode);
(void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') :
(count == -1 ? 'O' : 'i')), count, FALSE);
// Putting the text is done later, so can't really move the cursor to
// the next character. Use "l" to simulate it.
if ((flags & PUT_CURSEND) && gchar_cursor() != NUL)
stuffcharReadbuff('l');
return;
}
// For special registers '%' (file name), '#' (alternate file name) and
// ':' (last command line), etc. we have to create a fake yank register.
// For compiled code "expr_result" holds the expression result.
if (regname == '=' && expr_result != NULL)
insert_string = expr_result;
else if (get_spec_reg(regname, &insert_string, &allocated, TRUE)
&& insert_string == NULL)
return;
// Autocommands may be executed when saving lines for undo. This might
// make "y_array" invalid, so we start undo now to avoid that.
if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL)
goto end;
if (insert_string != NULL)
{
y_type = MCHAR;
#ifdef FEAT_EVAL
if (regname == '=')
{
// For the = register we need to split the string at NL
// characters.
// Loop twice: count the number of lines and save them.
for (;;)
{
y_size = 0;
ptr = insert_string;
while (ptr != NULL)
{
if (y_array != NULL)
y_array[y_size] = ptr;
++y_size;
ptr = vim_strchr(ptr, '\n');
if (ptr != NULL)
{
if (y_array != NULL)
*ptr = NUL;
++ptr;
// A trailing '\n' makes the register linewise.
if (*ptr == NUL)
{
y_type = MLINE;
break;
}
}
}
if (y_array != NULL)
break;
y_array = ALLOC_MULT(char_u *, y_size);
if (y_array == NULL)
goto end;
}
}
else
#endif
{
y_size = 1; // use fake one-line yank register
y_array = &insert_string;
}
}
else
{
get_yank_register(regname, FALSE);
y_type = y_current->y_type;
y_width = y_current->y_width;
y_size = y_current->y_size;
y_array = y_current->y_array;
y_current_used = y_current;
}
if (y_type == MLINE)
{
if (flags & PUT_LINE_SPLIT)
{
char_u *p;
// "p" or "P" in Visual mode: split the lines to put the text in
// between.
if (u_save_cursor() == FAIL)
goto end;
p = ml_get_cursor();
if (dir == FORWARD && *p != NUL)
MB_PTR_ADV(p);
ptr = vim_strsave(p);
if (ptr == NULL)
goto end;
ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE);
vim_free(ptr);
oldp = ml_get_curline();
p = oldp + curwin->w_cursor.col;
if (dir == FORWARD && *p != NUL)
MB_PTR_ADV(p);
ptr = vim_strnsave(oldp, p - oldp);
if (ptr == NULL)
goto end;
ml_replace(curwin->w_cursor.lnum, ptr, FALSE);
++nr_lines;
dir = FORWARD;
}
if (flags & PUT_LINE_FORWARD)
{
// Must be "p" for a Visual block, put lines below the block.
curwin->w_cursor = curbuf->b_visual.vi_end;
dir = FORWARD;
}
curbuf->b_op_start = curwin->w_cursor; // default for '[ mark
curbuf->b_op_end = curwin->w_cursor; // default for '] mark
}
if (flags & PUT_LINE) // :put command or "p" in Visual line mode.
y_type = MLINE;
if (y_size == 0 || y_array == NULL)
{
semsg(_(e_nothing_in_register_str),
regname == 0 ? (char_u *)"\"" : transchar(regname));
goto end;
}
if (y_type == MBLOCK)
{
lnum = curwin->w_cursor.lnum + y_size + 1;
if (lnum > curbuf->b_ml.ml_line_count)
lnum = curbuf->b_ml.ml_line_count + 1;
if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL)
goto end;
}
else if (y_type == MLINE)
{
lnum = curwin->w_cursor.lnum;
#ifdef FEAT_FOLDING
// Correct line number for closed fold. Don't move the cursor yet,
// u_save() uses it.
if (dir == BACKWARD)
(void)hasFolding(lnum, &lnum, NULL);
else
(void)hasFolding(lnum, NULL, &lnum);
#endif
if (dir == FORWARD)
++lnum;
// In an empty buffer the empty line is going to be replaced, include
// it in the saved lines.
if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL)
goto end;
#ifdef FEAT_FOLDING
if (dir == FORWARD)
curwin->w_cursor.lnum = lnum - 1;
else
curwin->w_cursor.lnum = lnum;
curbuf->b_op_start = curwin->w_cursor; // for mark_adjust()
#endif
}
else if (u_save_cursor() == FAIL)
goto end;
yanklen = (int)STRLEN(y_array[0]);
if (cur_ve_flags == VE_ALL && y_type == MCHAR)
{
if (gchar_cursor() == TAB)
{
int viscol = getviscol();
int ts = curbuf->b_p_ts;
// Don't need to insert spaces when "p" on the last position of a
// tab or "P" on the first position.
if (dir == FORWARD ?
#ifdef FEAT_VARTABS
tabstop_padding(viscol, ts, curbuf->b_p_vts_array) != 1
#else
ts - (viscol % ts) != 1
#endif
: curwin->w_cursor.coladd > 0)
coladvance_force(viscol);
else
curwin->w_cursor.coladd = 0;
}
else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL)
coladvance_force(getviscol() + (dir == FORWARD));
}
lnum = curwin->w_cursor.lnum;
col = curwin->w_cursor.col;
// Block mode
if (y_type == MBLOCK)
{
int c = gchar_cursor();
colnr_T endcol2 = 0;
if (dir == FORWARD && c != NUL)
{
if (cur_ve_flags == VE_ALL)
getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2);
else
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col);
if (has_mbyte)
// move to start of next multi-byte character
curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
else
if (c != TAB || cur_ve_flags != VE_ALL)
++curwin->w_cursor.col;
++col;
}
else
getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2);
col += curwin->w_cursor.coladd;
if (cur_ve_flags == VE_ALL
&& (curwin->w_cursor.coladd > 0
|| endcol2 == curwin->w_cursor.col))
{
if (dir == FORWARD && c == NUL)
++col;
if (dir != FORWARD && c != NUL && curwin->w_cursor.coladd > 0)
++curwin->w_cursor.col;
if (c == TAB)
{
if (dir == BACKWARD && curwin->w_cursor.col)
curwin->w_cursor.col--;
if (dir == FORWARD && col - 1 == endcol2)
curwin->w_cursor.col++;
}
}
curwin->w_cursor.coladd = 0;
bd.textcol = 0;
for (i = 0; i < y_size; ++i)
{
int spaces = 0;
char shortline;
bd.startspaces = 0;
bd.endspaces = 0;
vcol = 0;
delcount = 0;
// add a new line
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
{
if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"",
(colnr_T)1, FALSE) == FAIL)
break;
++nr_lines;
}
// get the old line and advance to the position to insert at
oldp = ml_get_curline();
oldlen = (int)STRLEN(oldp);
for (ptr = oldp; vcol < col && *ptr; )
{
// Count a tab for what it's worth (if list mode not on)
incr = lbr_chartabsize_adv(oldp, &ptr, vcol);
vcol += incr;
}
bd.textcol = (colnr_T)(ptr - oldp);
shortline = (vcol < col) || (vcol == col && !*ptr) ;
if (vcol < col) // line too short, padd with spaces
bd.startspaces = col - vcol;
else if (vcol > col)
{
bd.endspaces = vcol - col;
bd.startspaces = incr - bd.endspaces;
--bd.textcol;
delcount = 1;
if (has_mbyte)
bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol);
if (oldp[bd.textcol] != TAB)
{
// Only a Tab can be split into spaces. Other
// characters will have to be moved to after the
// block, causing misalignment.
delcount = 0;
bd.endspaces = 0;
}
}
yanklen = (int)STRLEN(y_array[i]);
if ((flags & PUT_BLOCK_INNER) == 0)
{
// calculate number of spaces required to fill right side of
// block
spaces = y_width + 1;
for (j = 0; j < yanklen; j++)
spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0);
if (spaces < 0)
spaces = 0;
}
// Insert the new text.
// First check for multiplication overflow.
if (yanklen + spaces != 0
&& count > ((INT_MAX - (bd.startspaces + bd.endspaces))
/ (yanklen + spaces)))
{
emsg(_(e_resulting_text_too_long));
break;
}
totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces;
newp = alloc(totlen + oldlen + 1);
if (newp == NULL)
break;
// copy part up to cursor to new line
ptr = newp;
mch_memmove(ptr, oldp, (size_t)bd.textcol);
ptr += bd.textcol;
// may insert some spaces before the new text
vim_memset(ptr, ' ', (size_t)bd.startspaces);
ptr += bd.startspaces;
// insert the new text
for (j = 0; j < count; ++j)
{
mch_memmove(ptr, y_array[i], (size_t)yanklen);
ptr += yanklen;
// insert block's trailing spaces only if there's text behind
if ((j < count - 1 || !shortline) && spaces)
{
vim_memset(ptr, ' ', (size_t)spaces);
ptr += spaces;
}
}
// may insert some spaces after the new text
vim_memset(ptr, ' ', (size_t)bd.endspaces);
ptr += bd.endspaces;
// move the text after the cursor to the end of the line.
mch_memmove(ptr, oldp + bd.textcol + delcount,
(size_t)(oldlen - bd.textcol - delcount + 1));
ml_replace(curwin->w_cursor.lnum, newp, FALSE);
++curwin->w_cursor.lnum;
if (i == 0)
curwin->w_cursor.col += bd.startspaces;
}
changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines);
// Set '[ mark.
curbuf->b_op_start = curwin->w_cursor;
curbuf->b_op_start.lnum = lnum;
// adjust '] mark
curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1;
curbuf->b_op_end.col = bd.textcol + totlen - 1;
curbuf->b_op_end.coladd = 0;
if (flags & PUT_CURSEND)
{
colnr_T len;
curwin->w_cursor = curbuf->b_op_end;
curwin->w_cursor.col++;
// in Insert mode we might be after the NUL, correct for that
len = (colnr_T)STRLEN(ml_get_curline());
if (curwin->w_cursor.col > len)
curwin->w_cursor.col = len;
}
else
curwin->w_cursor.lnum = lnum;
}
else
{
// Character or Line mode
if (y_type == MCHAR)
{
// if type is MCHAR, FORWARD is the same as BACKWARD on the next
// char
if (dir == FORWARD && gchar_cursor() != NUL)
{
if (has_mbyte)
{
int bytelen = (*mb_ptr2len)(ml_get_cursor());
// put it on the next of the multi-byte character.
col += bytelen;
if (yanklen)
{
curwin->w_cursor.col += bytelen;
curbuf->b_op_end.col += bytelen;
}
}
else
{
++col;
if (yanklen)
{
++curwin->w_cursor.col;
++curbuf->b_op_end.col;
}
}
}
curbuf->b_op_start = curwin->w_cursor;
}
// Line mode: BACKWARD is the same as FORWARD on the previous line
else if (dir == BACKWARD)
--lnum;
new_cursor = curwin->w_cursor;
// simple case: insert into one line at a time
if (y_type == MCHAR && y_size == 1)
{
linenr_T end_lnum = 0; // init for gcc
linenr_T start_lnum = lnum;
int first_byte_off = 0;
if (VIsual_active)
{
end_lnum = curbuf->b_visual.vi_end.lnum;
if (end_lnum < curbuf->b_visual.vi_start.lnum)
end_lnum = curbuf->b_visual.vi_start.lnum;
if (end_lnum > start_lnum)
{
pos_T pos;
// "col" is valid for the first line, in following lines
// the virtual column needs to be used. Matters for
// multi-byte characters.
pos.lnum = lnum;
pos.col = col;
pos.coladd = 0;
getvcol(curwin, &pos, NULL, &vcol, NULL);
}
}
if (count == 0 || yanklen == 0)
{
if (VIsual_active)
lnum = end_lnum;
}
else if (count > INT_MAX / yanklen)
// multiplication overflow
emsg(_(e_resulting_text_too_long));
else
{
totlen = count * yanklen;
do {
oldp = ml_get(lnum);
oldlen = (int)STRLEN(oldp);
if (lnum > start_lnum)
{
pos_T pos;
pos.lnum = lnum;
if (getvpos(&pos, vcol) == OK)
col = pos.col;
else
col = MAXCOL;
}
if (VIsual_active && col > oldlen)
{
lnum++;
continue;
}
newp = alloc(totlen + oldlen + 1);
if (newp == NULL)
goto end; // alloc() gave an error message
mch_memmove(newp, oldp, (size_t)col);
ptr = newp + col;
for (i = 0; i < count; ++i)
{
mch_memmove(ptr, y_array[0], (size_t)yanklen);
ptr += yanklen;
}
STRMOVE(ptr, oldp + col);
ml_replace(lnum, newp, FALSE);
// compute the byte offset for the last character
first_byte_off = mb_head_off(newp, ptr - 1);
// Place cursor on last putted char.
if (lnum == curwin->w_cursor.lnum)
{
// make sure curwin->w_virtcol is updated
changed_cline_bef_curs();
curwin->w_cursor.col += (colnr_T)(totlen - 1);
}
if (VIsual_active)
lnum++;
} while (VIsual_active && lnum <= end_lnum);
if (VIsual_active) // reset lnum to the last visual line
lnum--;
}
// put '] at the first byte of the last character
curbuf->b_op_end = curwin->w_cursor;
curbuf->b_op_end.col -= first_byte_off;
// For "CTRL-O p" in Insert mode, put cursor after last char
if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND)))
++curwin->w_cursor.col;
else
curwin->w_cursor.col -= first_byte_off;
changed_bytes(lnum, col);
}
else
{
linenr_T new_lnum = new_cursor.lnum;
size_t len;
// Insert at least one line. When y_type is MCHAR, break the first
// line in two.
for (cnt = 1; cnt <= count; ++cnt)
{
i = 0;
if (y_type == MCHAR)
{
// Split the current line in two at the insert position.
// First insert y_array[size - 1] in front of second line.
// Then append y_array[0] to first line.
lnum = new_cursor.lnum;
ptr = ml_get(lnum) + col;
totlen = (int)STRLEN(y_array[y_size - 1]);
newp = alloc(STRLEN(ptr) + totlen + 1);
if (newp == NULL)
goto error;
STRCPY(newp, y_array[y_size - 1]);
STRCAT(newp, ptr);
// insert second line
ml_append(lnum, newp, (colnr_T)0, FALSE);
++new_lnum;
vim_free(newp);
oldp = ml_get(lnum);
newp = alloc(col + yanklen + 1);
if (newp == NULL)
goto error;
// copy first part of line
mch_memmove(newp, oldp, (size_t)col);
// append to first line
mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1));
ml_replace(lnum, newp, FALSE);
curwin->w_cursor.lnum = lnum;
i = 1;
}
for (; i < y_size; ++i)
{
if (y_type != MCHAR || i < y_size - 1)
{
if (ml_append(lnum, y_array[i], (colnr_T)0, FALSE)
== FAIL)
goto error;
new_lnum++;
}
lnum++;
++nr_lines;
if (flags & PUT_FIXINDENT)
{
old_pos = curwin->w_cursor;
curwin->w_cursor.lnum = lnum;
ptr = ml_get(lnum);
if (cnt == count && i == y_size - 1)
lendiff = (int)STRLEN(ptr);
if (*ptr == '#' && preprocs_left())
indent = 0; // Leave # lines at start
else
if (*ptr == NUL)
indent = 0; // Ignore empty lines
else if (first_indent)
{
indent_diff = orig_indent - get_indent();
indent = orig_indent;
first_indent = FALSE;
}
else if ((indent = get_indent() + indent_diff) < 0)
indent = 0;
(void)set_indent(indent, 0);
curwin->w_cursor = old_pos;
// remember how many chars were removed
if (cnt == count && i == y_size - 1)
lendiff -= (int)STRLEN(ml_get(lnum));
}
}
if (cnt == 1)
new_lnum = lnum;
}
error:
// Adjust marks.
if (y_type == MLINE)
{
curbuf->b_op_start.col = 0;
if (dir == FORWARD)
curbuf->b_op_start.lnum++;
}
// Skip mark_adjust when adding lines after the last one, there
// can't be marks there. But still needed in diff mode.
if (curbuf->b_op_start.lnum + (y_type == MCHAR) - 1 + nr_lines
< curbuf->b_ml.ml_line_count
#ifdef FEAT_DIFF
|| curwin->w_p_diff
#endif
)
mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR),
(linenr_T)MAXLNUM, nr_lines, 0L);
// note changed text for displaying and folding
if (y_type == MCHAR)
changed_lines(curwin->w_cursor.lnum, col,
curwin->w_cursor.lnum + 1, nr_lines);
else
changed_lines(curbuf->b_op_start.lnum, 0,
curbuf->b_op_start.lnum, nr_lines);
if (y_current_used != NULL && (y_current_used != y_current
|| y_current->y_array != y_array))
{
// Something invoked through changed_lines() has changed the
// yank buffer, e.g. a GUI clipboard callback.
emsg(_(e_yank_register_changed_while_using_it));
goto end;
}
// Put the '] mark on the first byte of the last inserted character.
// Correct the length for change in indent.
curbuf->b_op_end.lnum = new_lnum;
len = STRLEN(y_array[y_size - 1]);
col = (colnr_T)len - lendiff;
if (col > 1)
curbuf->b_op_end.col = col - 1
- mb_head_off(y_array[y_size - 1],
y_array[y_size - 1] + len - 1);
else
curbuf->b_op_end.col = 0;
if (flags & PUT_CURSLINE)
{
// ":put": put cursor on last inserted line
curwin->w_cursor.lnum = lnum;
beginline(BL_WHITE | BL_FIX);
}
else if (flags & PUT_CURSEND)
{
// put cursor after inserted text
if (y_type == MLINE)
{
if (lnum >= curbuf->b_ml.ml_line_count)
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
else
curwin->w_cursor.lnum = lnum + 1;
curwin->w_cursor.col = 0;
}
else
{
curwin->w_cursor.lnum = new_lnum;
curwin->w_cursor.col = col;
curbuf->b_op_end = curwin->w_cursor;
if (col > 1)
curbuf->b_op_end.col = col - 1;
}
}
else if (y_type == MLINE)
{
// put cursor on first non-blank in first inserted line
curwin->w_cursor.col = 0;
if (dir == FORWARD)
++curwin->w_cursor.lnum;
beginline(BL_WHITE | BL_FIX);
}
else // put cursor on first inserted character
curwin->w_cursor = new_cursor;
}
}
msgmore(nr_lines);
curwin->w_set_curswant = TRUE;
end:
if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
{
curbuf->b_op_start = orig_start;
curbuf->b_op_end = orig_end;
}
if (allocated)
vim_free(insert_string);
if (regname == '=')
vim_free(y_array);
VIsual_active = FALSE;
// If the cursor is past the end of the line put it at the end.
adjust_cursor_eol();
} | 3592 | True | 1 |
|
CVE-2022-1897 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/82c12151-c283-40cf-aa05-2e39efa89118', 'name': 'https://huntr.dev/bounties/82c12151-c283-40cf-aa05-2e39efa89118', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/338f1fc0ee3ca929387448fe464579d6113fa76a', 'name': 'https://github.com/vim/vim/commit/338f1fc0ee3ca929387448fe464579d6113fa76a', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/QMFHBC5OQXDPV2SDYA2JUQGVCPYASTJB/', 'name': 'FEDORA-2022-5ce148636b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/OZSLFIKFYU5Y2KM5EJKQNYHWRUBDQ4GJ/', 'name': 'FEDORA-2022-d94440bf0e', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/TYNK6SDCMOLQJOI3B4AOE66P2G2IH4ZM/', 'name': 'FEDORA-2022-bb2daad935', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-787'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.0.5023', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Write in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T07:15Z | 2022-05-27T15:15Z | Out-of-bounds Write | The software writes data past the end, or before the beginning, of the intended buffer. | Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/787.html | 0 | Bram Moolenaar | 2022-05-26 15:56:23+01:00 | patch 8.2.5023: substitute overwrites allocated buffer
Problem: Substitute overwrites allocated buffer.
Solution: Disallow undo when in a substitute command. | 338f1fc0ee3ca929387448fe464579d6113fa76a | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | normal_cmd | normal_cmd( oparg_T * oap , int toplevel UNUSED) | ['oap', 'UNUSED'] | normal_cmd(
oparg_T *oap,
int toplevel UNUSED) // TRUE when called from main()
{
cmdarg_T ca; // command arguments
int c;
int ctrl_w = FALSE; // got CTRL-W command
int old_col = curwin->w_curswant;
int need_flushbuf = FALSE; // need to call out_flush()
pos_T old_pos; // cursor position before command
int mapped_len;
static int old_mapped_len = 0;
int idx;
int set_prevcount = FALSE;
int save_did_cursorhold = did_cursorhold;
CLEAR_FIELD(ca); // also resets ca.retval
ca.oap = oap;
// Use a count remembered from before entering an operator. After typing
// "3d" we return from normal_cmd() and come back here, the "3" is
// remembered in "opcount".
ca.opcount = opcount;
// If there is an operator pending, then the command we take this time
// will terminate it. Finish_op tells us to finish the operation before
// returning this time (unless the operation was cancelled).
#ifdef CURSOR_SHAPE
c = finish_op;
#endif
finish_op = (oap->op_type != OP_NOP);
#ifdef CURSOR_SHAPE
if (finish_op != c)
{
ui_cursor_shape(); // may show different cursor shape
# ifdef FEAT_MOUSESHAPE
update_mouseshape(-1);
# endif
}
#endif
may_trigger_modechanged();
// When not finishing an operator and no register name typed, reset the
// count.
if (!finish_op && !oap->regname)
{
ca.opcount = 0;
#ifdef FEAT_EVAL
set_prevcount = TRUE;
#endif
}
// Restore counts from before receiving K_CURSORHOLD. This means after
// typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not
// "3 * 2".
if (oap->prev_opcount > 0 || oap->prev_count0 > 0)
{
ca.opcount = oap->prev_opcount;
ca.count0 = oap->prev_count0;
oap->prev_opcount = 0;
oap->prev_count0 = 0;
}
mapped_len = typebuf_maplen();
State = MODE_NORMAL_BUSY;
#ifdef USE_ON_FLY_SCROLL
dont_scroll = FALSE; // allow scrolling here
#endif
#ifdef FEAT_EVAL
// Set v:count here, when called from main() and not a stuffed
// command, so that v:count can be used in an expression mapping
// when there is no count. Do set it for redo.
if (toplevel && readbuf1_empty())
set_vcount_ca(&ca, &set_prevcount);
#endif
/*
* Get the command character from the user.
*/
c = safe_vgetc();
LANGMAP_ADJUST(c, get_real_state() != MODE_SELECT);
// If a mapping was started in Visual or Select mode, remember the length
// of the mapping. This is used below to not return to Insert mode for as
// long as the mapping is being executed.
if (restart_edit == 0)
old_mapped_len = 0;
else if (old_mapped_len
|| (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0))
old_mapped_len = typebuf_maplen();
if (c == NUL)
c = K_ZERO;
// In Select mode, typed text replaces the selection.
if (VIsual_active
&& VIsual_select
&& (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER))
{
int len;
// Fake a "c"hange command. When "restart_edit" is set (e.g., because
// 'insertmode' is set) fake a "d"elete command, Insert mode will
// restart automatically.
// Insert the typed character in the typeahead buffer, so that it can
// be mapped in Insert mode. Required for ":lmap" to work.
len = ins_char_typebuf(vgetc_char, vgetc_mod_mask);
// When recording and gotchars() was called the character will be
// recorded again, remove the previous recording.
if (KeyTyped)
ungetchars(len);
if (restart_edit != 0)
c = 'd';
else
c = 'c';
msg_nowait = TRUE; // don't delay going to insert mode
old_mapped_len = 0; // do go to Insert mode
}
// If the window was made so small that nothing shows, make it at least one
// line and one column when typing a command.
if (KeyTyped && !KeyStuffed)
win_ensure_size();
#ifdef FEAT_CMDL_INFO
need_flushbuf = add_to_showcmd(c);
#endif
// Get the command count
c = normal_cmd_get_count(&ca, c, toplevel, set_prevcount, &ctrl_w,
&need_flushbuf);
// Find the command character in the table of commands.
// For CTRL-W we already got nchar when looking for a count.
if (ctrl_w)
{
ca.nchar = c;
ca.cmdchar = Ctrl_W;
}
else
ca.cmdchar = c;
idx = find_command(ca.cmdchar);
if (idx < 0)
{
// Not a known command: beep.
clearopbeep(oap);
goto normal_end;
}
if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW))
{
// This command is not allowed while editing a cmdline: beep.
clearopbeep(oap);
text_locked_msg();
goto normal_end;
}
if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked())
goto normal_end;
// In Visual/Select mode, a few keys are handled in a special way.
if (VIsual_active)
{
// when 'keymodel' contains "stopsel" may stop Select/Visual mode
if (km_stopsel
&& (nv_cmds[idx].cmd_flags & NV_STS)
&& !(mod_mask & MOD_MASK_SHIFT))
{
end_visual_mode();
redraw_curbuf_later(INVERTED);
}
// Keys that work different when 'keymodel' contains "startsel"
if (km_startsel)
{
if (nv_cmds[idx].cmd_flags & NV_SS)
{
unshift_special(&ca);
idx = find_command(ca.cmdchar);
if (idx < 0)
{
// Just in case
clearopbeep(oap);
goto normal_end;
}
}
else if ((nv_cmds[idx].cmd_flags & NV_SSS)
&& (mod_mask & MOD_MASK_SHIFT))
mod_mask &= ~MOD_MASK_SHIFT;
}
}
#ifdef FEAT_RIGHTLEFT
if (curwin->w_p_rl && KeyTyped && !KeyStuffed
&& (nv_cmds[idx].cmd_flags & NV_RL))
{
// Invert horizontal movements and operations. Only when typed by the
// user directly, not when the result of a mapping or "x" translated
// to "dl".
switch (ca.cmdchar)
{
case 'l': ca.cmdchar = 'h'; break;
case K_RIGHT: ca.cmdchar = K_LEFT; break;
case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break;
case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break;
case 'h': ca.cmdchar = 'l'; break;
case K_LEFT: ca.cmdchar = K_RIGHT; break;
case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break;
case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break;
case '>': ca.cmdchar = '<'; break;
case '<': ca.cmdchar = '>'; break;
}
idx = find_command(ca.cmdchar);
}
#endif
// Get additional characters if we need them.
if (normal_cmd_needs_more_chars(&ca, nv_cmds[idx].cmd_flags))
idx = normal_cmd_get_more_chars(idx, &ca, &need_flushbuf);
#ifdef FEAT_CMDL_INFO
// Flush the showcmd characters onto the screen so we can see them while
// the command is being executed. Only do this when the shown command was
// actually displayed, otherwise this will slow down a lot when executing
// mappings.
if (need_flushbuf)
out_flush();
#endif
if (ca.cmdchar != K_IGNORE)
{
if (ex_normal_busy)
did_cursorhold = save_did_cursorhold;
else
did_cursorhold = FALSE;
}
State = MODE_NORMAL;
if (ca.nchar == ESC)
{
clearop(oap);
if (restart_edit == 0 && goto_im())
restart_edit = 'a';
goto normal_end;
}
if (ca.cmdchar != K_IGNORE)
{
msg_didout = FALSE; // don't scroll screen up for normal command
msg_col = 0;
}
old_pos = curwin->w_cursor; // remember where cursor was
// When 'keymodel' contains "startsel" some keys start Select/Visual
// mode.
if (!VIsual_active && km_startsel)
{
if (nv_cmds[idx].cmd_flags & NV_SS)
{
start_selection();
unshift_special(&ca);
idx = find_command(ca.cmdchar);
}
else if ((nv_cmds[idx].cmd_flags & NV_SSS)
&& (mod_mask & MOD_MASK_SHIFT))
{
start_selection();
mod_mask &= ~MOD_MASK_SHIFT;
}
}
// Execute the command!
// Call the command function found in the commands table.
ca.arg = nv_cmds[idx].cmd_arg;
(nv_cmds[idx].cmd_func)(&ca);
// If we didn't start or finish an operator, reset oap->regname, unless we
// need it later.
if (!finish_op
&& !oap->op_type
&& (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG)))
{
clearop(oap);
#ifdef FEAT_EVAL
reset_reg_var();
#endif
}
// Get the length of mapped chars again after typing a count, second
// character or "z333<cr>".
if (old_mapped_len > 0)
old_mapped_len = typebuf_maplen();
// If an operation is pending, handle it. But not for K_IGNORE or
// K_MOUSEMOVE.
if (ca.cmdchar != K_IGNORE && ca.cmdchar != K_MOUSEMOVE)
do_pending_operator(&ca, old_col, FALSE);
// Wait for a moment when a message is displayed that will be overwritten
// by the mode message.
if (normal_cmd_need_to_wait_for_msg(&ca, &old_pos))
normal_cmd_wait_for_msg();
// Finish up after executing a Normal mode command.
normal_end:
msg_nowait = FALSE;
#ifdef FEAT_EVAL
if (finish_op)
reset_reg_var();
#endif
// Reset finish_op, in case it was set
#ifdef CURSOR_SHAPE
c = finish_op;
#endif
finish_op = FALSE;
may_trigger_modechanged();
#ifdef CURSOR_SHAPE
// Redraw the cursor with another shape, if we were in Operator-pending
// mode or did a replace command.
if (c || ca.cmdchar == 'r')
{
ui_cursor_shape(); // may show different cursor shape
# ifdef FEAT_MOUSESHAPE
update_mouseshape(-1);
# endif
}
#endif
#ifdef FEAT_CMDL_INFO
if (oap->op_type == OP_NOP && oap->regname == 0
&& ca.cmdchar != K_CURSORHOLD)
clear_showcmd();
#endif
checkpcmark(); // check if we moved since setting pcmark
vim_free(ca.searchbuf);
if (has_mbyte)
mb_adjust_cursor();
if (curwin->w_p_scb && toplevel)
{
validate_cursor(); // may need to update w_leftcol
do_check_scrollbind(TRUE);
}
if (curwin->w_p_crb && toplevel)
{
validate_cursor(); // may need to update w_leftcol
do_check_cursorbind();
}
#ifdef FEAT_TERMINAL
// don't go to Insert mode if a terminal has a running job
if (term_job_running(curbuf->b_term))
restart_edit = 0;
#endif
// May restart edit(), if we got here with CTRL-O in Insert mode (but not
// if still inside a mapping that started in Visual mode).
// May switch from Visual to Select mode after CTRL-O command.
if ( oap->op_type == OP_NOP
&& ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0)
|| restart_VIsual_select == 1)
&& !(ca.retval & CA_COMMAND_BUSY)
&& stuff_empty()
&& oap->regname == 0)
{
if (restart_VIsual_select == 1)
{
VIsual_select = TRUE;
may_trigger_modechanged();
showmode();
restart_VIsual_select = 0;
VIsual_select_reg = 0;
}
if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0)
(void)edit(restart_edit, FALSE, 1L);
}
if (restart_VIsual_select == 2)
restart_VIsual_select = 1;
// Save count before an operator for next time.
opcount = ca.opcount;
} | 1308 | True | 1 |
CVE-2022-1897 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/82c12151-c283-40cf-aa05-2e39efa89118', 'name': 'https://huntr.dev/bounties/82c12151-c283-40cf-aa05-2e39efa89118', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/338f1fc0ee3ca929387448fe464579d6113fa76a', 'name': 'https://github.com/vim/vim/commit/338f1fc0ee3ca929387448fe464579d6113fa76a', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/QMFHBC5OQXDPV2SDYA2JUQGVCPYASTJB/', 'name': 'FEDORA-2022-5ce148636b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/OZSLFIKFYU5Y2KM5EJKQNYHWRUBDQ4GJ/', 'name': 'FEDORA-2022-d94440bf0e', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/TYNK6SDCMOLQJOI3B4AOE66P2G2IH4ZM/', 'name': 'FEDORA-2022-bb2daad935', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-787'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.0.5023', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Write in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T07:15Z | 2022-05-27T15:15Z | Out-of-bounds Write | The software writes data past the end, or before the beginning, of the intended buffer. | Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/787.html | 0 | Bram Moolenaar | 2022-05-26 15:56:23+01:00 | patch 8.2.5023: substitute overwrites allocated buffer
Problem: Substitute overwrites allocated buffer.
Solution: Disallow undo when in a substitute command. | 338f1fc0ee3ca929387448fe464579d6113fa76a | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | nv_g_cmd | nv_g_cmd( cmdarg_T * cap) | ['cap'] | nv_g_cmd(cmdarg_T *cap)
{
oparg_T *oap = cap->oap;
int i;
switch (cap->nchar)
{
case Ctrl_A:
case Ctrl_X:
#ifdef MEM_PROFILE
// "g^A": dump log of used memory.
if (!VIsual_active && cap->nchar == Ctrl_A)
vim_mem_profile_dump();
else
#endif
// "g^A/g^X": sequentially increment visually selected region
if (VIsual_active)
{
cap->arg = TRUE;
cap->cmdchar = cap->nchar;
cap->nchar = NUL;
nv_addsub(cap);
}
else
clearopbeep(oap);
break;
// "gR": Enter virtual replace mode.
case 'R':
cap->arg = TRUE;
nv_Replace(cap);
break;
case 'r':
nv_vreplace(cap);
break;
case '&':
do_cmdline_cmd((char_u *)"%s//~/&");
break;
// "gv": Reselect the previous Visual area. If Visual already active,
// exchange previous and current Visual area.
case 'v':
nv_gv_cmd(cap);
break;
// "gV": Don't reselect the previous Visual area after a Select mode
// mapping of menu.
case 'V':
VIsual_reselect = FALSE;
break;
// "gh": start Select mode.
// "gH": start Select line mode.
// "g^H": start Select block mode.
case K_BS:
cap->nchar = Ctrl_H;
// FALLTHROUGH
case 'h':
case 'H':
case Ctrl_H:
cap->cmdchar = cap->nchar + ('v' - 'h');
cap->arg = TRUE;
nv_visual(cap);
break;
// "gn", "gN" visually select next/previous search match
// "gn" selects next match
// "gN" selects previous match
case 'N':
case 'n':
if (!current_search(cap->count1, cap->nchar == 'n'))
clearopbeep(oap);
break;
// "gj" and "gk" two new funny movement keys -- up and down
// movement based on *screen* line rather than *file* line.
case 'j':
case K_DOWN:
// with 'nowrap' it works just like the normal "j" command.
if (!curwin->w_p_wrap)
{
oap->motion_type = MLINE;
i = cursor_down(cap->count1, oap->op_type == OP_NOP);
}
else
i = nv_screengo(oap, FORWARD, cap->count1);
if (i == FAIL)
clearopbeep(oap);
break;
case 'k':
case K_UP:
// with 'nowrap' it works just like the normal "k" command.
if (!curwin->w_p_wrap)
{
oap->motion_type = MLINE;
i = cursor_up(cap->count1, oap->op_type == OP_NOP);
}
else
i = nv_screengo(oap, BACKWARD, cap->count1);
if (i == FAIL)
clearopbeep(oap);
break;
// "gJ": join two lines without inserting a space.
case 'J':
nv_join(cap);
break;
// "g0", "g^" : Like "0" and "^" but for screen lines.
// "gm": middle of "g0" and "g$".
case '^':
case '0':
case 'm':
case K_HOME:
case K_KHOME:
nv_g_home_m_cmd(cap);
break;
case 'M':
{
oap->motion_type = MCHAR;
oap->inclusive = FALSE;
i = linetabsize(ml_get_curline());
if (cap->count0 > 0 && cap->count0 <= 100)
coladvance((colnr_T)(i * cap->count0 / 100));
else
coladvance((colnr_T)(i / 2));
curwin->w_set_curswant = TRUE;
}
break;
// "g_": to the last non-blank character in the line or <count> lines
// downward.
case '_':
nv_g_underscore_cmd(cap);
break;
// "g$" : Like "$" but for screen lines.
case '$':
case K_END:
case K_KEND:
nv_g_dollar_cmd(cap);
break;
// "g*" and "g#", like "*" and "#" but without using "\<" and "\>"
case '*':
case '#':
#if POUND != '#'
case POUND: // pound sign (sometimes equal to '#')
#endif
case Ctrl_RSB: // :tag or :tselect for current identifier
case ']': // :tselect for current identifier
nv_ident(cap);
break;
// ge and gE: go back to end of word
case 'e':
case 'E':
oap->motion_type = MCHAR;
curwin->w_set_curswant = TRUE;
oap->inclusive = TRUE;
if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL)
clearopbeep(oap);
break;
// "g CTRL-G": display info about cursor position
case Ctrl_G:
cursor_pos_info(NULL);
break;
// "gi": start Insert at the last position.
case 'i':
nv_gi_cmd(cap);
break;
// "gI": Start insert in column 1.
case 'I':
beginline(0);
if (!checkclearopq(oap))
invoke_edit(cap, FALSE, 'g', FALSE);
break;
#ifdef FEAT_SEARCHPATH
// "gf": goto file, edit file under cursor
// "]f" and "[f": can also be used.
case 'f':
case 'F':
nv_gotofile(cap);
break;
#endif
// "g'm" and "g`m": jump to mark without setting pcmark
case '\'':
cap->arg = TRUE;
// FALLTHROUGH
case '`':
nv_gomark(cap);
break;
// "gs": Goto sleep.
case 's':
do_sleep(cap->count1 * 1000L, FALSE);
break;
// "ga": Display the ascii value of the character under the
// cursor. It is displayed in decimal, hex, and octal. -- webb
case 'a':
do_ascii(NULL);
break;
// "g8": Display the bytes used for the UTF-8 character under the
// cursor. It is displayed in hex.
// "8g8" finds illegal byte sequence.
case '8':
if (cap->count0 == 8)
utf_find_illegal();
else
show_utf8();
break;
// "g<": show scrollback text
case '<':
show_sb_text();
break;
// "gg": Goto the first line in file. With a count it goes to
// that line number like for "G". -- webb
case 'g':
cap->arg = FALSE;
nv_goto(cap);
break;
// Two-character operators:
// "gq" Format text
// "gw" Format text and keep cursor position
// "g~" Toggle the case of the text.
// "gu" Change text to lower case.
// "gU" Change text to upper case.
// "g?" rot13 encoding
// "g@" call 'operatorfunc'
case 'q':
case 'w':
oap->cursor_start = curwin->w_cursor;
// FALLTHROUGH
case '~':
case 'u':
case 'U':
case '?':
case '@':
nv_operator(cap);
break;
// "gd": Find first occurrence of pattern under the cursor in the
// current function
// "gD": idem, but in the current file.
case 'd':
case 'D':
nv_gd(oap, cap->nchar, (int)cap->count0);
break;
// g<*Mouse> : <C-*mouse>
case K_MIDDLEMOUSE:
case K_MIDDLEDRAG:
case K_MIDDLERELEASE:
case K_LEFTMOUSE:
case K_LEFTDRAG:
case K_LEFTRELEASE:
case K_MOUSEMOVE:
case K_RIGHTMOUSE:
case K_RIGHTDRAG:
case K_RIGHTRELEASE:
case K_X1MOUSE:
case K_X1DRAG:
case K_X1RELEASE:
case K_X2MOUSE:
case K_X2DRAG:
case K_X2RELEASE:
mod_mask = MOD_MASK_CTRL;
(void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0);
break;
case K_IGNORE:
break;
// "gP" and "gp": same as "P" and "p" but leave cursor just after new text
case 'p':
case 'P':
nv_put(cap);
break;
#ifdef FEAT_BYTEOFF
// "go": goto byte count from start of buffer
case 'o':
goto_byte(cap->count0);
break;
#endif
// "gQ": improved Ex mode
case 'Q':
if (text_locked())
{
clearopbeep(cap->oap);
text_locked_msg();
break;
}
if (!checkclearopq(oap))
do_exmode(TRUE);
break;
case ',':
nv_pcmark(cap);
break;
case ';':
cap->count1 = -cap->count1;
nv_pcmark(cap);
break;
case 't':
if (!checkclearop(oap))
goto_tabpage((int)cap->count0);
break;
case 'T':
if (!checkclearop(oap))
goto_tabpage(-(int)cap->count1);
break;
case TAB:
if (!checkclearop(oap) && goto_tabpage_lastused() == FAIL)
clearopbeep(oap);
break;
case '+':
case '-': // "g+" and "g-": undo or redo along the timeline
if (!checkclearopq(oap))
undo_time(cap->nchar == '-' ? -cap->count1 : cap->count1,
FALSE, FALSE, FALSE);
break;
default:
clearopbeep(oap);
break;
}
} | 1060 | True | 1 |
CVE-2022-1897 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/82c12151-c283-40cf-aa05-2e39efa89118', 'name': 'https://huntr.dev/bounties/82c12151-c283-40cf-aa05-2e39efa89118', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/338f1fc0ee3ca929387448fe464579d6113fa76a', 'name': 'https://github.com/vim/vim/commit/338f1fc0ee3ca929387448fe464579d6113fa76a', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/QMFHBC5OQXDPV2SDYA2JUQGVCPYASTJB/', 'name': 'FEDORA-2022-5ce148636b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/OZSLFIKFYU5Y2KM5EJKQNYHWRUBDQ4GJ/', 'name': 'FEDORA-2022-d94440bf0e', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/TYNK6SDCMOLQJOI3B4AOE66P2G2IH4ZM/', 'name': 'FEDORA-2022-bb2daad935', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-787'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.0.5023', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:34:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Write in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T07:15Z | 2022-05-27T15:15Z | Out-of-bounds Write | The software writes data past the end, or before the beginning, of the intended buffer. | Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/787.html | 0 | Bram Moolenaar | 2022-05-26 15:56:23+01:00 | patch 8.2.5023: substitute overwrites allocated buffer
Problem: Substitute overwrites allocated buffer.
Solution: Disallow undo when in a substitute command. | 338f1fc0ee3ca929387448fe464579d6113fa76a | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | nv_gotofile | nv_gotofile( cmdarg_T * cap) | ['cap'] | nv_gotofile(cmdarg_T *cap)
{
char_u *ptr;
linenr_T lnum = -1;
if (text_locked())
{
clearopbeep(cap->oap);
text_locked_msg();
return;
}
if (curbuf_locked())
{
clearop(cap->oap);
return;
}
#ifdef FEAT_PROP_POPUP
if (ERROR_IF_TERM_POPUP_WINDOW)
return;
#endif
ptr = grab_file_name(cap->count1, &lnum);
if (ptr != NULL)
{
// do autowrite if necessary
if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf))
(void)autowrite(curbuf, FALSE);
setpcmark();
if (do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
buf_hide(curbuf) ? ECMD_HIDE : 0, curwin) == OK
&& cap->nchar == 'F' && lnum >= 0)
{
curwin->w_cursor.lnum = lnum;
check_cursor_lnum();
beginline(BL_SOL | BL_FIX);
}
vim_free(ptr);
}
else
clearop(cap->oap);
} | 186 | True | 1 |
CVE-2022-1942 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/67ca4d3b-9175-43c1-925c-72a7091bc071', 'name': 'https://huntr.dev/bounties/67ca4d3b-9175-43c1-925c-72a7091bc071', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/71223e2db87c2bf3b09aecb46266b56cda26191d', 'name': 'https://github.com/vim/vim/commit/71223e2db87c2bf3b09aecb46266b56cda26191d', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/TYNK6SDCMOLQJOI3B4AOE66P2G2IH4ZM/', 'name': 'FEDORA-2022-bb2daad935', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5043', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T18:53Z | 2022-05-31T14:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-05-30 15:23:09+01:00 | patch 8.2.5043: can open a cmdline window from a substitute expression
Problem: Can open a cmdline window from a substitute expression.
Solution: Disallow opening a command line window when text or buffer is
locked. | 71223e2db87c2bf3b09aecb46266b56cda26191d | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | buflist_getfile | buflist_getfile( int n , linenr_T lnum , int options , int forceit) | ['n', 'lnum', 'options', 'forceit'] | buflist_getfile(
int n,
linenr_T lnum,
int options,
int forceit)
{
buf_T *buf;
win_T *wp = NULL;
pos_T *fpos;
colnr_T col;
buf = buflist_findnr(n);
if (buf == NULL)
{
if ((options & GETF_ALT) && n == 0)
emsg(_(e_no_alternate_file));
else
semsg(_(e_buffer_nr_not_found), n);
return FAIL;
}
// if alternate file is the current buffer, nothing to do
if (buf == curbuf)
return OK;
if (text_locked())
{
text_locked_msg();
return FAIL;
}
if (curbuf_locked())
return FAIL;
// altfpos may be changed by getfile(), get it now
if (lnum == 0)
{
fpos = buflist_findfpos(buf);
lnum = fpos->lnum;
col = fpos->col;
}
else
col = 0;
if (options & GETF_SWITCH)
{
// If 'switchbuf' contains "useopen": jump to first window containing
// "buf" if one exists
if (swb_flags & SWB_USEOPEN)
wp = buf_jump_open_win(buf);
// If 'switchbuf' contains "usetab": jump to first window in any tab
// page containing "buf" if one exists
if (wp == NULL && (swb_flags & SWB_USETAB))
wp = buf_jump_open_tab(buf);
// If 'switchbuf' contains "split", "vsplit" or "newtab" and the
// current buffer isn't empty: open new tab or window
if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB))
&& !BUFEMPTY())
{
if (swb_flags & SWB_NEWTAB)
tabpage_new();
else if (win_split(0, (swb_flags & SWB_VSPLIT) ? WSP_VERT : 0)
== FAIL)
return FAIL;
RESET_BINDING(curwin);
}
}
++RedrawingDisabled;
if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL,
(options & GETF_SETMARK), lnum, forceit)))
{
--RedrawingDisabled;
// cursor is at to BOL and w_cursor.lnum is checked due to getfile()
if (!p_sol && col != 0)
{
curwin->w_cursor.col = col;
check_cursor_col();
curwin->w_cursor.coladd = 0;
curwin->w_set_curswant = TRUE;
}
return OK;
}
--RedrawingDisabled;
return FAIL;
} | 330 | True | 1 |
|
CVE-2022-1942 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/67ca4d3b-9175-43c1-925c-72a7091bc071', 'name': 'https://huntr.dev/bounties/67ca4d3b-9175-43c1-925c-72a7091bc071', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/71223e2db87c2bf3b09aecb46266b56cda26191d', 'name': 'https://github.com/vim/vim/commit/71223e2db87c2bf3b09aecb46266b56cda26191d', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/TYNK6SDCMOLQJOI3B4AOE66P2G2IH4ZM/', 'name': 'FEDORA-2022-bb2daad935', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5043', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T18:53Z | 2022-05-31T14:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-05-30 15:23:09+01:00 | patch 8.2.5043: can open a cmdline window from a substitute expression
Problem: Can open a cmdline window from a substitute expression.
Solution: Disallow opening a command line window when text or buffer is
locked. | 71223e2db87c2bf3b09aecb46266b56cda26191d | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | win_goto | win_goto( win_T * wp) | ['wp'] | win_goto(win_T *wp)
{
#ifdef FEAT_CONCEAL
win_T *owp = curwin;
#endif
#ifdef FEAT_PROP_POPUP
if (ERROR_IF_ANY_POPUP_WINDOW)
return;
if (popup_is_popup(wp))
{
emsg(_(e_not_allowed_to_enter_popup_window));
return;
}
#endif
if (text_locked())
{
beep_flush();
text_locked_msg();
return;
}
if (curbuf_locked())
return;
if (wp->w_buffer != curbuf)
reset_VIsual_and_resel();
else if (VIsual_active)
wp->w_cursor = curwin->w_cursor;
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
win_enter(wp, TRUE);
#ifdef FEAT_CONCEAL
// Conceal cursor line in previous window, unconceal in current window.
if (win_valid(owp) && owp->w_p_cole > 0 && !msg_scrolled)
redrawWinline(owp, owp->w_cursor.lnum);
if (curwin->w_p_cole > 0 && !msg_scrolled)
need_cursor_line_redraw = TRUE;
#endif
} | 143 | True | 1 |
|
CVE-2022-1968 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/949090e5-f4ea-4edf-bd79-cd98f0498a5b', 'name': 'https://huntr.dev/bounties/949090e5-f4ea-4edf-bd79-cd98f0498a5b', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/409510c588b1eec1ae33511ae97a21eb8e110895', 'name': 'https://github.com/vim/vim/commit/409510c588b1eec1ae33511ae97a21eb8e110895', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/06/msg00014.html', 'name': '[debian-lts-announce] 20220620 [SECURITY] [DLA 3053-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T18:53Z | 2022-06-02T14:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-06-01 15:23:13+01:00 | patch 8.2.5050: using freed memory when searching for pattern in path
Problem: Using freed memory when searching for pattern in path.
Solution: Make a copy of the line. | 409510c588b1eec1ae33511ae97a21eb8e110895 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | find_pattern_in_path | find_pattern_in_path( char_u * ptr , int dir UNUSED , int len , int whole , int skip_comments , int type , long count , int action , linenr_T start_lnum , linenr_T end_lnum) | ['ptr', 'UNUSED', 'len', 'whole', 'skip_comments', 'type', 'count', 'action', 'start_lnum', 'end_lnum'] | find_pattern_in_path(
char_u *ptr, // pointer to search pattern
int dir UNUSED, // direction of expansion
int len, // length of search pattern
int whole, // match whole words only
int skip_comments, // don't match inside comments
int type, // Type of search; are we looking for a type?
// a macro?
long count,
int action, // What to do when we find it
linenr_T start_lnum, // first line to start searching
linenr_T end_lnum) // last line for searching
{
SearchedFile *files; // Stack of included files
SearchedFile *bigger; // When we need more space
int max_path_depth = 50;
long match_count = 1;
char_u *pat;
char_u *new_fname;
char_u *curr_fname = curbuf->b_fname;
char_u *prev_fname = NULL;
linenr_T lnum;
int depth;
int depth_displayed; // For type==CHECK_PATH
int old_files;
int already_searched;
char_u *file_line;
char_u *line;
char_u *p;
char_u save_char;
int define_matched;
regmatch_T regmatch;
regmatch_T incl_regmatch;
regmatch_T def_regmatch;
int matched = FALSE;
int did_show = FALSE;
int found = FALSE;
int i;
char_u *already = NULL;
char_u *startp = NULL;
char_u *inc_opt = NULL;
#if defined(FEAT_QUICKFIX)
win_T *curwin_save = NULL;
#endif
regmatch.regprog = NULL;
incl_regmatch.regprog = NULL;
def_regmatch.regprog = NULL;
file_line = alloc(LSIZE);
if (file_line == NULL)
return;
if (type != CHECK_PATH && type != FIND_DEFINE
// when CONT_SOL is set compare "ptr" with the beginning of the
// line is faster than quote_meta/regcomp/regexec "ptr" -- Acevedo
&& !compl_status_sol())
{
pat = alloc(len + 5);
if (pat == NULL)
goto fpip_end;
sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr);
// ignore case according to p_ic, p_scs and pat
regmatch.rm_ic = ignorecase(pat);
regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
vim_free(pat);
if (regmatch.regprog == NULL)
goto fpip_end;
}
inc_opt = (*curbuf->b_p_inc == NUL) ? p_inc : curbuf->b_p_inc;
if (*inc_opt != NUL)
{
incl_regmatch.regprog = vim_regcomp(inc_opt,
magic_isset() ? RE_MAGIC : 0);
if (incl_regmatch.regprog == NULL)
goto fpip_end;
incl_regmatch.rm_ic = FALSE; // don't ignore case in incl. pat.
}
if (type == FIND_DEFINE && (*curbuf->b_p_def != NUL || *p_def != NUL))
{
def_regmatch.regprog = vim_regcomp(*curbuf->b_p_def == NUL
? p_def : curbuf->b_p_def,
magic_isset() ? RE_MAGIC : 0);
if (def_regmatch.regprog == NULL)
goto fpip_end;
def_regmatch.rm_ic = FALSE; // don't ignore case in define pat.
}
files = lalloc_clear(max_path_depth * sizeof(SearchedFile), TRUE);
if (files == NULL)
goto fpip_end;
old_files = max_path_depth;
depth = depth_displayed = -1;
lnum = start_lnum;
if (end_lnum > curbuf->b_ml.ml_line_count)
end_lnum = curbuf->b_ml.ml_line_count;
if (lnum > end_lnum) // do at least one line
lnum = end_lnum;
line = ml_get(lnum);
for (;;)
{
if (incl_regmatch.regprog != NULL
&& vim_regexec(&incl_regmatch, line, (colnr_T)0))
{
char_u *p_fname = (curr_fname == curbuf->b_fname)
? curbuf->b_ffname : curr_fname;
if (inc_opt != NULL && strstr((char *)inc_opt, "\\zs") != NULL)
// Use text from '\zs' to '\ze' (or end) of 'include'.
new_fname = find_file_name_in_path(incl_regmatch.startp[0],
(int)(incl_regmatch.endp[0] - incl_regmatch.startp[0]),
FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname);
else
// Use text after match with 'include'.
new_fname = file_name_in_line(incl_regmatch.endp[0], 0,
FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL);
already_searched = FALSE;
if (new_fname != NULL)
{
// Check whether we have already searched in this file
for (i = 0;; i++)
{
if (i == depth + 1)
i = old_files;
if (i == max_path_depth)
break;
if (fullpathcmp(new_fname, files[i].name, TRUE, TRUE)
& FPC_SAME)
{
if (type != CHECK_PATH
&& action == ACTION_SHOW_ALL
&& files[i].matched)
{
msg_putchar('\n'); // cursor below last one
if (!got_int) // don't display if 'q'
// typed at "--more--"
// message
{
msg_home_replace_hl(new_fname);
msg_puts(_(" (includes previously listed match)"));
prev_fname = NULL;
}
}
VIM_CLEAR(new_fname);
already_searched = TRUE;
break;
}
}
}
if (type == CHECK_PATH && (action == ACTION_SHOW_ALL
|| (new_fname == NULL && !already_searched)))
{
if (did_show)
msg_putchar('\n'); // cursor below last one
else
{
gotocmdline(TRUE); // cursor at status line
msg_puts_title(_("--- Included files "));
if (action != ACTION_SHOW_ALL)
msg_puts_title(_("not found "));
msg_puts_title(_("in path ---\n"));
}
did_show = TRUE;
while (depth_displayed < depth && !got_int)
{
++depth_displayed;
for (i = 0; i < depth_displayed; i++)
msg_puts(" ");
msg_home_replace(files[depth_displayed].name);
msg_puts(" -->\n");
}
if (!got_int) // don't display if 'q' typed
// for "--more--" message
{
for (i = 0; i <= depth_displayed; i++)
msg_puts(" ");
if (new_fname != NULL)
{
// using "new_fname" is more reliable, e.g., when
// 'includeexpr' is set.
msg_outtrans_attr(new_fname, HL_ATTR(HLF_D));
}
else
{
/*
* Isolate the file name.
* Include the surrounding "" or <> if present.
*/
if (inc_opt != NULL
&& strstr((char *)inc_opt, "\\zs") != NULL)
{
// pattern contains \zs, use the match
p = incl_regmatch.startp[0];
i = (int)(incl_regmatch.endp[0]
- incl_regmatch.startp[0]);
}
else
{
// find the file name after the end of the match
for (p = incl_regmatch.endp[0];
*p && !vim_isfilec(*p); p++)
;
for (i = 0; vim_isfilec(p[i]); i++)
;
}
if (i == 0)
{
// Nothing found, use the rest of the line.
p = incl_regmatch.endp[0];
i = (int)STRLEN(p);
}
// Avoid checking before the start of the line, can
// happen if \zs appears in the regexp.
else if (p > line)
{
if (p[-1] == '"' || p[-1] == '<')
{
--p;
++i;
}
if (p[i] == '"' || p[i] == '>')
++i;
}
save_char = p[i];
p[i] = NUL;
msg_outtrans_attr(p, HL_ATTR(HLF_D));
p[i] = save_char;
}
if (new_fname == NULL && action == ACTION_SHOW_ALL)
{
if (already_searched)
msg_puts(_(" (Already listed)"));
else
msg_puts(_(" NOT FOUND"));
}
}
out_flush(); // output each line directly
}
if (new_fname != NULL)
{
// Push the new file onto the file stack
if (depth + 1 == old_files)
{
bigger = ALLOC_MULT(SearchedFile, max_path_depth * 2);
if (bigger != NULL)
{
for (i = 0; i <= depth; i++)
bigger[i] = files[i];
for (i = depth + 1; i < old_files + max_path_depth; i++)
{
bigger[i].fp = NULL;
bigger[i].name = NULL;
bigger[i].lnum = 0;
bigger[i].matched = FALSE;
}
for (i = old_files; i < max_path_depth; i++)
bigger[i + max_path_depth] = files[i];
old_files += max_path_depth;
max_path_depth *= 2;
vim_free(files);
files = bigger;
}
}
if ((files[depth + 1].fp = mch_fopen((char *)new_fname, "r"))
== NULL)
vim_free(new_fname);
else
{
if (++depth == old_files)
{
/*
* lalloc() for 'bigger' must have failed above. We
* will forget one of our already visited files now.
*/
vim_free(files[old_files].name);
++old_files;
}
files[depth].name = curr_fname = new_fname;
files[depth].lnum = 0;
files[depth].matched = FALSE;
if (action == ACTION_EXPAND)
{
msg_hist_off = TRUE; // reset in msg_trunc_attr()
vim_snprintf((char*)IObuff, IOSIZE,
_("Scanning included file: %s"),
(char *)new_fname);
msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R));
}
else if (p_verbose >= 5)
{
verbose_enter();
smsg(_("Searching included file %s"),
(char *)new_fname);
verbose_leave();
}
}
}
}
else
{
/*
* Check if the line is a define (type == FIND_DEFINE)
*/
p = line;
search_line:
define_matched = FALSE;
if (def_regmatch.regprog != NULL
&& vim_regexec(&def_regmatch, line, (colnr_T)0))
{
/*
* Pattern must be first identifier after 'define', so skip
* to that position before checking for match of pattern. Also
* don't let it match beyond the end of this identifier.
*/
p = def_regmatch.endp[0];
while (*p && !vim_iswordc(*p))
p++;
define_matched = TRUE;
}
/*
* Look for a match. Don't do this if we are looking for a
* define and this line didn't match define_prog above.
*/
if (def_regmatch.regprog == NULL || define_matched)
{
if (define_matched || compl_status_sol())
{
// compare the first "len" chars from "ptr"
startp = skipwhite(p);
if (p_ic)
matched = !MB_STRNICMP(startp, ptr, len);
else
matched = !STRNCMP(startp, ptr, len);
if (matched && define_matched && whole
&& vim_iswordc(startp[len]))
matched = FALSE;
}
else if (regmatch.regprog != NULL
&& vim_regexec(®match, line, (colnr_T)(p - line)))
{
matched = TRUE;
startp = regmatch.startp[0];
/*
* Check if the line is not a comment line (unless we are
* looking for a define). A line starting with "# define"
* is not considered to be a comment line.
*/
if (!define_matched && skip_comments)
{
if ((*line != '#' ||
STRNCMP(skipwhite(line + 1), "define", 6) != 0)
&& get_leader_len(line, NULL, FALSE, TRUE))
matched = FALSE;
/*
* Also check for a "/ *" or "/ /" before the match.
* Skips lines like "int backwards; / * normal index
* * /" when looking for "normal".
* Note: Doesn't skip "/ *" in comments.
*/
p = skipwhite(line);
if (matched
|| (p[0] == '/' && p[1] == '*') || p[0] == '*')
for (p = line; *p && p < startp; ++p)
{
if (matched
&& p[0] == '/'
&& (p[1] == '*' || p[1] == '/'))
{
matched = FALSE;
// After "//" all text is comment
if (p[1] == '/')
break;
++p;
}
else if (!matched && p[0] == '*' && p[1] == '/')
{
// Can find match after "* /".
matched = TRUE;
++p;
}
}
}
}
}
}
if (matched)
{
if (action == ACTION_EXPAND)
{
int cont_s_ipos = FALSE;
int add_r;
char_u *aux;
if (depth == -1 && lnum == curwin->w_cursor.lnum)
break;
found = TRUE;
aux = p = startp;
if (compl_status_adding())
{
p += ins_compl_len();
if (vim_iswordp(p))
goto exit_matched;
p = find_word_start(p);
}
p = find_word_end(p);
i = (int)(p - aux);
if (compl_status_adding() && i == ins_compl_len())
{
// IOSIZE > compl_length, so the STRNCPY works
STRNCPY(IObuff, aux, i);
// Get the next line: when "depth" < 0 from the current
// buffer, otherwise from the included file. Jump to
// exit_matched when past the last line.
if (depth < 0)
{
if (lnum >= end_lnum)
goto exit_matched;
line = ml_get(++lnum);
}
else if (vim_fgets(line = file_line,
LSIZE, files[depth].fp))
goto exit_matched;
// we read a line, set "already" to check this "line" later
// if depth >= 0 we'll increase files[depth].lnum far
// below -- Acevedo
already = aux = p = skipwhite(line);
p = find_word_start(p);
p = find_word_end(p);
if (p > aux)
{
if (*aux != ')' && IObuff[i-1] != TAB)
{
if (IObuff[i-1] != ' ')
IObuff[i++] = ' ';
// IObuf =~ "\(\k\|\i\).* ", thus i >= 2
if (p_js
&& (IObuff[i-2] == '.'
|| (vim_strchr(p_cpo, CPO_JOINSP) == NULL
&& (IObuff[i-2] == '?'
|| IObuff[i-2] == '!'))))
IObuff[i++] = ' ';
}
// copy as much as possible of the new word
if (p - aux >= IOSIZE - i)
p = aux + IOSIZE - i - 1;
STRNCPY(IObuff + i, aux, p - aux);
i += (int)(p - aux);
cont_s_ipos = TRUE;
}
IObuff[i] = NUL;
aux = IObuff;
if (i == ins_compl_len())
goto exit_matched;
}
add_r = ins_compl_add_infercase(aux, i, p_ic,
curr_fname == curbuf->b_fname ? NULL : curr_fname,
dir, cont_s_ipos);
if (add_r == OK)
// if dir was BACKWARD then honor it just once
dir = FORWARD;
else if (add_r == FAIL)
break;
}
else if (action == ACTION_SHOW_ALL)
{
found = TRUE;
if (!did_show)
gotocmdline(TRUE); // cursor at status line
if (curr_fname != prev_fname)
{
if (did_show)
msg_putchar('\n'); // cursor below last one
if (!got_int) // don't display if 'q' typed
// at "--more--" message
msg_home_replace_hl(curr_fname);
prev_fname = curr_fname;
}
did_show = TRUE;
if (!got_int)
show_pat_in_path(line, type, TRUE, action,
(depth == -1) ? NULL : files[depth].fp,
(depth == -1) ? &lnum : &files[depth].lnum,
match_count++);
// Set matched flag for this file and all the ones that
// include it
for (i = 0; i <= depth; ++i)
files[i].matched = TRUE;
}
else if (--count <= 0)
{
found = TRUE;
if (depth == -1 && lnum == curwin->w_cursor.lnum
#if defined(FEAT_QUICKFIX)
&& g_do_tagpreview == 0
#endif
)
emsg(_(e_match_is_on_current_line));
else if (action == ACTION_SHOW)
{
show_pat_in_path(line, type, did_show, action,
(depth == -1) ? NULL : files[depth].fp,
(depth == -1) ? &lnum : &files[depth].lnum, 1L);
did_show = TRUE;
}
else
{
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
#endif
#if defined(FEAT_QUICKFIX)
// ":psearch" uses the preview window
if (g_do_tagpreview != 0)
{
curwin_save = curwin;
prepare_tagpreview(TRUE, TRUE, FALSE);
}
#endif
if (action == ACTION_SPLIT)
{
if (win_split(0, 0) == FAIL)
break;
RESET_BINDING(curwin);
}
if (depth == -1)
{
// match in current file
#if defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
if (!win_valid(curwin_save))
break;
if (!GETFILE_SUCCESS(getfile(
curwin_save->w_buffer->b_fnum, NULL,
NULL, TRUE, lnum, FALSE)))
break; // failed to jump to file
}
else
#endif
setpcmark();
curwin->w_cursor.lnum = lnum;
check_cursor();
}
else
{
if (!GETFILE_SUCCESS(getfile(
0, files[depth].name, NULL, TRUE,
files[depth].lnum, FALSE)))
break; // failed to jump to file
// autocommands may have changed the lnum, we don't
// want that here
curwin->w_cursor.lnum = files[depth].lnum;
}
}
if (action != ACTION_SHOW)
{
curwin->w_cursor.col = (colnr_T)(startp - line);
curwin->w_set_curswant = TRUE;
}
#if defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0
&& curwin != curwin_save && win_valid(curwin_save))
{
// Return cursor to where we were
validate_cursor();
redraw_later(VALID);
win_enter(curwin_save, TRUE);
}
# ifdef FEAT_PROP_POPUP
else if (WIN_IS_POPUP(curwin))
// can't keep focus in popup window
win_enter(firstwin, TRUE);
# endif
#endif
break;
}
exit_matched:
matched = FALSE;
// look for other matches in the rest of the line if we
// are not at the end of it already
if (def_regmatch.regprog == NULL
&& action == ACTION_EXPAND
&& !compl_status_sol()
&& *startp != NUL
&& *(p = startp + mb_ptr2len(startp)) != NUL)
goto search_line;
}
line_breakcheck();
if (action == ACTION_EXPAND)
ins_compl_check_keys(30, FALSE);
if (got_int || ins_compl_interrupted())
break;
/*
* Read the next line. When reading an included file and encountering
* end-of-file, close the file and continue in the file that included
* it.
*/
while (depth >= 0 && !already
&& vim_fgets(line = file_line, LSIZE, files[depth].fp))
{
fclose(files[depth].fp);
--old_files;
files[old_files].name = files[depth].name;
files[old_files].matched = files[depth].matched;
--depth;
curr_fname = (depth == -1) ? curbuf->b_fname
: files[depth].name;
if (depth < depth_displayed)
depth_displayed = depth;
}
if (depth >= 0) // we could read the line
{
files[depth].lnum++;
// Remove any CR and LF from the line.
i = (int)STRLEN(line);
if (i > 0 && line[i - 1] == '\n')
line[--i] = NUL;
if (i > 0 && line[i - 1] == '\r')
line[--i] = NUL;
}
else if (!already)
{
if (++lnum > end_lnum)
break;
line = ml_get(lnum);
}
already = NULL;
}
// End of big for (;;) loop.
// Close any files that are still open.
for (i = 0; i <= depth; i++)
{
fclose(files[i].fp);
vim_free(files[i].name);
}
for (i = old_files; i < max_path_depth; i++)
vim_free(files[i].name);
vim_free(files);
if (type == CHECK_PATH)
{
if (!did_show)
{
if (action != ACTION_SHOW_ALL)
msg(_("All included files were found"));
else
msg(_("No included files"));
}
}
else if (!found && action != ACTION_EXPAND)
{
if (got_int || ins_compl_interrupted())
emsg(_(e_interrupted));
else if (type == FIND_DEFINE)
emsg(_(e_couldnt_find_definition));
else
emsg(_(e_couldnt_find_pattern));
}
if (action == ACTION_SHOW || action == ACTION_SHOW_ALL)
msg_end();
fpip_end:
vim_free(file_line);
vim_regfree(regmatch.regprog);
vim_regfree(incl_regmatch.regprog);
vim_regfree(def_regmatch.regprog);
} | 3211 | True | 1 |
CVE-2022-2042 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/8628b4cd-4055-4059-aed4-64f7fdc10eba', 'name': 'https://huntr.dev/bounties/8628b4cd-4055-4059-aed4-64f7fdc10eba', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/2813f38e021c6e6581c0c88fcf107e41788bc835', 'name': 'https://github.com/vim/vim/commit/2813f38e021c6e6581c0c88fcf107e41788bc835', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T05:15Z | 2022-06-10T19:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-06-09 19:54:24+01:00 | patch 8.2.5072: using uninitialized value and freed memory in spell command
Problem: Using uninitialized value and freed memory in spell command.
Solution: Initialize "attr". Check for empty line early. | 2813f38e021c6e6581c0c88fcf107e41788bc835 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | spell_move_to | spell_move_to( win_T * wp , int dir , int allwords , int curline , hlf_T * attrp) | ['wp', 'dir', 'allwords', 'curline', 'attrp'] | spell_move_to(
win_T *wp,
int dir, // FORWARD or BACKWARD
int allwords, // TRUE for "[s"/"]s", FALSE for "[S"/"]S"
int curline,
hlf_T *attrp) // return: attributes of bad word or NULL
// (only when "dir" is FORWARD)
{
linenr_T lnum;
pos_T found_pos;
int found_len = 0;
char_u *line;
char_u *p;
char_u *endp;
hlf_T attr;
int len;
#ifdef FEAT_SYN_HL
int has_syntax = syntax_present(wp);
#endif
int col;
int can_spell;
char_u *buf = NULL;
int buflen = 0;
int skip = 0;
int capcol = -1;
int found_one = FALSE;
int wrapped = FALSE;
if (no_spell_checking(wp))
return 0;
/*
* Start looking for bad word at the start of the line, because we can't
* start halfway a word, we don't know where it starts or ends.
*
* When searching backwards, we continue in the line to find the last
* bad word (in the cursor line: before the cursor).
*
* We concatenate the start of the next line, so that wrapped words work
* (e.g. "et<line-break>cetera"). Doesn't work when searching backwards
* though...
*/
lnum = wp->w_cursor.lnum;
CLEAR_POS(&found_pos);
while (!got_int)
{
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
len = (int)STRLEN(line);
if (buflen < len + MAXWLEN + 2)
{
vim_free(buf);
buflen = len + MAXWLEN + 2;
buf = alloc(buflen);
if (buf == NULL)
break;
}
// In first line check first word for Capital.
if (lnum == 1)
capcol = 0;
// For checking first word with a capital skip white space.
if (capcol == 0)
capcol = getwhitecols(line);
else if (curline && wp == curwin)
{
// For spellbadword(): check if first word needs a capital.
col = getwhitecols(line);
if (check_need_cap(lnum, col))
capcol = col;
// Need to get the line again, may have looked at the previous
// one.
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
}
// Copy the line into "buf" and append the start of the next line if
// possible.
STRCPY(buf, line);
if (lnum < wp->w_buffer->b_ml.ml_line_count)
spell_cat_line(buf + STRLEN(buf),
ml_get_buf(wp->w_buffer, lnum + 1, FALSE), MAXWLEN);
p = buf + skip;
endp = buf + len;
while (p < endp)
{
// When searching backward don't search after the cursor. Unless
// we wrapped around the end of the buffer.
if (dir == BACKWARD
&& lnum == wp->w_cursor.lnum
&& !wrapped
&& (colnr_T)(p - buf) >= wp->w_cursor.col)
break;
// start of word
attr = HLF_COUNT;
len = spell_check(wp, p, &attr, &capcol, FALSE);
if (attr != HLF_COUNT)
{
// We found a bad word. Check the attribute.
if (allwords || attr == HLF_SPB)
{
// When searching forward only accept a bad word after
// the cursor.
if (dir == BACKWARD
|| lnum != wp->w_cursor.lnum
|| (wrapped
|| (colnr_T)(curline ? p - buf + len
: p - buf)
> wp->w_cursor.col))
{
#ifdef FEAT_SYN_HL
if (has_syntax)
{
col = (int)(p - buf);
(void)syn_get_id(wp, lnum, (colnr_T)col,
FALSE, &can_spell, FALSE);
if (!can_spell)
attr = HLF_COUNT;
}
else
#endif
can_spell = TRUE;
if (can_spell)
{
found_one = TRUE;
found_pos.lnum = lnum;
found_pos.col = (int)(p - buf);
found_pos.coladd = 0;
if (dir == FORWARD)
{
// No need to search further.
wp->w_cursor = found_pos;
vim_free(buf);
if (attrp != NULL)
*attrp = attr;
return len;
}
else if (curline)
// Insert mode completion: put cursor after
// the bad word.
found_pos.col += len;
found_len = len;
}
}
else
found_one = TRUE;
}
}
// advance to character after the word
p += len;
capcol -= len;
}
if (dir == BACKWARD && found_pos.lnum != 0)
{
// Use the last match in the line (before the cursor).
wp->w_cursor = found_pos;
vim_free(buf);
return found_len;
}
if (curline)
break; // only check cursor line
// If we are back at the starting line and searched it again there
// is no match, give up.
if (lnum == wp->w_cursor.lnum && wrapped)
break;
// Advance to next line.
if (dir == BACKWARD)
{
if (lnum > 1)
--lnum;
else if (!p_ws)
break; // at first line and 'nowrapscan'
else
{
// Wrap around to the end of the buffer. May search the
// starting line again and accept the last match.
lnum = wp->w_buffer->b_ml.ml_line_count;
wrapped = TRUE;
if (!shortmess(SHM_SEARCH))
give_warning((char_u *)_(top_bot_msg), TRUE);
}
capcol = -1;
}
else
{
if (lnum < wp->w_buffer->b_ml.ml_line_count)
++lnum;
else if (!p_ws)
break; // at first line and 'nowrapscan'
else
{
// Wrap around to the start of the buffer. May search the
// starting line again and accept the first match.
lnum = 1;
wrapped = TRUE;
if (!shortmess(SHM_SEARCH))
give_warning((char_u *)_(bot_top_msg), TRUE);
}
// If we are back at the starting line and there is no match then
// give up.
if (lnum == wp->w_cursor.lnum && !found_one)
break;
// Skip the characters at the start of the next line that were
// included in a match crossing line boundaries.
if (attr == HLF_COUNT)
skip = (int)(p - endp);
else
skip = 0;
// Capcol skips over the inserted space.
--capcol;
// But after empty line check first word in next line
if (*skipwhite(line) == NUL)
capcol = 0;
}
line_breakcheck();
}
vim_free(buf);
return 0;
} | 828 | True | 1 |
CVE-2022-2126 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/156d3911952d73b03d7420dc3540215247db0fe8', 'name': 'https://github.com/vim/vim/commit/156d3911952d73b03d7420dc3540215247db0fe8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/8d196d9b-3d10-41d2-9f70-8ef0d08c946e', 'name': 'https://huntr.dev/bounties/8d196d9b-3d10-41d2-9f70-8ef0d08c946e', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/06/msg00014.html', 'name': '[debian-lts-announce] 20220620 [SECURITY] [DLA 3053-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-125'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5123', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Read in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T08:15Z | 2022-06-19T13:15Z | Out-of-bounds Read | The software reads data past the end, or before the beginning, of the intended buffer. | Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/125.html | 0 | Bram Moolenaar | 2022-06-18 14:09:08+01:00 | patch 8.2.5123: using invalid index when looking for spell suggestions
Problem: Using invalid index when looking for spell suggestions.
Solution: Do not decrement the index when it is zero. | 156d3911952d73b03d7420dc3540215247db0fe8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | suggest_trie_walk | suggest_trie_walk( suginfo_T * su , langp_T * lp , char_u * fword , int soundfold) | ['su', 'lp', 'fword', 'soundfold'] | suggest_trie_walk(
suginfo_T *su,
langp_T *lp,
char_u *fword,
int soundfold)
{
char_u tword[MAXWLEN]; // good word collected so far
trystate_T stack[MAXWLEN];
char_u preword[MAXWLEN * 3]; // word found with proper case;
// concatenation of prefix compound
// words and split word. NUL terminated
// when going deeper but not when coming
// back.
char_u compflags[MAXWLEN]; // compound flags, one for each word
trystate_T *sp;
int newscore;
int score;
char_u *byts, *fbyts, *pbyts;
idx_T *idxs, *fidxs, *pidxs;
int depth;
int c, c2, c3;
int n = 0;
int flags;
garray_T *gap;
idx_T arridx;
int len;
char_u *p;
fromto_T *ftp;
int fl = 0, tl;
int repextra = 0; // extra bytes in fword[] from REP item
slang_T *slang = lp->lp_slang;
int fword_ends;
int goodword_ends;
#ifdef DEBUG_TRIEWALK
// Stores the name of the change made at each level.
char_u changename[MAXWLEN][80];
#endif
int breakcheckcount = 1000;
#ifdef FEAT_RELTIME
proftime_T time_limit;
#endif
int compound_ok;
// Go through the whole case-fold tree, try changes at each node.
// "tword[]" contains the word collected from nodes in the tree.
// "fword[]" the word we are trying to match with (initially the bad
// word).
depth = 0;
sp = &stack[0];
CLEAR_POINTER(sp);
sp->ts_curi = 1;
if (soundfold)
{
// Going through the soundfold tree.
byts = fbyts = slang->sl_sbyts;
idxs = fidxs = slang->sl_sidxs;
pbyts = NULL;
pidxs = NULL;
sp->ts_prefixdepth = PFD_NOPREFIX;
sp->ts_state = STATE_START;
}
else
{
// When there are postponed prefixes we need to use these first. At
// the end of the prefix we continue in the case-fold tree.
fbyts = slang->sl_fbyts;
fidxs = slang->sl_fidxs;
pbyts = slang->sl_pbyts;
pidxs = slang->sl_pidxs;
if (pbyts != NULL)
{
byts = pbyts;
idxs = pidxs;
sp->ts_prefixdepth = PFD_PREFIXTREE;
sp->ts_state = STATE_NOPREFIX; // try without prefix first
}
else
{
byts = fbyts;
idxs = fidxs;
sp->ts_prefixdepth = PFD_NOPREFIX;
sp->ts_state = STATE_START;
}
}
#ifdef FEAT_RELTIME
// The loop may take an indefinite amount of time. Break out after some
// time.
if (spell_suggest_timeout > 0)
profile_setlimit(spell_suggest_timeout, &time_limit);
#endif
// Loop to find all suggestions. At each round we either:
// - For the current state try one operation, advance "ts_curi",
// increase "depth".
// - When a state is done go to the next, set "ts_state".
// - When all states are tried decrease "depth".
while (depth >= 0 && !got_int)
{
sp = &stack[depth];
switch (sp->ts_state)
{
case STATE_START:
case STATE_NOPREFIX:
// Start of node: Deal with NUL bytes, which means
// tword[] may end here.
arridx = sp->ts_arridx; // current node in the tree
len = byts[arridx]; // bytes in this node
arridx += sp->ts_curi; // index of current byte
if (sp->ts_prefixdepth == PFD_PREFIXTREE)
{
// Skip over the NUL bytes, we use them later.
for (n = 0; n < len && byts[arridx + n] == 0; ++n)
;
sp->ts_curi += n;
// Always past NUL bytes now.
n = (int)sp->ts_state;
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_ENDNUL;
sp->ts_save_badflags = su->su_badflags;
// At end of a prefix or at start of prefixtree: check for
// following word.
if (depth < MAXWLEN - 1
&& (byts[arridx] == 0 || n == (int)STATE_NOPREFIX))
{
// Set su->su_badflags to the caps type at this position.
// Use the caps type until here for the prefix itself.
if (has_mbyte)
n = nofold_len(fword, sp->ts_fidx, su->su_badptr);
else
n = sp->ts_fidx;
flags = badword_captype(su->su_badptr, su->su_badptr + n);
su->su_badflags = badword_captype(su->su_badptr + n,
su->su_badptr + su->su_badlen);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "prefix");
#endif
go_deeper(stack, depth, 0);
++depth;
sp = &stack[depth];
sp->ts_prefixdepth = depth - 1;
byts = fbyts;
idxs = fidxs;
sp->ts_arridx = 0;
// Move the prefix to preword[] with the right case
// and make find_keepcap_word() works.
tword[sp->ts_twordlen] = NUL;
make_case_word(tword + sp->ts_splitoff,
preword + sp->ts_prewordlen, flags);
sp->ts_prewordlen = (char_u)STRLEN(preword);
sp->ts_splitoff = sp->ts_twordlen;
}
break;
}
if (sp->ts_curi > len || byts[arridx] != 0)
{
// Past bytes in node and/or past NUL bytes.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_ENDNUL;
sp->ts_save_badflags = su->su_badflags;
break;
}
// End of word in tree.
++sp->ts_curi; // eat one NUL byte
flags = (int)idxs[arridx];
// Skip words with the NOSUGGEST flag.
if (flags & WF_NOSUGGEST)
break;
fword_ends = (fword[sp->ts_fidx] == NUL
|| (soundfold
? VIM_ISWHITE(fword[sp->ts_fidx])
: !spell_iswordp(fword + sp->ts_fidx, curwin)));
tword[sp->ts_twordlen] = NUL;
if (sp->ts_prefixdepth <= PFD_NOTSPECIAL
&& (sp->ts_flags & TSF_PREFIXOK) == 0
&& pbyts != NULL)
{
// There was a prefix before the word. Check that the prefix
// can be used with this word.
// Count the length of the NULs in the prefix. If there are
// none this must be the first try without a prefix.
n = stack[sp->ts_prefixdepth].ts_arridx;
len = pbyts[n++];
for (c = 0; c < len && pbyts[n + c] == 0; ++c)
;
if (c > 0)
{
c = valid_word_prefix(c, n, flags,
tword + sp->ts_splitoff, slang, FALSE);
if (c == 0)
break;
// Use the WF_RARE flag for a rare prefix.
if (c & WF_RAREPFX)
flags |= WF_RARE;
// Tricky: when checking for both prefix and compounding
// we run into the prefix flag first.
// Remember that it's OK, so that we accept the prefix
// when arriving at a compound flag.
sp->ts_flags |= TSF_PREFIXOK;
}
}
// Check NEEDCOMPOUND: can't use word without compounding. Do try
// appending another compound word below.
if (sp->ts_complen == sp->ts_compsplit && fword_ends
&& (flags & WF_NEEDCOMP))
goodword_ends = FALSE;
else
goodword_ends = TRUE;
p = NULL;
compound_ok = TRUE;
if (sp->ts_complen > sp->ts_compsplit)
{
if (slang->sl_nobreak)
{
// There was a word before this word. When there was no
// change in this word (it was correct) add the first word
// as a suggestion. If this word was corrected too, we
// need to check if a correct word follows.
if (sp->ts_fidx - sp->ts_splitfidx
== sp->ts_twordlen - sp->ts_splitoff
&& STRNCMP(fword + sp->ts_splitfidx,
tword + sp->ts_splitoff,
sp->ts_fidx - sp->ts_splitfidx) == 0)
{
preword[sp->ts_prewordlen] = NUL;
newscore = score_wordcount_adj(slang, sp->ts_score,
preword + sp->ts_prewordlen,
sp->ts_prewordlen > 0);
// Add the suggestion if the score isn't too bad.
if (newscore <= su->su_maxscore)
add_suggestion(su, &su->su_ga, preword,
sp->ts_splitfidx - repextra,
newscore, 0, FALSE,
lp->lp_sallang, FALSE);
break;
}
}
else
{
// There was a compound word before this word. If this
// word does not support compounding then give up
// (splitting is tried for the word without compound
// flag).
if (((unsigned)flags >> 24) == 0
|| sp->ts_twordlen - sp->ts_splitoff
< slang->sl_compminlen)
break;
// For multi-byte chars check character length against
// COMPOUNDMIN.
if (has_mbyte
&& slang->sl_compminlen > 0
&& mb_charlen(tword + sp->ts_splitoff)
< slang->sl_compminlen)
break;
compflags[sp->ts_complen] = ((unsigned)flags >> 24);
compflags[sp->ts_complen + 1] = NUL;
vim_strncpy(preword + sp->ts_prewordlen,
tword + sp->ts_splitoff,
sp->ts_twordlen - sp->ts_splitoff);
// Verify CHECKCOMPOUNDPATTERN rules.
if (match_checkcompoundpattern(preword, sp->ts_prewordlen,
&slang->sl_comppat))
compound_ok = FALSE;
if (compound_ok)
{
p = preword;
while (*skiptowhite(p) != NUL)
p = skipwhite(skiptowhite(p));
if (fword_ends && !can_compound(slang, p,
compflags + sp->ts_compsplit))
// Compound is not allowed. But it may still be
// possible if we add another (short) word.
compound_ok = FALSE;
}
// Get pointer to last char of previous word.
p = preword + sp->ts_prewordlen;
MB_PTR_BACK(preword, p);
}
}
// Form the word with proper case in preword.
// If there is a word from a previous split, append.
// For the soundfold tree don't change the case, simply append.
if (soundfold)
STRCPY(preword + sp->ts_prewordlen, tword + sp->ts_splitoff);
else if (flags & WF_KEEPCAP)
// Must find the word in the keep-case tree.
find_keepcap_word(slang, tword + sp->ts_splitoff,
preword + sp->ts_prewordlen);
else
{
// Include badflags: If the badword is onecap or allcap
// use that for the goodword too. But if the badword is
// allcap and it's only one char long use onecap.
c = su->su_badflags;
if ((c & WF_ALLCAP)
&& su->su_badlen == (*mb_ptr2len)(su->su_badptr))
c = WF_ONECAP;
c |= flags;
// When appending a compound word after a word character don't
// use Onecap.
if (p != NULL && spell_iswordp_nmw(p, curwin))
c &= ~WF_ONECAP;
make_case_word(tword + sp->ts_splitoff,
preword + sp->ts_prewordlen, c);
}
if (!soundfold)
{
// Don't use a banned word. It may appear again as a good
// word, thus remember it.
if (flags & WF_BANNED)
{
add_banned(su, preword + sp->ts_prewordlen);
break;
}
if ((sp->ts_complen == sp->ts_compsplit
&& WAS_BANNED(su, preword + sp->ts_prewordlen))
|| WAS_BANNED(su, preword))
{
if (slang->sl_compprog == NULL)
break;
// the word so far was banned but we may try compounding
goodword_ends = FALSE;
}
}
newscore = 0;
if (!soundfold) // soundfold words don't have flags
{
if ((flags & WF_REGION)
&& (((unsigned)flags >> 16) & lp->lp_region) == 0)
newscore += SCORE_REGION;
if (flags & WF_RARE)
newscore += SCORE_RARE;
if (!spell_valid_case(su->su_badflags,
captype(preword + sp->ts_prewordlen, NULL)))
newscore += SCORE_ICASE;
}
// TODO: how about splitting in the soundfold tree?
if (fword_ends
&& goodword_ends
&& sp->ts_fidx >= sp->ts_fidxtry
&& compound_ok)
{
// The badword also ends: add suggestions.
#ifdef DEBUG_TRIEWALK
if (soundfold && STRCMP(preword, "smwrd") == 0)
{
int j;
// print the stack of changes that brought us here
smsg("------ %s -------", fword);
for (j = 0; j < depth; ++j)
smsg("%s", changename[j]);
}
#endif
if (soundfold)
{
// For soundfolded words we need to find the original
// words, the edit distance and then add them.
add_sound_suggest(su, preword, sp->ts_score, lp);
}
else if (sp->ts_fidx > 0)
{
// Give a penalty when changing non-word char to word
// char, e.g., "thes," -> "these".
p = fword + sp->ts_fidx;
MB_PTR_BACK(fword, p);
if (!spell_iswordp(p, curwin) && *preword != NUL)
{
p = preword + STRLEN(preword);
MB_PTR_BACK(preword, p);
if (spell_iswordp(p, curwin))
newscore += SCORE_NONWORD;
}
// Give a bonus to words seen before.
score = score_wordcount_adj(slang,
sp->ts_score + newscore,
preword + sp->ts_prewordlen,
sp->ts_prewordlen > 0);
// Add the suggestion if the score isn't too bad.
if (score <= su->su_maxscore)
{
add_suggestion(su, &su->su_ga, preword,
sp->ts_fidx - repextra,
score, 0, FALSE, lp->lp_sallang, FALSE);
if (su->su_badflags & WF_MIXCAP)
{
// We really don't know if the word should be
// upper or lower case, add both.
c = captype(preword, NULL);
if (c == 0 || c == WF_ALLCAP)
{
make_case_word(tword + sp->ts_splitoff,
preword + sp->ts_prewordlen,
c == 0 ? WF_ALLCAP : 0);
add_suggestion(su, &su->su_ga, preword,
sp->ts_fidx - repextra,
score + SCORE_ICASE, 0, FALSE,
lp->lp_sallang, FALSE);
}
}
}
}
}
// Try word split and/or compounding.
if ((sp->ts_fidx >= sp->ts_fidxtry || fword_ends)
// Don't split halfway a character.
&& (!has_mbyte || sp->ts_tcharlen == 0))
{
int try_compound;
int try_split;
// If past the end of the bad word don't try a split.
// Otherwise try changing the next word. E.g., find
// suggestions for "the the" where the second "the" is
// different. It's done like a split.
// TODO: word split for soundfold words
try_split = (sp->ts_fidx - repextra < su->su_badlen)
&& !soundfold;
// Get here in several situations:
// 1. The word in the tree ends:
// If the word allows compounding try that. Otherwise try
// a split by inserting a space. For both check that a
// valid words starts at fword[sp->ts_fidx].
// For NOBREAK do like compounding to be able to check if
// the next word is valid.
// 2. The badword does end, but it was due to a change (e.g.,
// a swap). No need to split, but do check that the
// following word is valid.
// 3. The badword and the word in the tree end. It may still
// be possible to compound another (short) word.
try_compound = FALSE;
if (!soundfold
&& !slang->sl_nocompoundsugs
&& slang->sl_compprog != NULL
&& ((unsigned)flags >> 24) != 0
&& sp->ts_twordlen - sp->ts_splitoff
>= slang->sl_compminlen
&& (!has_mbyte
|| slang->sl_compminlen == 0
|| mb_charlen(tword + sp->ts_splitoff)
>= slang->sl_compminlen)
&& (slang->sl_compsylmax < MAXWLEN
|| sp->ts_complen + 1 - sp->ts_compsplit
< slang->sl_compmax)
&& (can_be_compound(sp, slang,
compflags, ((unsigned)flags >> 24))))
{
try_compound = TRUE;
compflags[sp->ts_complen] = ((unsigned)flags >> 24);
compflags[sp->ts_complen + 1] = NUL;
}
// For NOBREAK we never try splitting, it won't make any word
// valid.
if (slang->sl_nobreak && !slang->sl_nocompoundsugs)
try_compound = TRUE;
// If we could add a compound word, and it's also possible to
// split at this point, do the split first and set
// TSF_DIDSPLIT to avoid doing it again.
else if (!fword_ends
&& try_compound
&& (sp->ts_flags & TSF_DIDSPLIT) == 0)
{
try_compound = FALSE;
sp->ts_flags |= TSF_DIDSPLIT;
--sp->ts_curi; // do the same NUL again
compflags[sp->ts_complen] = NUL;
}
else
sp->ts_flags &= ~TSF_DIDSPLIT;
if (try_split || try_compound)
{
if (!try_compound && (!fword_ends || !goodword_ends))
{
// If we're going to split need to check that the
// words so far are valid for compounding. If there
// is only one word it must not have the NEEDCOMPOUND
// flag.
if (sp->ts_complen == sp->ts_compsplit
&& (flags & WF_NEEDCOMP))
break;
p = preword;
while (*skiptowhite(p) != NUL)
p = skipwhite(skiptowhite(p));
if (sp->ts_complen > sp->ts_compsplit
&& !can_compound(slang, p,
compflags + sp->ts_compsplit))
break;
if (slang->sl_nosplitsugs)
newscore += SCORE_SPLIT_NO;
else
newscore += SCORE_SPLIT;
// Give a bonus to words seen before.
newscore = score_wordcount_adj(slang, newscore,
preword + sp->ts_prewordlen, TRUE);
}
if (TRY_DEEPER(su, stack, depth, newscore))
{
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
if (!try_compound && !fword_ends)
sprintf(changename[depth], "%.*s-%s: split",
sp->ts_twordlen, tword, fword + sp->ts_fidx);
else
sprintf(changename[depth], "%.*s-%s: compound",
sp->ts_twordlen, tword, fword + sp->ts_fidx);
#endif
// Save things to be restored at STATE_SPLITUNDO.
sp->ts_save_badflags = su->su_badflags;
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SPLITUNDO;
++depth;
sp = &stack[depth];
// Append a space to preword when splitting.
if (!try_compound && !fword_ends)
STRCAT(preword, " ");
sp->ts_prewordlen = (char_u)STRLEN(preword);
sp->ts_splitoff = sp->ts_twordlen;
sp->ts_splitfidx = sp->ts_fidx;
// If the badword has a non-word character at this
// position skip it. That means replacing the
// non-word character with a space. Always skip a
// character when the word ends. But only when the
// good word can end.
if (((!try_compound && !spell_iswordp_nmw(fword
+ sp->ts_fidx,
curwin))
|| fword_ends)
&& fword[sp->ts_fidx] != NUL
&& goodword_ends)
{
int l;
l = mb_ptr2len(fword + sp->ts_fidx);
if (fword_ends)
{
// Copy the skipped character to preword.
mch_memmove(preword + sp->ts_prewordlen,
fword + sp->ts_fidx, l);
sp->ts_prewordlen += l;
preword[sp->ts_prewordlen] = NUL;
}
else
sp->ts_score -= SCORE_SPLIT - SCORE_SUBST;
sp->ts_fidx += l;
}
// When compounding include compound flag in
// compflags[] (already set above). When splitting we
// may start compounding over again.
if (try_compound)
++sp->ts_complen;
else
sp->ts_compsplit = sp->ts_complen;
sp->ts_prefixdepth = PFD_NOPREFIX;
// set su->su_badflags to the caps type at this
// position
if (has_mbyte)
n = nofold_len(fword, sp->ts_fidx, su->su_badptr);
else
n = sp->ts_fidx;
su->su_badflags = badword_captype(su->su_badptr + n,
su->su_badptr + su->su_badlen);
// Restart at top of the tree.
sp->ts_arridx = 0;
// If there are postponed prefixes, try these too.
if (pbyts != NULL)
{
byts = pbyts;
idxs = pidxs;
sp->ts_prefixdepth = PFD_PREFIXTREE;
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_NOPREFIX;
}
}
}
}
break;
case STATE_SPLITUNDO:
// Undo the changes done for word split or compound word.
su->su_badflags = sp->ts_save_badflags;
// Continue looking for NUL bytes.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_START;
// In case we went into the prefix tree.
byts = fbyts;
idxs = fidxs;
break;
case STATE_ENDNUL:
// Past the NUL bytes in the node.
su->su_badflags = sp->ts_save_badflags;
if (fword[sp->ts_fidx] == NUL && sp->ts_tcharlen == 0)
{
// The badword ends, can't use STATE_PLAIN.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_DEL;
break;
}
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_PLAIN;
// FALLTHROUGH
case STATE_PLAIN:
// Go over all possible bytes at this node, add each to tword[]
// and use child node. "ts_curi" is the index.
arridx = sp->ts_arridx;
if (sp->ts_curi > byts[arridx])
{
// Done all bytes at this node, do next state. When still at
// already changed bytes skip the other tricks.
PROF_STORE(sp->ts_state)
if (sp->ts_fidx >= sp->ts_fidxtry)
sp->ts_state = STATE_DEL;
else
sp->ts_state = STATE_FINAL;
}
else
{
arridx += sp->ts_curi++;
c = byts[arridx];
// Normal byte, go one level deeper. If it's not equal to the
// byte in the bad word adjust the score. But don't even try
// when the byte was already changed. And don't try when we
// just deleted this byte, accepting it is always cheaper than
// delete + substitute.
if (c == fword[sp->ts_fidx]
|| (sp->ts_tcharlen > 0 && sp->ts_isdiff != DIFF_NONE))
newscore = 0;
else
newscore = SCORE_SUBST;
if ((newscore == 0
|| (sp->ts_fidx >= sp->ts_fidxtry
&& ((sp->ts_flags & TSF_DIDDEL) == 0
|| c != fword[sp->ts_delidx])))
&& TRY_DEEPER(su, stack, depth, newscore))
{
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
if (newscore > 0)
sprintf(changename[depth], "%.*s-%s: subst %c to %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
fword[sp->ts_fidx], c);
else
sprintf(changename[depth], "%.*s-%s: accept %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
fword[sp->ts_fidx]);
#endif
++depth;
sp = &stack[depth];
if (fword[sp->ts_fidx] != NUL)
++sp->ts_fidx;
tword[sp->ts_twordlen++] = c;
sp->ts_arridx = idxs[arridx];
if (newscore == SCORE_SUBST)
sp->ts_isdiff = DIFF_YES;
if (has_mbyte)
{
// Multi-byte characters are a bit complicated to
// handle: They differ when any of the bytes differ
// and then their length may also differ.
if (sp->ts_tcharlen == 0)
{
// First byte.
sp->ts_tcharidx = 0;
sp->ts_tcharlen = MB_BYTE2LEN(c);
sp->ts_fcharstart = sp->ts_fidx - 1;
sp->ts_isdiff = (newscore != 0)
? DIFF_YES : DIFF_NONE;
}
else if (sp->ts_isdiff == DIFF_INSERT)
// When inserting trail bytes don't advance in the
// bad word.
--sp->ts_fidx;
if (++sp->ts_tcharidx == sp->ts_tcharlen)
{
// Last byte of character.
if (sp->ts_isdiff == DIFF_YES)
{
// Correct ts_fidx for the byte length of the
// character (we didn't check that before).
sp->ts_fidx = sp->ts_fcharstart
+ mb_ptr2len(
fword + sp->ts_fcharstart);
// For changing a composing character adjust
// the score from SCORE_SUBST to
// SCORE_SUBCOMP.
if (enc_utf8
&& utf_iscomposing(
utf_ptr2char(tword
+ sp->ts_twordlen
- sp->ts_tcharlen))
&& utf_iscomposing(
utf_ptr2char(fword
+ sp->ts_fcharstart)))
sp->ts_score -=
SCORE_SUBST - SCORE_SUBCOMP;
// For a similar character adjust score from
// SCORE_SUBST to SCORE_SIMILAR.
else if (!soundfold
&& slang->sl_has_map
&& similar_chars(slang,
mb_ptr2char(tword
+ sp->ts_twordlen
- sp->ts_tcharlen),
mb_ptr2char(fword
+ sp->ts_fcharstart)))
sp->ts_score -=
SCORE_SUBST - SCORE_SIMILAR;
}
else if (sp->ts_isdiff == DIFF_INSERT
&& sp->ts_twordlen > sp->ts_tcharlen)
{
p = tword + sp->ts_twordlen - sp->ts_tcharlen;
c = mb_ptr2char(p);
if (enc_utf8 && utf_iscomposing(c))
{
// Inserting a composing char doesn't
// count that much.
sp->ts_score -= SCORE_INS - SCORE_INSCOMP;
}
else
{
// If the previous character was the same,
// thus doubling a character, give a bonus
// to the score. Also for the soundfold
// tree (might seem illogical but does
// give better scores).
MB_PTR_BACK(tword, p);
if (c == mb_ptr2char(p))
sp->ts_score -= SCORE_INS
- SCORE_INSDUP;
}
}
// Starting a new char, reset the length.
sp->ts_tcharlen = 0;
}
}
else
{
// If we found a similar char adjust the score.
// We do this after calling go_deeper() because
// it's slow.
if (newscore != 0
&& !soundfold
&& slang->sl_has_map
&& similar_chars(slang,
c, fword[sp->ts_fidx - 1]))
sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
}
}
}
break;
case STATE_DEL:
// When past the first byte of a multi-byte char don't try
// delete/insert/swap a character.
if (has_mbyte && sp->ts_tcharlen > 0)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
break;
}
// Try skipping one character in the bad word (delete it).
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_INS_PREP;
sp->ts_curi = 1;
if (soundfold && sp->ts_fidx == 0 && fword[sp->ts_fidx] == '*')
// Deleting a vowel at the start of a word counts less, see
// soundalike_score().
newscore = 2 * SCORE_DEL / 3;
else
newscore = SCORE_DEL;
if (fword[sp->ts_fidx] != NUL
&& TRY_DEEPER(su, stack, depth, newscore))
{
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: delete %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
fword[sp->ts_fidx]);
#endif
++depth;
// Remember what character we deleted, so that we can avoid
// inserting it again.
stack[depth].ts_flags |= TSF_DIDDEL;
stack[depth].ts_delidx = sp->ts_fidx;
// Advance over the character in fword[]. Give a bonus to the
// score if the same character is following "nn" -> "n". It's
// a bit illogical for soundfold tree but it does give better
// results.
if (has_mbyte)
{
c = mb_ptr2char(fword + sp->ts_fidx);
stack[depth].ts_fidx += mb_ptr2len(fword + sp->ts_fidx);
if (enc_utf8 && utf_iscomposing(c))
stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP;
else if (c == mb_ptr2char(fword + stack[depth].ts_fidx))
stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
}
else
{
++stack[depth].ts_fidx;
if (fword[sp->ts_fidx] == fword[sp->ts_fidx + 1])
stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
}
break;
}
// FALLTHROUGH
case STATE_INS_PREP:
if (sp->ts_flags & TSF_DIDDEL)
{
// If we just deleted a byte then inserting won't make sense,
// a substitute is always cheaper.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SWAP;
break;
}
// skip over NUL bytes
n = sp->ts_arridx;
for (;;)
{
if (sp->ts_curi > byts[n])
{
// Only NUL bytes at this node, go to next state.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SWAP;
break;
}
if (byts[n + sp->ts_curi] != NUL)
{
// Found a byte to insert.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_INS;
break;
}
++sp->ts_curi;
}
break;
// FALLTHROUGH
case STATE_INS:
// Insert one byte. Repeat this for each possible byte at this
// node.
n = sp->ts_arridx;
if (sp->ts_curi > byts[n])
{
// Done all bytes at this node, go to next state.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SWAP;
break;
}
// Do one more byte at this node, but:
// - Skip NUL bytes.
// - Skip the byte if it's equal to the byte in the word,
// accepting that byte is always better.
n += sp->ts_curi++;
c = byts[n];
if (soundfold && sp->ts_twordlen == 0 && c == '*')
// Inserting a vowel at the start of a word counts less,
// see soundalike_score().
newscore = 2 * SCORE_INS / 3;
else
newscore = SCORE_INS;
if (c != fword[sp->ts_fidx]
&& TRY_DEEPER(su, stack, depth, newscore))
{
go_deeper(stack, depth, newscore);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: insert %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
c);
#endif
++depth;
sp = &stack[depth];
tword[sp->ts_twordlen++] = c;
sp->ts_arridx = idxs[n];
if (has_mbyte)
{
fl = MB_BYTE2LEN(c);
if (fl > 1)
{
// There are following bytes for the same character.
// We must find all bytes before trying
// delete/insert/swap/etc.
sp->ts_tcharlen = fl;
sp->ts_tcharidx = 1;
sp->ts_isdiff = DIFF_INSERT;
}
}
else
fl = 1;
if (fl == 1)
{
// If the previous character was the same, thus doubling a
// character, give a bonus to the score. Also for
// soundfold words (illogical but does give a better
// score).
if (sp->ts_twordlen >= 2
&& tword[sp->ts_twordlen - 2] == c)
sp->ts_score -= SCORE_INS - SCORE_INSDUP;
}
}
break;
case STATE_SWAP:
// Swap two bytes in the bad word: "12" -> "21".
// We change "fword" here, it's changed back afterwards at
// STATE_UNSWAP.
p = fword + sp->ts_fidx;
c = *p;
if (c == NUL)
{
// End of word, can't swap or replace.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
break;
}
// Don't swap if the first character is not a word character.
// SWAP3 etc. also don't make sense then.
if (!soundfold && !spell_iswordp(p, curwin))
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
if (has_mbyte)
{
n = MB_CPTR2LEN(p);
c = mb_ptr2char(p);
if (p[n] == NUL)
c2 = NUL;
else if (!soundfold && !spell_iswordp(p + n, curwin))
c2 = c; // don't swap non-word char
else
c2 = mb_ptr2char(p + n);
}
else
{
if (p[1] == NUL)
c2 = NUL;
else if (!soundfold && !spell_iswordp(p + 1, curwin))
c2 = c; // don't swap non-word char
else
c2 = p[1];
}
// When the second character is NUL we can't swap.
if (c2 == NUL)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
// When characters are identical, swap won't do anything.
// Also get here if the second char is not a word character.
if (c == c2)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_SWAP3;
break;
}
if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP))
{
go_deeper(stack, depth, SCORE_SWAP);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: swap %c and %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
c, c2);
#endif
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNSWAP;
++depth;
if (has_mbyte)
{
fl = mb_char2len(c2);
mch_memmove(p, p + n, fl);
mb_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
}
else
{
p[0] = c2;
p[1] = c;
stack[depth].ts_fidxtry = sp->ts_fidx + 2;
}
}
else
{
// If this swap doesn't work then SWAP3 won't either.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
}
break;
case STATE_UNSWAP:
// Undo the STATE_SWAP swap: "21" -> "12".
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = mb_ptr2len(p);
c = mb_ptr2char(p + n);
mch_memmove(p + mb_ptr2len(p + n), p, n);
mb_char2bytes(c, p);
}
else
{
c = *p;
*p = p[1];
p[1] = c;
}
// FALLTHROUGH
case STATE_SWAP3:
// Swap two bytes, skipping one: "123" -> "321". We change
// "fword" here, it's changed back afterwards at STATE_UNSWAP3.
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = MB_CPTR2LEN(p);
c = mb_ptr2char(p);
fl = MB_CPTR2LEN(p + n);
c2 = mb_ptr2char(p + n);
if (!soundfold && !spell_iswordp(p + n + fl, curwin))
c3 = c; // don't swap non-word char
else
c3 = mb_ptr2char(p + n + fl);
}
else
{
c = *p;
c2 = p[1];
if (!soundfold && !spell_iswordp(p + 2, curwin))
c3 = c; // don't swap non-word char
else
c3 = p[2];
}
// When characters are identical: "121" then SWAP3 result is
// identical, ROT3L result is same as SWAP: "211", ROT3L result is
// same as SWAP on next char: "112". Thus skip all swapping.
// Also skip when c3 is NUL.
// Also get here when the third character is not a word character.
// Second character may any char: "a.b" -> "b.a"
if (c == c3 || c3 == NUL)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
{
go_deeper(stack, depth, SCORE_SWAP3);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: swap3 %c and %c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
c, c3);
#endif
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNSWAP3;
++depth;
if (has_mbyte)
{
tl = mb_char2len(c3);
mch_memmove(p, p + n + fl, tl);
mb_char2bytes(c2, p + tl);
mb_char2bytes(c, p + fl + tl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl + tl;
}
else
{
p[0] = p[2];
p[2] = c;
stack[depth].ts_fidxtry = sp->ts_fidx + 3;
}
}
else
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
}
break;
case STATE_UNSWAP3:
// Undo STATE_SWAP3: "321" -> "123"
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = mb_ptr2len(p);
c2 = mb_ptr2char(p + n);
fl = mb_ptr2len(p + n);
c = mb_ptr2char(p + n + fl);
tl = mb_ptr2len(p + n + fl);
mch_memmove(p + fl + tl, p, n);
mb_char2bytes(c, p);
mb_char2bytes(c2, p + tl);
p = p + tl;
}
else
{
c = *p;
*p = p[2];
p[2] = c;
++p;
}
if (!soundfold && !spell_iswordp(p, curwin))
{
// Middle char is not a word char, skip the rotate. First and
// third char were already checked at swap and swap3.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
break;
}
// Rotate three characters left: "123" -> "231". We change
// "fword" here, it's changed back afterwards at STATE_UNROT3L.
if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
{
go_deeper(stack, depth, SCORE_SWAP3);
#ifdef DEBUG_TRIEWALK
p = fword + sp->ts_fidx;
sprintf(changename[depth], "%.*s-%s: rotate left %c%c%c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
p[0], p[1], p[2]);
#endif
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNROT3L;
++depth;
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = MB_CPTR2LEN(p);
c = mb_ptr2char(p);
fl = MB_CPTR2LEN(p + n);
fl += MB_CPTR2LEN(p + n + fl);
mch_memmove(p, p + n, fl);
mb_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
}
else
{
c = *p;
*p = p[1];
p[1] = p[2];
p[2] = c;
stack[depth].ts_fidxtry = sp->ts_fidx + 3;
}
}
else
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
}
break;
case STATE_UNROT3L:
// Undo ROT3L: "231" -> "123"
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = mb_ptr2len(p);
n += mb_ptr2len(p + n);
c = mb_ptr2char(p + n);
tl = mb_ptr2len(p + n);
mch_memmove(p + tl, p, n);
mb_char2bytes(c, p);
}
else
{
c = p[2];
p[2] = p[1];
p[1] = *p;
*p = c;
}
// Rotate three bytes right: "123" -> "312". We change "fword"
// here, it's changed back afterwards at STATE_UNROT3R.
if (TRY_DEEPER(su, stack, depth, SCORE_SWAP3))
{
go_deeper(stack, depth, SCORE_SWAP3);
#ifdef DEBUG_TRIEWALK
p = fword + sp->ts_fidx;
sprintf(changename[depth], "%.*s-%s: rotate right %c%c%c",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
p[0], p[1], p[2]);
#endif
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNROT3R;
++depth;
p = fword + sp->ts_fidx;
if (has_mbyte)
{
n = MB_CPTR2LEN(p);
n += MB_CPTR2LEN(p + n);
c = mb_ptr2char(p + n);
tl = MB_CPTR2LEN(p + n);
mch_memmove(p + tl, p, n);
mb_char2bytes(c, p);
stack[depth].ts_fidxtry = sp->ts_fidx + n + tl;
}
else
{
c = p[2];
p[2] = p[1];
p[1] = *p;
*p = c;
stack[depth].ts_fidxtry = sp->ts_fidx + 3;
}
}
else
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_INI;
}
break;
case STATE_UNROT3R:
// Undo ROT3R: "312" -> "123"
p = fword + sp->ts_fidx;
if (has_mbyte)
{
c = mb_ptr2char(p);
tl = mb_ptr2len(p);
n = mb_ptr2len(p + tl);
n += mb_ptr2len(p + tl + n);
mch_memmove(p, p + tl, n);
mb_char2bytes(c, p + n);
}
else
{
c = *p;
*p = p[1];
p[1] = p[2];
p[2] = c;
}
// FALLTHROUGH
case STATE_REP_INI:
// Check if matching with REP items from the .aff file would work.
// Quickly skip if:
// - there are no REP items and we are not in the soundfold trie
// - the score is going to be too high anyway
// - already applied a REP item or swapped here
if ((lp->lp_replang == NULL && !soundfold)
|| sp->ts_score + SCORE_REP >= su->su_maxscore
|| sp->ts_fidx < sp->ts_fidxtry)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
break;
}
// Use the first byte to quickly find the first entry that may
// match. If the index is -1 there is none.
if (soundfold)
sp->ts_curi = slang->sl_repsal_first[fword[sp->ts_fidx]];
else
sp->ts_curi = lp->lp_replang->sl_rep_first[fword[sp->ts_fidx]];
if (sp->ts_curi < 0)
{
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
break;
}
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP;
// FALLTHROUGH
case STATE_REP:
// Try matching with REP items from the .aff file. For each match
// replace the characters and check if the resulting word is
// valid.
p = fword + sp->ts_fidx;
if (soundfold)
gap = &slang->sl_repsal;
else
gap = &lp->lp_replang->sl_rep;
while (sp->ts_curi < gap->ga_len)
{
ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
if (*ftp->ft_from != *p)
{
// past possible matching entries
sp->ts_curi = gap->ga_len;
break;
}
if (STRNCMP(ftp->ft_from, p, STRLEN(ftp->ft_from)) == 0
&& TRY_DEEPER(su, stack, depth, SCORE_REP))
{
go_deeper(stack, depth, SCORE_REP);
#ifdef DEBUG_TRIEWALK
sprintf(changename[depth], "%.*s-%s: replace %s with %s",
sp->ts_twordlen, tword, fword + sp->ts_fidx,
ftp->ft_from, ftp->ft_to);
#endif
// Need to undo this afterwards.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP_UNDO;
// Change the "from" to the "to" string.
++depth;
fl = (int)STRLEN(ftp->ft_from);
tl = (int)STRLEN(ftp->ft_to);
if (fl != tl)
{
STRMOVE(p + tl, p + fl);
repextra += tl - fl;
}
mch_memmove(p, ftp->ft_to, tl);
stack[depth].ts_fidxtry = sp->ts_fidx + tl;
stack[depth].ts_tcharlen = 0;
break;
}
}
if (sp->ts_curi >= gap->ga_len && sp->ts_state == STATE_REP)
{
// No (more) matches.
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_FINAL;
}
break;
case STATE_REP_UNDO:
// Undo a REP replacement and continue with the next one.
if (soundfold)
gap = &slang->sl_repsal;
else
gap = &lp->lp_replang->sl_rep;
ftp = (fromto_T *)gap->ga_data + sp->ts_curi - 1;
fl = (int)STRLEN(ftp->ft_from);
tl = (int)STRLEN(ftp->ft_to);
p = fword + sp->ts_fidx;
if (fl != tl)
{
STRMOVE(p + fl, p + tl);
repextra -= tl - fl;
}
mch_memmove(p, ftp->ft_from, fl);
PROF_STORE(sp->ts_state)
sp->ts_state = STATE_REP;
break;
default:
// Did all possible states at this level, go up one level.
--depth;
if (depth >= 0 && stack[depth].ts_prefixdepth == PFD_PREFIXTREE)
{
// Continue in or go back to the prefix tree.
byts = pbyts;
idxs = pidxs;
}
// Don't check for CTRL-C too often, it takes time.
if (--breakcheckcount == 0)
{
ui_breakcheck();
breakcheckcount = 1000;
#ifdef FEAT_RELTIME
if (spell_suggest_timeout > 0
&& profile_passed_limit(&time_limit))
got_int = TRUE;
#endif
}
}
}
} | 6081 | True | 1 |
CVE-2022-2175 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/6046aded8da002b08d380db29de2ba0268b6616e', 'name': 'https://github.com/vim/vim/commit/6046aded8da002b08d380db29de2ba0268b6616e', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7f0481c2-8b57-4324-b47c-795d1ea67e55', 'name': 'https://huntr.dev/bounties/7f0481c2-8b57-4324-b47c-795d1ea67e55', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-126'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5148', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Buffer Over-read in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T19:16Z | 2022-06-23T13:15Z | Buffer Over-read | The software reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations after the targeted buffer. | This typically occurs when the pointer or its index is incremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in exposure of sensitive information or possibly a crash.
| https://cwe.mitre.org/data/definitions/126.html | 0 | Bram Moolenaar | 2022-06-22 13:51:54+01:00 | patch 8.2.5148: invalid memory access when using expression on command line
Problem: Invalid memory access when using an expression on the command line.
Solution: Make sure the position does not go negative. | 6046aded8da002b08d380db29de2ba0268b6616e | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | cmdline_insert_reg | cmdline_insert_reg( int * gotesc UNUSED) | ['UNUSED'] | cmdline_insert_reg(int *gotesc UNUSED)
{
int i;
int c;
#ifdef USE_ON_FLY_SCROLL
dont_scroll = TRUE; // disallow scrolling here
#endif
putcmdline('"', TRUE);
++no_mapping;
++allow_keys;
i = c = plain_vgetc(); // CTRL-R <char>
if (i == Ctrl_O)
i = Ctrl_R; // CTRL-R CTRL-O == CTRL-R CTRL-R
if (i == Ctrl_R)
c = plain_vgetc(); // CTRL-R CTRL-R <char>
extra_char = NUL;
--no_mapping;
--allow_keys;
#ifdef FEAT_EVAL
/*
* Insert the result of an expression.
* Need to save the current command line, to be able to enter
* a new one...
*/
new_cmdpos = -1;
if (c == '=')
{
if (ccline.cmdfirstc == '=' // can't do this recursively
|| cmdline_star > 0) // or when typing a password
{
beep_flush();
c = ESC;
}
else
c = get_expr_register();
}
#endif
if (c != ESC) // use ESC to cancel inserting register
{
cmdline_paste(c, i == Ctrl_R, FALSE);
#ifdef FEAT_EVAL
// When there was a serious error abort getting the
// command line.
if (aborting())
{
*gotesc = TRUE; // will free ccline.cmdbuff after
// putting it in history
return GOTO_NORMAL_MODE;
}
#endif
KeyTyped = FALSE; // Don't do p_wc completion.
#ifdef FEAT_EVAL
if (new_cmdpos >= 0)
{
// set_cmdline_pos() was used
if (new_cmdpos > ccline.cmdlen)
ccline.cmdpos = ccline.cmdlen;
else
ccline.cmdpos = new_cmdpos;
}
#endif
}
// remove the double quote
redrawcmd();
// The text has been stuffed, the command line didn't change yet.
return CMDLINE_NOT_CHANGED;
} | 191 | True | 1 |
CVE-2022-2183 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/8eba2bd291b347e3008aa9e565652d51ad638cfa', 'name': 'https://github.com/vim/vim/commit/8eba2bd291b347e3008aa9e565652d51ad638cfa', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/d74ca3f9-380d-4c0a-b61c-11113cc98975', 'name': 'https://huntr.dev/bounties/d74ca3f9-380d-4c0a-b61c-11113cc98975', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-125'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5151', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Read in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T07:15Z | 2022-06-23T19:15Z | Out-of-bounds Read | The software reads data past the end, or before the beginning, of the intended buffer. | Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/125.html | 0 | Bram Moolenaar | 2022-06-22 19:59:28+01:00 | patch 8.2.5151: reading beyond the end of the line with lisp indenting
Problem: Reading beyond the end of the line with lisp indenting.
Solution: Avoid going over the NUL at the end of the line. | 8eba2bd291b347e3008aa9e565652d51ad638cfa | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | get_lisp_indent | get_lisp_indent( void) | ['void'] | get_lisp_indent(void)
{
pos_T *pos, realpos, paren;
int amount;
char_u *that;
colnr_T col;
colnr_T firsttry;
int parencount, quotecount;
int vi_lisp;
// Set vi_lisp to use the vi-compatible method
vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL);
realpos = curwin->w_cursor;
curwin->w_cursor.col = 0;
if ((pos = findmatch(NULL, '(')) == NULL)
pos = findmatch(NULL, '[');
else
{
paren = *pos;
pos = findmatch(NULL, '[');
if (pos == NULL || LT_POSP(pos, &paren))
pos = &paren;
}
if (pos != NULL)
{
// Extra trick: Take the indent of the first previous non-white
// line that is at the same () level.
amount = -1;
parencount = 0;
while (--curwin->w_cursor.lnum >= pos->lnum)
{
if (linewhite(curwin->w_cursor.lnum))
continue;
for (that = ml_get_curline(); *that != NUL; ++that)
{
if (*that == ';')
{
while (*(that + 1) != NUL)
++that;
continue;
}
if (*that == '\\')
{
if (*(that + 1) != NUL)
++that;
continue;
}
if (*that == '"' && *(that + 1) != NUL)
{
while (*++that && *that != '"')
{
// skipping escaped characters in the string
if (*that == '\\')
{
if (*++that == NUL)
break;
if (that[1] == NUL)
{
++that;
break;
}
}
}
if (*that == NUL)
break;
}
if (*that == '(' || *that == '[')
++parencount;
else if (*that == ')' || *that == ']')
--parencount;
}
if (parencount == 0)
{
amount = get_indent();
break;
}
}
if (amount == -1)
{
curwin->w_cursor.lnum = pos->lnum;
curwin->w_cursor.col = pos->col;
col = pos->col;
that = ml_get_curline();
if (vi_lisp && get_indent() == 0)
amount = 2;
else
{
char_u *line = that;
amount = 0;
while (*that && col)
{
amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount);
col--;
}
// Some keywords require "body" indenting rules (the
// non-standard-lisp ones are Scheme special forms):
//
// (let ((a 1)) instead (let ((a 1))
// (...)) of (...))
if (!vi_lisp && (*that == '(' || *that == '[')
&& lisp_match(that + 1))
amount += 2;
else
{
that++;
amount++;
firsttry = amount;
while (VIM_ISWHITE(*that))
{
amount += lbr_chartabsize(line, that, (colnr_T)amount);
++that;
}
if (*that && *that != ';') // not a comment line
{
// test *that != '(' to accommodate first let/do
// argument if it is more than one line
if (!vi_lisp && *that != '(' && *that != '[')
firsttry++;
parencount = 0;
quotecount = 0;
if (vi_lisp
|| (*that != '"'
&& *that != '\''
&& *that != '#'
&& (*that < '0' || *that > '9')))
{
while (*that
&& (!VIM_ISWHITE(*that)
|| quotecount
|| parencount)
&& (!((*that == '(' || *that == '[')
&& !quotecount
&& !parencount
&& vi_lisp)))
{
if (*that == '"')
quotecount = !quotecount;
if ((*that == '(' || *that == '[')
&& !quotecount)
++parencount;
if ((*that == ')' || *that == ']')
&& !quotecount)
--parencount;
if (*that == '\\' && *(that+1) != NUL)
amount += lbr_chartabsize_adv(
line, &that, (colnr_T)amount);
amount += lbr_chartabsize_adv(
line, &that, (colnr_T)amount);
}
}
while (VIM_ISWHITE(*that))
{
amount += lbr_chartabsize(
line, that, (colnr_T)amount);
that++;
}
if (!*that || *that == ';')
amount = firsttry;
}
}
}
}
}
else
amount = 0; // no matching '(' or '[' found, use zero indent
curwin->w_cursor = realpos;
return amount;
} | 792 | True | 1 |
CVE-2022-2207 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/05bc6051-4dc3-483b-ae56-cf23346b97b9', 'name': 'https://huntr.dev/bounties/05bc6051-4dc3-483b-ae56-cf23346b97b9', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/0971c7a4e537ea120a6bb2195960be8d0815e97b', 'name': 'https://github.com/vim/vim/commit/0971c7a4e537ea120a6bb2195960be8d0815e97b', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5162', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-26T19:16Z | 2022-06-27T12:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-06-26 12:59:02+01:00 | patch 8.2.5162: reading before the start of the line with BS in Replace mode
Problem: Reading before the start of the line with BS in Replace mode.
Solution: Check the cursor column is more than zero. | 0971c7a4e537ea120a6bb2195960be8d0815e97b | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ins_bs | ins_bs( int c , int mode , int * inserted_space_p) | ['c', 'mode', 'inserted_space_p'] | ins_bs(
int c,
int mode,
int *inserted_space_p)
{
linenr_T lnum;
int cc;
int temp = 0; // init for GCC
colnr_T save_col;
colnr_T mincol;
int did_backspace = FALSE;
int in_indent;
int oldState;
int cpc[MAX_MCO]; // composing characters
int call_fix_indent = FALSE;
/*
* can't delete anything in an empty file
* can't backup past first character in buffer
* can't backup past starting point unless 'backspace' > 1
* can backup to a previous line if 'backspace' == 0
*/
if ( BUFEMPTY()
|| (
#ifdef FEAT_RIGHTLEFT
!revins_on &&
#endif
((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
|| (!can_bs(BS_START)
&& ((arrow_used
#ifdef FEAT_JOB_CHANNEL
&& !bt_prompt(curbuf)
#endif
) || (curwin->w_cursor.lnum == Insstart_orig.lnum
&& curwin->w_cursor.col <= Insstart_orig.col)))
|| (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0
&& curwin->w_cursor.col <= ai_col)
|| (!can_bs(BS_EOL) && curwin->w_cursor.col == 0))))
{
vim_beep(BO_BS);
return FALSE;
}
if (stop_arrow() == FAIL)
return FALSE;
in_indent = inindent(0);
if (in_indent)
can_cindent = FALSE;
end_comment_pending = NUL; // After BS, don't auto-end comment
#ifdef FEAT_RIGHTLEFT
if (revins_on) // put cursor after last inserted char
inc_cursor();
#endif
// Virtualedit:
// BACKSPACE_CHAR eats a virtual space
// BACKSPACE_WORD eats all coladd
// BACKSPACE_LINE eats all coladd and keeps going
if (curwin->w_cursor.coladd > 0)
{
if (mode == BACKSPACE_CHAR)
{
--curwin->w_cursor.coladd;
return TRUE;
}
if (mode == BACKSPACE_WORD)
{
curwin->w_cursor.coladd = 0;
return TRUE;
}
curwin->w_cursor.coladd = 0;
}
/*
* Delete newline!
*/
if (curwin->w_cursor.col == 0)
{
lnum = Insstart.lnum;
if (curwin->w_cursor.lnum == lnum
#ifdef FEAT_RIGHTLEFT
|| revins_on
#endif
)
{
if (u_save((linenr_T)(curwin->w_cursor.lnum - 2),
(linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL)
return FALSE;
--Insstart.lnum;
Insstart.col = (colnr_T)STRLEN(ml_get(Insstart.lnum));
}
/*
* In replace mode:
* cc < 0: NL was inserted, delete it
* cc >= 0: NL was replaced, put original characters back
*/
cc = -1;
if (State & REPLACE_FLAG)
cc = replace_pop(); // returns -1 if NL was inserted
/*
* In replace mode, in the line we started replacing, we only move the
* cursor.
*/
if ((State & REPLACE_FLAG) && curwin->w_cursor.lnum <= lnum)
{
dec_cursor();
}
else
{
if (!(State & VREPLACE_FLAG)
|| curwin->w_cursor.lnum > orig_line_count)
{
temp = gchar_cursor(); // remember current char
--curwin->w_cursor.lnum;
// When "aw" is in 'formatoptions' we must delete the space at
// the end of the line, otherwise the line will be broken
// again when auto-formatting.
if (has_format_option(FO_AUTO)
&& has_format_option(FO_WHITE_PAR))
{
char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum,
TRUE);
int len;
len = (int)STRLEN(ptr);
if (len > 0 && ptr[len - 1] == ' ')
ptr[len - 1] = NUL;
}
(void)do_join(2, FALSE, FALSE, FALSE, FALSE);
if (temp == NUL && gchar_cursor() != NUL)
inc_cursor();
}
else
dec_cursor();
/*
* In MODE_REPLACE mode we have to put back the text that was
* replaced by the NL. On the replace stack is first a
* NUL-terminated sequence of characters that were deleted and then
* the characters that NL replaced.
*/
if (State & REPLACE_FLAG)
{
/*
* Do the next ins_char() in MODE_NORMAL state, to
* prevent ins_char() from replacing characters and
* avoiding showmatch().
*/
oldState = State;
State = MODE_NORMAL;
/*
* restore characters (blanks) deleted after cursor
*/
while (cc > 0)
{
save_col = curwin->w_cursor.col;
mb_replace_pop_ins(cc);
curwin->w_cursor.col = save_col;
cc = replace_pop();
}
// restore the characters that NL replaced
replace_pop_ins();
State = oldState;
}
}
did_ai = FALSE;
}
else
{
/*
* Delete character(s) before the cursor.
*/
#ifdef FEAT_RIGHTLEFT
if (revins_on) // put cursor on last inserted char
dec_cursor();
#endif
mincol = 0;
// keep indent
if (mode == BACKSPACE_LINE
&& (curbuf->b_p_ai || cindent_on())
#ifdef FEAT_RIGHTLEFT
&& !revins_on
#endif
)
{
save_col = curwin->w_cursor.col;
beginline(BL_WHITE);
if (curwin->w_cursor.col < save_col)
{
mincol = curwin->w_cursor.col;
// should now fix the indent to match with the previous line
call_fix_indent = TRUE;
}
curwin->w_cursor.col = save_col;
}
/*
* Handle deleting one 'shiftwidth' or 'softtabstop'.
*/
if ( mode == BACKSPACE_CHAR
&& ((p_sta && in_indent)
|| ((get_sts_value() != 0
#ifdef FEAT_VARTABS
|| tabstop_count(curbuf->b_p_vsts_array)
#endif
)
&& curwin->w_cursor.col > 0
&& (*(ml_get_cursor() - 1) == TAB
|| (*(ml_get_cursor() - 1) == ' '
&& (!*inserted_space_p
|| arrow_used))))))
{
int ts;
colnr_T vcol;
colnr_T want_vcol;
colnr_T start_vcol;
*inserted_space_p = FALSE;
// Compute the virtual column where we want to be. Since
// 'showbreak' may get in the way, need to get the last column of
// the previous character.
getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
start_vcol = vcol;
dec_cursor();
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
inc_cursor();
#ifdef FEAT_VARTABS
if (p_sta && in_indent)
{
ts = (int)get_sw_value(curbuf);
want_vcol = (want_vcol / ts) * ts;
}
else
want_vcol = tabstop_start(want_vcol, get_sts_value(),
curbuf->b_p_vsts_array);
#else
if (p_sta && in_indent)
ts = (int)get_sw_value(curbuf);
else
ts = (int)get_sts_value();
want_vcol = (want_vcol / ts) * ts;
#endif
// delete characters until we are at or before want_vcol
while (vcol > want_vcol
&& (cc = *(ml_get_cursor() - 1), VIM_ISWHITE(cc)))
ins_bs_one(&vcol);
// insert extra spaces until we are at want_vcol
while (vcol < want_vcol)
{
// Remember the first char we inserted
if (curwin->w_cursor.lnum == Insstart_orig.lnum
&& curwin->w_cursor.col < Insstart_orig.col)
Insstart_orig.col = curwin->w_cursor.col;
if (State & VREPLACE_FLAG)
ins_char(' ');
else
{
ins_str((char_u *)" ");
if ((State & REPLACE_FLAG))
replace_push(NUL);
}
getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
}
// If we are now back where we started delete one character. Can
// happen when using 'sts' and 'linebreak'.
if (vcol >= start_vcol)
ins_bs_one(&vcol);
}
/*
* Delete up to starting point, start of line or previous word.
*/
else
{
int cclass = 0, prev_cclass = 0;
if (has_mbyte)
cclass = mb_get_class(ml_get_cursor());
do
{
#ifdef FEAT_RIGHTLEFT
if (!revins_on) // put cursor on char to be deleted
#endif
dec_cursor();
cc = gchar_cursor();
// look multi-byte character class
if (has_mbyte)
{
prev_cclass = cclass;
cclass = mb_get_class(ml_get_cursor());
}
// start of word?
if (mode == BACKSPACE_WORD && !vim_isspace(cc))
{
mode = BACKSPACE_WORD_NOT_SPACE;
temp = vim_iswordc(cc);
}
// end of word?
else if (mode == BACKSPACE_WORD_NOT_SPACE
&& ((vim_isspace(cc) || vim_iswordc(cc) != temp)
|| prev_cclass != cclass))
{
#ifdef FEAT_RIGHTLEFT
if (!revins_on)
#endif
inc_cursor();
#ifdef FEAT_RIGHTLEFT
else if (State & REPLACE_FLAG)
dec_cursor();
#endif
break;
}
if (State & REPLACE_FLAG)
replace_do_bs(-1);
else
{
if (enc_utf8 && p_deco)
(void)utfc_ptr2char(ml_get_cursor(), cpc);
(void)del_char(FALSE);
/*
* If there are combining characters and 'delcombine' is set
* move the cursor back. Don't back up before the base
* character.
*/
if (enc_utf8 && p_deco && cpc[0] != NUL)
inc_cursor();
#ifdef FEAT_RIGHTLEFT
if (revins_chars)
{
revins_chars--;
revins_legal++;
}
if (revins_on && gchar_cursor() == NUL)
break;
#endif
}
// Just a single backspace?:
if (mode == BACKSPACE_CHAR)
break;
} while (
#ifdef FEAT_RIGHTLEFT
revins_on ||
#endif
(curwin->w_cursor.col > mincol
&& (can_bs(BS_NOSTOP)
|| (curwin->w_cursor.lnum != Insstart_orig.lnum
|| curwin->w_cursor.col != Insstart_orig.col)
)));
}
did_backspace = TRUE;
}
did_si = FALSE;
can_si = FALSE;
can_si_back = FALSE;
if (curwin->w_cursor.col <= 1)
did_ai = FALSE;
if (call_fix_indent)
fix_indent();
/*
* It's a little strange to put backspaces into the redo
* buffer, but it makes auto-indent a lot easier to deal
* with.
*/
AppendCharToRedobuff(c);
// If deleted before the insertion point, adjust it
if (curwin->w_cursor.lnum == Insstart_orig.lnum
&& curwin->w_cursor.col < Insstart_orig.col)
Insstart_orig.col = curwin->w_cursor.col;
// vi behaviour: the cursor moves backward but the character that
// was there remains visible
// Vim behaviour: the cursor moves backward and the character that
// was there is erased from the screen.
// We can emulate the vi behaviour by pretending there is a dollar
// displayed even when there isn't.
// --pkv Sun Jan 19 01:56:40 EST 2003
if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == -1)
dollar_vcol = curwin->w_virtcol;
#ifdef FEAT_FOLDING
// When deleting a char the cursor line must never be in a closed fold.
// E.g., when 'foldmethod' is indent and deleting the first non-white
// char before a Tab.
if (did_backspace)
foldOpenCursor();
#endif
return did_backspace;
} | 1416 | True | 1 |
|
CVE-2022-2208 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://github.com/vim/vim/commit/cd38bb4d83c942c4bad596835c6766cbf32e5195', 'name': 'https://github.com/vim/vim/commit/cd38bb4d83c942c4bad596835c6766cbf32e5195', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7bfe3d5b-568f-4c34-908f-a39909638cc1', 'name': 'https://huntr.dev/bounties/7bfe3d5b-568f-4c34-908f-a39909638cc1', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5163', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 8.2.5163.'}] | 2022-08-26T19:16Z | 2022-06-27T13:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-06-26 14:04:07+01:00 | patch 8.2.5163: crash when deleting buffers in diff mode
Problem: Crash when deleting buffers in diff mode.
Solution: Recompute diffs later. Skip window without a valid buffer. | cd38bb4d83c942c4bad596835c6766cbf32e5195 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | diff_buf_delete | diff_buf_delete( buf_T * buf) | ['buf'] | diff_buf_delete(buf_T *buf)
{
int i;
tabpage_T *tp;
FOR_ALL_TABPAGES(tp)
{
i = diff_buf_idx_tp(buf, tp);
if (i != DB_COUNT)
{
tp->tp_diffbuf[i] = NULL;
tp->tp_diff_invalid = TRUE;
if (tp == curtab)
diff_redraw(TRUE);
}
}
} | 64 | True | 1 |
CVE-2022-2208 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://github.com/vim/vim/commit/cd38bb4d83c942c4bad596835c6766cbf32e5195', 'name': 'https://github.com/vim/vim/commit/cd38bb4d83c942c4bad596835c6766cbf32e5195', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7bfe3d5b-568f-4c34-908f-a39909638cc1', 'name': 'https://huntr.dev/bounties/7bfe3d5b-568f-4c34-908f-a39909638cc1', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5163', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 8.2.5163.'}] | 2022-08-26T19:16Z | 2022-06-27T13:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-06-26 14:04:07+01:00 | patch 8.2.5163: crash when deleting buffers in diff mode
Problem: Crash when deleting buffers in diff mode.
Solution: Recompute diffs later. Skip window without a valid buffer. | cd38bb4d83c942c4bad596835c6766cbf32e5195 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | diff_redraw | diff_redraw( int dofold) | ['dofold'] | diff_redraw(
int dofold) // also recompute the folds
{
win_T *wp;
win_T *wp_other = NULL;
int used_max_fill_other = FALSE;
int used_max_fill_curwin = FALSE;
int n;
need_diff_redraw = FALSE;
FOR_ALL_WINDOWS(wp)
if (wp->w_p_diff)
{
redraw_win_later(wp, SOME_VALID);
if (wp != curwin)
wp_other = wp;
#ifdef FEAT_FOLDING
if (dofold && foldmethodIsDiff(wp))
foldUpdateAll(wp);
#endif
// A change may have made filler lines invalid, need to take care
// of that for other windows.
n = diff_check(wp, wp->w_topline);
if ((wp != curwin && wp->w_topfill > 0) || n > 0)
{
if (wp->w_topfill > n)
wp->w_topfill = (n < 0 ? 0 : n);
else if (n > 0 && n > wp->w_topfill)
{
wp->w_topfill = n;
if (wp == curwin)
used_max_fill_curwin = TRUE;
else if (wp_other != NULL)
used_max_fill_other = TRUE;
}
check_topfill(wp, FALSE);
}
}
if (wp_other != NULL && curwin->w_p_scb)
{
if (used_max_fill_curwin)
// The current window was set to use the maximum number of filler
// lines, may need to reduce them.
diff_set_topline(wp_other, curwin);
else if (used_max_fill_other)
// The other window was set to use the maximum number of filler
// lines, may need to reduce them.
diff_set_topline(curwin, wp_other);
}
} | 214 | True | 1 |
CVE-2022-2210 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/020845f8-f047-4072-af0f-3726fe1aea25', 'name': 'https://huntr.dev/bounties/020845f8-f047-4072-af0f-3726fe1aea25', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/c101abff4c6756db4f5e740fde289decb9452efa', 'name': 'https://github.com/vim/vim/commit/c101abff4c6756db4f5e740fde289decb9452efa', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-787'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5164', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Write in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T08:15Z | 2022-06-27T16:15Z | Out-of-bounds Write | The software writes data past the end, or before the beginning, of the intended buffer. | Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/787.html | 0 | Bram Moolenaar | 2022-06-26 16:53:34+01:00 | patch 8.2.5164: invalid memory access after diff buffer manipulations
Problem: Invalid memory access after diff buffer manipulations.
Solution: Use zero offset when change removes all lines in a diff block. | c101abff4c6756db4f5e740fde289decb9452efa | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | diff_mark_adjust_tp | diff_mark_adjust_tp( tabpage_T * tp , int idx , linenr_T line1 , linenr_T line2 , long amount , long amount_after) | ['tp', 'idx', 'line1', 'line2', 'amount', 'amount_after'] | diff_mark_adjust_tp(
tabpage_T *tp,
int idx,
linenr_T line1,
linenr_T line2,
long amount,
long amount_after)
{
diff_T *dp;
diff_T *dprev;
diff_T *dnext;
int i;
int inserted, deleted;
int n, off;
linenr_T last;
linenr_T lnum_deleted = line1; // lnum of remaining deletion
int check_unchanged;
if (diff_internal())
{
// Will update diffs before redrawing. Set _invalid to update the
// diffs themselves, set _update to also update folds properly just
// before redrawing.
// Do update marks here, it is needed for :%diffput.
tp->tp_diff_invalid = TRUE;
tp->tp_diff_update = TRUE;
}
if (line2 == MAXLNUM)
{
// mark_adjust(99, MAXLNUM, 9, 0): insert lines
inserted = amount;
deleted = 0;
}
else if (amount_after > 0)
{
// mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines
inserted = amount_after;
deleted = 0;
}
else
{
// mark_adjust(98, 99, MAXLNUM, -2): delete lines
inserted = 0;
deleted = -amount_after;
}
dprev = NULL;
dp = tp->tp_first_diff;
for (;;)
{
// If the change is after the previous diff block and before the next
// diff block, thus not touching an existing change, create a new diff
// block. Don't do this when ex_diffgetput() is busy.
if ((dp == NULL || dp->df_lnum[idx] - 1 > line2
|| (line2 == MAXLNUM && dp->df_lnum[idx] > line1))
&& (dprev == NULL
|| dprev->df_lnum[idx] + dprev->df_count[idx] < line1)
&& !diff_busy)
{
dnext = diff_alloc_new(tp, dprev, dp);
if (dnext == NULL)
return;
dnext->df_lnum[idx] = line1;
dnext->df_count[idx] = inserted;
for (i = 0; i < DB_COUNT; ++i)
if (tp->tp_diffbuf[i] != NULL && i != idx)
{
if (dprev == NULL)
dnext->df_lnum[i] = line1;
else
dnext->df_lnum[i] = line1
+ (dprev->df_lnum[i] + dprev->df_count[i])
- (dprev->df_lnum[idx] + dprev->df_count[idx]);
dnext->df_count[i] = deleted;
}
}
// if at end of the list, quit
if (dp == NULL)
break;
/*
* Check for these situations:
* 1 2 3
* 1 2 3
* line1 2 3 4 5
* 2 3 4 5
* 2 3 4 5
* line2 2 3 4 5
* 3 5 6
* 3 5 6
*/
// compute last line of this change
last = dp->df_lnum[idx] + dp->df_count[idx] - 1;
// 1. change completely above line1: nothing to do
if (last >= line1 - 1)
{
// 6. change below line2: only adjust for amount_after; also when
// "deleted" became zero when deleted all lines between two diffs
if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2)
{
if (amount_after == 0)
break; // nothing left to change
dp->df_lnum[idx] += amount_after;
}
else
{
check_unchanged = FALSE;
// 2. 3. 4. 5.: inserted/deleted lines touching this diff.
if (deleted > 0)
{
if (dp->df_lnum[idx] >= line1)
{
off = dp->df_lnum[idx] - lnum_deleted;
if (last <= line2)
{
// 4. delete all lines of diff
if (dp->df_next != NULL
&& dp->df_next->df_lnum[idx] - 1 <= line2)
{
// delete continues in next diff, only do
// lines until that one
n = dp->df_next->df_lnum[idx] - lnum_deleted;
deleted -= n;
n -= dp->df_count[idx];
lnum_deleted = dp->df_next->df_lnum[idx];
}
else
n = deleted - dp->df_count[idx];
dp->df_count[idx] = 0;
}
else
{
// 5. delete lines at or just before top of diff
n = off;
dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1;
check_unchanged = TRUE;
}
dp->df_lnum[idx] = line1;
}
else
{
off = 0;
if (last < line2)
{
// 2. delete at end of diff
dp->df_count[idx] -= last - lnum_deleted + 1;
if (dp->df_next != NULL
&& dp->df_next->df_lnum[idx] - 1 <= line2)
{
// delete continues in next diff, only do
// lines until that one
n = dp->df_next->df_lnum[idx] - 1 - last;
deleted -= dp->df_next->df_lnum[idx]
- lnum_deleted;
lnum_deleted = dp->df_next->df_lnum[idx];
}
else
n = line2 - last;
check_unchanged = TRUE;
}
else
{
// 3. delete lines inside the diff
n = 0;
dp->df_count[idx] -= deleted;
}
}
for (i = 0; i < DB_COUNT; ++i)
if (tp->tp_diffbuf[i] != NULL && i != idx)
{
dp->df_lnum[i] -= off;
dp->df_count[i] += n;
}
}
else
{
if (dp->df_lnum[idx] <= line1)
{
// inserted lines somewhere in this diff
dp->df_count[idx] += inserted;
check_unchanged = TRUE;
}
else
// inserted lines somewhere above this diff
dp->df_lnum[idx] += inserted;
}
if (check_unchanged)
// Check if inserted lines are equal, may reduce the
// size of the diff. TODO: also check for equal lines
// in the middle and perhaps split the block.
diff_check_unchanged(tp, dp);
}
}
// check if this block touches the previous one, may merge them.
if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx]
== dp->df_lnum[idx])
{
for (i = 0; i < DB_COUNT; ++i)
if (tp->tp_diffbuf[i] != NULL)
dprev->df_count[i] += dp->df_count[i];
dprev->df_next = dp->df_next;
vim_free(dp);
dp = dprev->df_next;
}
else
{
// Advance to next entry.
dprev = dp;
dp = dp->df_next;
}
}
dprev = NULL;
dp = tp->tp_first_diff;
while (dp != NULL)
{
// All counts are zero, remove this entry.
for (i = 0; i < DB_COUNT; ++i)
if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0)
break;
if (i == DB_COUNT)
{
dnext = dp->df_next;
vim_free(dp);
dp = dnext;
if (dprev == NULL)
tp->tp_first_diff = dnext;
else
dprev->df_next = dnext;
}
else
{
// Advance to next entry.
dprev = dp;
dp = dp->df_next;
}
}
if (tp == curtab)
{
// Don't redraw right away, this updates the diffs, which can be slow.
need_diff_redraw = TRUE;
// Need to recompute the scroll binding, may remove or add filler
// lines (e.g., when adding lines above w_topline). But it's slow when
// making many changes, postpone until redrawing.
diff_need_scrollbind = TRUE;
}
} | 1013 | True | 1 |
CVE-2022-2231 | False | False | False | True | AV:N/AC:M/Au:N/C:N/I:N/A:P | NETWORK | MEDIUM | NONE | NONE | NONE | PARTIAL | 4.3 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | False | [{'url': 'https://huntr.dev/bounties/8dae6ab4-7a7a-4716-a65c-9b090fa057b5', 'name': 'https://huntr.dev/bounties/8dae6ab4-7a7a-4716-a65c-9b090fa057b5', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/79481367a457951aabd9501b510fd7e3eb29c3d8', 'name': 'https://github.com/vim/vim/commit/79481367a457951aabd9501b510fd7e3eb29c3d8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/GFD2A4YLBR7OIRHTL7CK6YNMEIQ264CN/', 'name': 'FEDORA-2022-719f3ec21b', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/U743FMJGFQ35GBPCQ6OWMVZEJPDFVEWM/', 'name': 'FEDORA-2022-bb7f3cacbf', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.2.5169', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 8.2.'}] | 2022-08-21T07:15Z | 2022-06-28T20:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-06-27 20:15:10+01:00 | patch 8.2.5169: nested :source may use NULL pointer
Problem: Nested :source may use NULL pointer.
Solution: Do not use the NULL pointer. | 79481367a457951aabd9501b510fd7e3eb29c3d8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | eval0_retarg | eval0_retarg( char_u * arg , typval_T * rettv , exarg_T * eap , evalarg_T * evalarg , char_u ** retarg) | ['arg', 'rettv', 'eap', 'evalarg', 'retarg'] | eval0_retarg(
char_u *arg,
typval_T *rettv,
exarg_T *eap,
evalarg_T *evalarg,
char_u **retarg)
{
int ret;
char_u *p;
char_u *expr_end;
int did_emsg_before = did_emsg;
int called_emsg_before = called_emsg;
int flags = evalarg == NULL ? 0 : evalarg->eval_flags;
int check_for_end = retarg == NULL;
int end_error = FALSE;
p = skipwhite(arg);
ret = eval1(&p, rettv, evalarg);
expr_end = p;
p = skipwhite(p);
// In Vim9 script a command block is not split at NL characters for
// commands using an expression argument. Skip over a '#' comment to check
// for a following NL. Require white space before the '#'.
if (in_vim9script() && p > expr_end && retarg == NULL)
while (*p == '#')
{
char_u *nl = vim_strchr(p, NL);
if (nl == NULL)
break;
p = skipwhite(nl + 1);
if (eap != NULL && *p != NUL)
eap->nextcmd = p;
check_for_end = FALSE;
}
if (ret != FAIL && check_for_end)
end_error = !ends_excmd2(arg, p);
if (ret == FAIL || end_error)
{
if (ret != FAIL)
clear_tv(rettv);
/*
* Report the invalid expression unless the expression evaluation has
* been cancelled due to an aborting error, an interrupt, or an
* exception, or we already gave a more specific error.
* Also check called_emsg for when using assert_fails().
*/
if (!aborting()
&& did_emsg == did_emsg_before
&& called_emsg == called_emsg_before
&& (flags & EVAL_CONSTANT) == 0
&& (!in_vim9script() || !vim9_bad_comment(p)))
{
if (end_error)
semsg(_(e_trailing_characters_str), p);
else
semsg(_(e_invalid_expression_str), arg);
}
// Some of the expression may not have been consumed. Do not check for
// a next command to avoid more errors, unless "|" is following, which
// could only be a command separator.
if (eap != NULL && skipwhite(p)[0] == '|' && skipwhite(p)[1] != '|')
eap->nextcmd = check_nextcmd(p);
return FAIL;
}
if (retarg != NULL)
*retarg = p;
else if (check_for_end && eap != NULL)
set_nextcmd(eap, p);
return ret;
} | 342 | True | 1 |
CVE-2022-2257 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/083692d598139228e101b8c521aaef7bcf256e9a', 'name': 'https://github.com/vim/vim/commit/083692d598139228e101b8c521aaef7bcf256e9a', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/ca581f80-03ba-472a-b820-78f7fd05fe89', 'name': 'https://huntr.dev/bounties/ca581f80-03ba-472a-b820-78f7fd05fe89', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UXPO5EHDV6J4B27E65DOQGZFELUFPRSK/', 'name': 'FEDORA-2022-b06fbea2c7', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-125'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0009', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Read in GitHub repository vim/vim prior to 9.0.'}] | 2022-08-26T18:01Z | 2022-06-30T21:15Z | Out-of-bounds Read | The software reads data past the end, or before the beginning, of the intended buffer. | Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/125.html | 0 | Bram Moolenaar | 2022-06-29 21:16:58+01:00 | patch 9.0.0009: going past the end of a menu item with only modifier
Problem: Going past the end of a menu item with only modifier.
Solution: Check for NUL. | 083692d598139228e101b8c521aaef7bcf256e9a | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | str2special | str2special( char_u ** sp , int from) | ['sp', 'from'] | str2special(
char_u **sp,
int from) // TRUE for lhs of mapping
{
int c;
static char_u buf[7];
char_u *str = *sp;
int modifiers = 0;
int special = FALSE;
if (has_mbyte)
{
char_u *p;
// Try to un-escape a multi-byte character. Return the un-escaped
// string if it is a multi-byte character.
p = mb_unescape(sp);
if (p != NULL)
return p;
}
c = *str;
if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
{
if (str[1] == KS_MODIFIER)
{
modifiers = str[2];
str += 3;
c = *str;
}
if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
{
c = TO_SPECIAL(str[1], str[2]);
str += 2;
}
if (IS_SPECIAL(c) || modifiers) // special key
special = TRUE;
}
if (has_mbyte && !IS_SPECIAL(c) && MB_BYTE2LEN(c) > 1)
{
char_u *p;
*sp = str;
// Try to un-escape a multi-byte character after modifiers.
p = mb_unescape(sp);
if (p != NULL)
// Since 'special' is TRUE the multi-byte character 'c' will be
// processed by get_special_key_name()
c = (*mb_ptr2char)(p);
else
// illegal byte
*sp = str + 1;
}
else
// single-byte character or illegal byte
*sp = str + 1;
// Make special keys and C0 control characters in <> form, also <M-Space>.
// Use <Space> only for lhs of a mapping.
if (special || c < ' ' || (from && c == ' '))
return get_special_key_name(c, modifiers);
buf[0] = c;
buf[1] = NUL;
return buf;
} | 280 | True | 1 |
CVE-2022-2286 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/fe7681fb-2318-436b-8e65-daf66cd597d8', 'name': 'https://huntr.dev/bounties/fe7681fb-2318-436b-8e65-daf66cd597d8', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/f12129f1714f7d2301935bb21d896609bdac221c', 'name': 'https://github.com/vim/vim/commit/f12129f1714f7d2301935bb21d896609bdac221c', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UXPO5EHDV6J4B27E65DOQGZFELUFPRSK/', 'name': 'FEDORA-2022-b06fbea2c7', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-125'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0020', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Read in GitHub repository vim/vim prior to 9.0.'}] | 2022-08-26T18:01Z | 2022-07-02T19:15Z | Out-of-bounds Read | The software reads data past the end, or before the beginning, of the intended buffer. | Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/125.html | 0 | Bram Moolenaar | 2022-07-01 19:58:30+01:00 | patch 9.0.0020: with some completion reading past end of string
Problem: With some completion reading past end of string.
Solution: Check the length of the string. | f12129f1714f7d2301935bb21d896609bdac221c | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ins_compl_stop | ins_compl_stop( int c , int prev_mode , int retval) | ['c', 'prev_mode', 'retval'] | ins_compl_stop(int c, int prev_mode, int retval)
{
char_u *ptr;
int want_cindent;
// Get here when we have finished typing a sequence of ^N and
// ^P or other completion characters in CTRL-X mode. Free up
// memory that was used, and make sure we can redo the insert.
if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E)
{
// If any of the original typed text has been changed, eg when
// ignorecase is set, we must add back-spaces to the redo
// buffer. We add as few as necessary to delete just the part
// of the original text that has changed.
// When using the longest match, edited the match or used
// CTRL-E then don't use the current match.
if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E)
ptr = compl_curr_match->cp_str;
else
ptr = NULL;
ins_compl_fixRedoBufForLeader(ptr);
}
want_cindent = (get_can_cindent() && cindent_on());
// When completing whole lines: fix indent for 'cindent'.
// Otherwise, break line if it's too long.
if (compl_cont_mode == CTRL_X_WHOLE_LINE)
{
// re-indent the current line
if (want_cindent)
{
do_c_expr_indent();
want_cindent = FALSE; // don't do it again
}
}
else
{
int prev_col = curwin->w_cursor.col;
// put the cursor on the last char, for 'tw' formatting
if (prev_col > 0)
dec_cursor();
// only format when something was inserted
if (!arrow_used && !ins_need_undo_get() && c != Ctrl_E)
insertchar(NUL, 0, -1);
if (prev_col > 0
&& ml_get_curline()[curwin->w_cursor.col] != NUL)
inc_cursor();
}
// If the popup menu is displayed pressing CTRL-Y means accepting
// the selection without inserting anything. When
// compl_enter_selects is set the Enter key does the same.
if ((c == Ctrl_Y || (compl_enter_selects
&& (c == CAR || c == K_KENTER || c == NL)))
&& pum_visible())
retval = TRUE;
// CTRL-E means completion is Ended, go back to the typed text.
// but only do this, if the Popup is still visible
if (c == Ctrl_E)
{
ins_compl_delete();
if (compl_leader != NULL)
ins_bytes(compl_leader + get_compl_len());
else if (compl_first_match != NULL)
ins_bytes(compl_orig_text + get_compl_len());
retval = TRUE;
}
auto_format(FALSE, TRUE);
// Trigger the CompleteDonePre event to give scripts a chance to
// act upon the completion before clearing the info, and restore
// ctrl_x_mode, so that complete_info() can be used.
ctrl_x_mode = prev_mode;
ins_apply_autocmds(EVENT_COMPLETEDONEPRE);
ins_compl_free();
compl_started = FALSE;
compl_matches = 0;
if (!shortmess(SHM_COMPLETIONMENU))
msg_clr_cmdline(); // necessary for "noshowmode"
ctrl_x_mode = CTRL_X_NORMAL;
compl_enter_selects = FALSE;
if (edit_submode != NULL)
{
edit_submode = NULL;
showmode();
}
#ifdef FEAT_CMDWIN
if (c == Ctrl_C && cmdwin_type != 0)
// Avoid the popup menu remains displayed when leaving the
// command line window.
update_screen(0);
#endif
// Indent now if a key was typed that is in 'cinkeys'.
if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
do_c_expr_indent();
// Trigger the CompleteDone event to give scripts a chance to act
// upon the end of completion.
ins_apply_autocmds(EVENT_COMPLETEDONE);
return retval;
} | 355 | True | 1 |
CVE-2022-2289 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/c5274dd12224421f2430b30c53b881b9403d649e', 'name': 'https://github.com/vim/vim/commit/c5274dd12224421f2430b30c53b881b9403d649e', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/7447d2ea-db5b-4883-adf4-1eaf7deace64', 'name': 'https://huntr.dev/bounties/7447d2ea-db5b-4883-adf4-1eaf7deace64', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UXPO5EHDV6J4B27E65DOQGZFELUFPRSK/', 'name': 'FEDORA-2022-b06fbea2c7', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}, {'lang': 'en', 'value': 'CWE-416'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0026', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.'}] | 2022-08-26T17:53Z | 2022-07-03T15:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-07-02 15:10:00+01:00 | patch 9.0.0026: accessing freed memory with diff put
Problem: Accessing freed memory with diff put.
Solution: Bail out when diff pointer is no longer valid. | c5274dd12224421f2430b30c53b881b9403d649e | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ex_diffgetput | ex_diffgetput( exarg_T * eap) | ['eap'] | ex_diffgetput(exarg_T *eap)
{
linenr_T lnum;
int count;
linenr_T off = 0;
diff_T *dp;
diff_T *dprev;
diff_T *dfree;
int idx_cur;
int idx_other;
int idx_from;
int idx_to;
int i;
int added;
char_u *p;
aco_save_T aco;
buf_T *buf;
int start_skip, end_skip;
int new_count;
int buf_empty;
int found_not_ma = FALSE;
// Find the current buffer in the list of diff buffers.
idx_cur = diff_buf_idx(curbuf);
if (idx_cur == DB_COUNT)
{
emsg(_(e_current_buffer_is_not_in_diff_mode));
return;
}
if (*eap->arg == NUL)
{
// No argument: Find the other buffer in the list of diff buffers.
for (idx_other = 0; idx_other < DB_COUNT; ++idx_other)
if (curtab->tp_diffbuf[idx_other] != curbuf
&& curtab->tp_diffbuf[idx_other] != NULL)
{
if (eap->cmdidx != CMD_diffput
|| curtab->tp_diffbuf[idx_other]->b_p_ma)
break;
found_not_ma = TRUE;
}
if (idx_other == DB_COUNT)
{
if (found_not_ma)
emsg(_(e_no_other_buffer_in_diff_mode_is_modifiable));
else
emsg(_(e_no_other_buffer_in_diff_mode));
return;
}
// Check that there isn't a third buffer in the list
for (i = idx_other + 1; i < DB_COUNT; ++i)
if (curtab->tp_diffbuf[i] != curbuf
&& curtab->tp_diffbuf[i] != NULL
&& (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma))
{
emsg(_(e_more_than_two_buffers_in_diff_mode_dont_know_which_one_to_use));
return;
}
}
else
{
// Buffer number or pattern given. Ignore trailing white space.
p = eap->arg + STRLEN(eap->arg);
while (p > eap->arg && VIM_ISWHITE(p[-1]))
--p;
for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i)
;
if (eap->arg + i == p) // digits only
i = atol((char *)eap->arg);
else
{
i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE);
if (i < 0)
return; // error message already given
}
buf = buflist_findnr(i);
if (buf == NULL)
{
semsg(_(e_cant_find_buffer_str), eap->arg);
return;
}
if (buf == curbuf)
return; // nothing to do
idx_other = diff_buf_idx(buf);
if (idx_other == DB_COUNT)
{
semsg(_(e_buffer_str_is_not_in_diff_mode), eap->arg);
return;
}
}
diff_busy = TRUE;
// When no range given include the line above or below the cursor.
if (eap->addr_count == 0)
{
// Make it possible that ":diffget" on the last line gets line below
// the cursor line when there is no difference above the cursor.
if (eap->cmdidx == CMD_diffget
&& eap->line1 == curbuf->b_ml.ml_line_count
&& diff_check(curwin, eap->line1) == 0
&& (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0))
++eap->line2;
else if (eap->line1 > 0)
--eap->line1;
}
if (eap->cmdidx == CMD_diffget)
{
idx_from = idx_other;
idx_to = idx_cur;
}
else
{
idx_from = idx_cur;
idx_to = idx_other;
// Need to make the other buffer the current buffer to be able to make
// changes in it.
// set curwin/curbuf to buf and save a few things
aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]);
}
// May give the warning for a changed buffer here, which can trigger the
// FileChangedRO autocommand, which may do nasty things and mess
// everything up.
if (!curbuf->b_changed)
{
change_warning(0);
if (diff_buf_idx(curbuf) != idx_to)
{
emsg(_(e_buffer_changed_unexpectedly));
goto theend;
}
}
dprev = NULL;
for (dp = curtab->tp_first_diff; dp != NULL; )
{
if (dp->df_lnum[idx_cur] > eap->line2 + off)
break; // past the range that was specified
dfree = NULL;
lnum = dp->df_lnum[idx_to];
count = dp->df_count[idx_to];
if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off
&& u_save(lnum - 1, lnum + count) != FAIL)
{
// Inside the specified range and saving for undo worked.
start_skip = 0;
end_skip = 0;
if (eap->addr_count > 0)
{
// A range was specified: check if lines need to be skipped.
start_skip = eap->line1 + off - dp->df_lnum[idx_cur];
if (start_skip > 0)
{
// range starts below start of current diff block
if (start_skip > count)
{
lnum += count;
count = 0;
}
else
{
count -= start_skip;
lnum += start_skip;
}
}
else
start_skip = 0;
end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1
- (eap->line2 + off);
if (end_skip > 0)
{
// range ends above end of current/from diff block
if (idx_cur == idx_from) // :diffput
{
i = dp->df_count[idx_cur] - start_skip - end_skip;
if (count > i)
count = i;
}
else // :diffget
{
count -= end_skip;
end_skip = dp->df_count[idx_from] - start_skip - count;
if (end_skip < 0)
end_skip = 0;
}
}
else
end_skip = 0;
}
buf_empty = BUFEMPTY();
added = 0;
for (i = 0; i < count; ++i)
{
// remember deleting the last line of the buffer
buf_empty = curbuf->b_ml.ml_line_count == 1;
ml_delete(lnum);
--added;
}
for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i)
{
linenr_T nr;
nr = dp->df_lnum[idx_from] + start_skip + i;
if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count)
break;
p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from],
nr, FALSE));
if (p != NULL)
{
ml_append(lnum + i - 1, p, 0, FALSE);
vim_free(p);
++added;
if (buf_empty && curbuf->b_ml.ml_line_count == 2)
{
// Added the first line into an empty buffer, need to
// delete the dummy empty line.
buf_empty = FALSE;
ml_delete((linenr_T)2);
}
}
}
new_count = dp->df_count[idx_to] + added;
dp->df_count[idx_to] = new_count;
if (start_skip == 0 && end_skip == 0)
{
// Check if there are any other buffers and if the diff is
// equal in them.
for (i = 0; i < DB_COUNT; ++i)
if (curtab->tp_diffbuf[i] != NULL && i != idx_from
&& i != idx_to
&& !diff_equal_entry(dp, idx_from, i))
break;
if (i == DB_COUNT)
{
// delete the diff entry, the buffers are now equal here
dfree = dp;
dp = dp->df_next;
if (dprev == NULL)
curtab->tp_first_diff = dp;
else
dprev->df_next = dp;
}
}
// Adjust marks. This will change the following entries!
if (added != 0)
{
mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added);
if (curwin->w_cursor.lnum >= lnum)
{
// Adjust the cursor position if it's in/after the changed
// lines.
if (curwin->w_cursor.lnum >= lnum + count)
curwin->w_cursor.lnum += added;
else if (added < 0)
curwin->w_cursor.lnum = lnum;
}
}
changed_lines(lnum, 0, lnum + count, (long)added);
if (dfree != NULL)
{
// Diff is deleted, update folds in other windows.
#ifdef FEAT_FOLDING
diff_fold_update(dfree, idx_to);
#endif
vim_free(dfree);
}
else
// mark_adjust() may have changed the count in a wrong way
dp->df_count[idx_to] = new_count;
// When changing the current buffer, keep track of line numbers
if (idx_cur == idx_to)
off += added;
}
// If before the range or not deleted, go to next diff.
if (dfree == NULL)
{
dprev = dp;
dp = dp->df_next;
}
}
// restore curwin/curbuf and a few other things
if (eap->cmdidx != CMD_diffget)
{
// Syncing undo only works for the current buffer, but we change
// another buffer. Sync undo if the command was typed. This isn't
// 100% right when ":diffput" is used in a function or mapping.
if (KeyTyped)
u_sync(FALSE);
aucmd_restbuf(&aco);
}
theend:
diff_busy = FALSE;
if (diff_need_update)
ex_diffupdate(NULL);
// Check that the cursor is on a valid character and update its
// position. When there were filler lines the topline has become
// invalid.
check_cursor();
changed_line_abv_curs();
if (diff_need_update)
// redraw already done by ex_diffupdate()
diff_need_update = FALSE;
else
{
// Also need to redraw the other buffers.
diff_redraw(FALSE);
apply_autocmds(EVENT_DIFFUPDATED, NULL, NULL, FALSE, curbuf);
}
} | 1391 | True | 1 |
CVE-2022-2304 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/54e5fed6d27b747ff152cdb6edfb72ff60e70939', 'name': 'https://github.com/vim/vim/commit/54e5fed6d27b747ff152cdb6edfb72ff60e70939', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/eb7402f3-025a-402f-97a7-c38700d9548a', 'name': 'https://huntr.dev/bounties/eb7402f3-025a-402f-97a7-c38700d9548a', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/UXPO5EHDV6J4B27E65DOQGZFELUFPRSK/', 'name': 'FEDORA-2022-b06fbea2c7', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-121'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0035', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Stack-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.'}] | 2022-08-26T17:53Z | 2022-07-05T13:15Z | Stack-based Buffer Overflow | A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function). | https://cwe.mitre.org/data/definitions/121.html | 0 | Bram Moolenaar | 2022-07-04 13:37:07+01:00 | patch 9.0.0035: spell dump may go beyond end of an array
Problem: Spell dump may go beyond end of an array.
Solution: Limit the word length. | 54e5fed6d27b747ff152cdb6edfb72ff60e70939 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | spell_dump_compl | spell_dump_compl( char_u * pat , int ic , int * dir , int dumpflags_arg) | ['pat', 'ic', 'dir', 'dumpflags_arg'] | spell_dump_compl(
char_u *pat, // leading part of the word
int ic, // ignore case
int *dir, // direction for adding matches
int dumpflags_arg) // DUMPFLAG_*
{
langp_T *lp;
slang_T *slang;
idx_T arridx[MAXWLEN];
int curi[MAXWLEN];
char_u word[MAXWLEN];
int c;
char_u *byts;
idx_T *idxs;
linenr_T lnum = 0;
int round;
int depth;
int n;
int flags;
char_u *region_names = NULL; // region names being used
int do_region = TRUE; // dump region names and numbers
char_u *p;
int lpi;
int dumpflags = dumpflags_arg;
int patlen;
// When ignoring case or when the pattern starts with capital pass this on
// to dump_word().
if (pat != NULL)
{
if (ic)
dumpflags |= DUMPFLAG_ICASE;
else
{
n = captype(pat, NULL);
if (n == WF_ONECAP)
dumpflags |= DUMPFLAG_ONECAP;
else if (n == WF_ALLCAP && (int)STRLEN(pat) > mb_ptr2len(pat))
dumpflags |= DUMPFLAG_ALLCAP;
}
}
// Find out if we can support regions: All languages must support the same
// regions or none at all.
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
{
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
p = lp->lp_slang->sl_regions;
if (p[0] != 0)
{
if (region_names == NULL) // first language with regions
region_names = p;
else if (STRCMP(region_names, p) != 0)
{
do_region = FALSE; // region names are different
break;
}
}
}
if (do_region && region_names != NULL)
{
if (pat == NULL)
{
vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names);
ml_append(lnum++, IObuff, (colnr_T)0, FALSE);
}
}
else
do_region = FALSE;
/*
* Loop over all files loaded for the entries in 'spelllang'.
*/
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi)
{
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
slang = lp->lp_slang;
if (slang->sl_fbyts == NULL) // reloading failed
continue;
if (pat == NULL)
{
vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname);
ml_append(lnum++, IObuff, (colnr_T)0, FALSE);
}
// When matching with a pattern and there are no prefixes only use
// parts of the tree that match "pat".
if (pat != NULL && slang->sl_pbyts == NULL)
patlen = (int)STRLEN(pat);
else
patlen = -1;
// round 1: case-folded tree
// round 2: keep-case tree
for (round = 1; round <= 2; ++round)
{
if (round == 1)
{
dumpflags &= ~DUMPFLAG_KEEPCASE;
byts = slang->sl_fbyts;
idxs = slang->sl_fidxs;
}
else
{
dumpflags |= DUMPFLAG_KEEPCASE;
byts = slang->sl_kbyts;
idxs = slang->sl_kidxs;
}
if (byts == NULL)
continue; // array is empty
depth = 0;
arridx[0] = 0;
curi[0] = 1;
while (depth >= 0 && !got_int
&& (pat == NULL || !ins_compl_interrupted()))
{
if (curi[depth] > byts[arridx[depth]])
{
// Done all bytes at this node, go up one level.
--depth;
line_breakcheck();
ins_compl_check_keys(50, FALSE);
}
else
{
// Do one more byte at this node.
n = arridx[depth] + curi[depth];
++curi[depth];
c = byts[n];
if (c == 0)
{
// End of word, deal with the word.
// Don't use keep-case words in the fold-case tree,
// they will appear in the keep-case tree.
// Only use the word when the region matches.
flags = (int)idxs[n];
if ((round == 2 || (flags & WF_KEEPCAP) == 0)
&& (flags & WF_NEEDCOMP) == 0
&& (do_region
|| (flags & WF_REGION) == 0
|| (((unsigned)flags >> 16)
& lp->lp_region) != 0))
{
word[depth] = NUL;
if (!do_region)
flags &= ~WF_REGION;
// Dump the basic word if there is no prefix or
// when it's the first one.
c = (unsigned)flags >> 24;
if (c == 0 || curi[depth] == 2)
{
dump_word(slang, word, pat, dir,
dumpflags, flags, lnum);
if (pat == NULL)
++lnum;
}
// Apply the prefix, if there is one.
if (c != 0)
lnum = dump_prefixes(slang, word, pat, dir,
dumpflags, flags, lnum);
}
}
else
{
// Normal char, go one level deeper.
word[depth++] = c;
arridx[depth] = idxs[n];
curi[depth] = 1;
// Check if this character matches with the pattern.
// If not skip the whole tree below it.
// Always ignore case here, dump_word() will check
// proper case later. This isn't exactly right when
// length changes for multi-byte characters with
// ignore case...
if (depth <= patlen
&& MB_STRNICMP(word, pat, depth) != 0)
--depth;
}
}
}
}
}
} | 793 | True | 1 |
|
CVE-2022-2343 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/2ecb4345-2fc7-4e7f-adb0-83a20bb458f5', 'name': 'https://huntr.dev/bounties/2ecb4345-2fc7-4e7f-adb0-83a20bb458f5', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/caea66442d86e7bbba3bf3dc202c3c0d549b9853', 'name': 'https://github.com/vim/vim/commit/caea66442d86e7bbba3bf3dc202c3c0d549b9853', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0044', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0044.'}] | 2022-08-26T17:58Z | 2022-07-08T18:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-07-07 19:42:04+01:00 | patch 9.0.0045: reading past end of completion with a long line
Problem: Reading past end of completion with a long line and 'infercase'
set.
Solution: Allocate the string if needed. | caea66442d86e7bbba3bf3dc202c3c0d549b9853 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ins_compl_add_infercase | ins_compl_add_infercase( char_u * str_arg , int len , int icase , char_u * fname , int dir , int cont_s_ipos) | ['str_arg', 'len', 'icase', 'fname', 'dir', 'cont_s_ipos'] | ins_compl_add_infercase(
char_u *str_arg,
int len,
int icase,
char_u *fname,
int dir,
int cont_s_ipos) // next ^X<> will set initial_pos
{
char_u *str = str_arg;
char_u *p;
int actual_len; // Take multi-byte characters
int actual_compl_length; // into account.
int min_len;
int flags = 0;
if (p_ic && curbuf->b_p_inf && len > 0)
{
// Infer case of completed part.
// Find actual length of completion.
if (has_mbyte)
{
p = str;
actual_len = 0;
while (*p != NUL)
{
MB_PTR_ADV(p);
++actual_len;
}
}
else
actual_len = len;
// Find actual length of original text.
if (has_mbyte)
{
p = compl_orig_text;
actual_compl_length = 0;
while (*p != NUL)
{
MB_PTR_ADV(p);
++actual_compl_length;
}
}
else
actual_compl_length = compl_length;
// "actual_len" may be smaller than "actual_compl_length" when using
// thesaurus, only use the minimum when comparing.
min_len = actual_len < actual_compl_length
? actual_len : actual_compl_length;
str = ins_compl_infercase_gettext(str, actual_len, actual_compl_length,
min_len);
}
if (cont_s_ipos)
flags |= CP_CONT_S_IPOS;
if (icase)
flags |= CP_ICASE;
return ins_compl_add(str, len, fname, NULL, NULL, dir, flags, FALSE);
} | 193 | True | 1 |
|
CVE-2022-2343 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/2ecb4345-2fc7-4e7f-adb0-83a20bb458f5', 'name': 'https://huntr.dev/bounties/2ecb4345-2fc7-4e7f-adb0-83a20bb458f5', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/caea66442d86e7bbba3bf3dc202c3c0d549b9853', 'name': 'https://github.com/vim/vim/commit/caea66442d86e7bbba3bf3dc202c3c0d549b9853', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0044', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0044.'}] | 2022-08-26T17:58Z | 2022-07-08T18:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-07-07 19:42:04+01:00 | patch 9.0.0045: reading past end of completion with a long line
Problem: Reading past end of completion with a long line and 'infercase'
set.
Solution: Allocate the string if needed. | caea66442d86e7bbba3bf3dc202c3c0d549b9853 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ins_compl_infercase_gettext | ins_compl_infercase_gettext( char_u * str , int actual_len , int actual_compl_length , int min_len) | ['str', 'actual_len', 'actual_compl_length', 'min_len'] | ins_compl_infercase_gettext(
char_u *str,
int actual_len,
int actual_compl_length,
int min_len)
{
int *wca; // Wide character array.
char_u *p;
int i, c;
int has_lower = FALSE;
int was_letter = FALSE;
IObuff[0] = NUL;
// Allocate wide character array for the completion and fill it.
wca = ALLOC_MULT(int, actual_len);
if (wca == NULL)
return IObuff;
p = str;
for (i = 0; i < actual_len; ++i)
if (has_mbyte)
wca[i] = mb_ptr2char_adv(&p);
else
wca[i] = *(p++);
// Rule 1: Were any chars converted to lower?
p = compl_orig_text;
for (i = 0; i < min_len; ++i)
{
if (has_mbyte)
c = mb_ptr2char_adv(&p);
else
c = *(p++);
if (MB_ISLOWER(c))
{
has_lower = TRUE;
if (MB_ISUPPER(wca[i]))
{
// Rule 1 is satisfied.
for (i = actual_compl_length; i < actual_len; ++i)
wca[i] = MB_TOLOWER(wca[i]);
break;
}
}
}
// Rule 2: No lower case, 2nd consecutive letter converted to
// upper case.
if (!has_lower)
{
p = compl_orig_text;
for (i = 0; i < min_len; ++i)
{
if (has_mbyte)
c = mb_ptr2char_adv(&p);
else
c = *(p++);
if (was_letter && MB_ISUPPER(c) && MB_ISLOWER(wca[i]))
{
// Rule 2 is satisfied.
for (i = actual_compl_length; i < actual_len; ++i)
wca[i] = MB_TOUPPER(wca[i]);
break;
}
was_letter = MB_ISLOWER(c) || MB_ISUPPER(c);
}
}
// Copy the original case of the part we typed.
p = compl_orig_text;
for (i = 0; i < min_len; ++i)
{
if (has_mbyte)
c = mb_ptr2char_adv(&p);
else
c = *(p++);
if (MB_ISLOWER(c))
wca[i] = MB_TOLOWER(wca[i]);
else if (MB_ISUPPER(c))
wca[i] = MB_TOUPPER(wca[i]);
}
// Generate encoding specific output from wide character array.
// Multi-byte characters can occupy up to five bytes more than
// ASCII characters, and we also need one byte for NUL, so stay
// six bytes away from the edge of IObuff.
p = IObuff;
i = 0;
while (i < actual_len && (p - IObuff + 6) < IOSIZE)
if (has_mbyte)
p += (*mb_char2bytes)(wca[i++], p);
else
*(p++) = wca[i++];
*p = NUL;
vim_free(wca);
return IObuff;
} | 459 | True | 1 |
|
CVE-2022-2344 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://github.com/vim/vim/commit/baefde14550231f6468ac2ed2ed495bc381c0c92', 'name': 'https://github.com/vim/vim/commit/baefde14550231f6468ac2ed2ed495bc381c0c92', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/4a095ed9-3125-464a-b656-c31b437e1996', 'name': 'https://huntr.dev/bounties/4a095ed9-3125-464a-b656-c31b437e1996', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0045', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0045.'}] | 2022-08-21T08:15Z | 2022-07-08T19:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-07-07 19:59:49+01:00 | patch 9.0.0046: reading past end of completion with duplicate match
Problem: Reading past end of completion with duplicate match.
Solution: Check string length | baefde14550231f6468ac2ed2ed495bc381c0c92 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ins_compl_add | ins_compl_add( char_u * str , int len , char_u * fname , char_u ** cptext , typval_T * user_data UNUSED , int cdir , int flags_arg , int adup) | ['str', 'len', 'fname', 'cptext', 'UNUSED', 'cdir', 'flags_arg', 'adup'] | ins_compl_add(
char_u *str,
int len,
char_u *fname,
char_u **cptext, // extra text for popup menu or NULL
typval_T *user_data UNUSED, // "user_data" entry or NULL
int cdir,
int flags_arg,
int adup) // accept duplicate match
{
compl_T *match;
int dir = (cdir == 0 ? compl_direction : cdir);
int flags = flags_arg;
if (flags & CP_FAST)
fast_breakcheck();
else
ui_breakcheck();
if (got_int)
return FAIL;
if (len < 0)
len = (int)STRLEN(str);
// If the same match is already present, don't add it.
if (compl_first_match != NULL && !adup)
{
match = compl_first_match;
do
{
if (!match_at_original_text(match)
&& STRNCMP(match->cp_str, str, len) == 0
&& match->cp_str[len] == NUL)
return NOTDONE;
match = match->cp_next;
} while (match != NULL && !is_first_match(match));
}
// Remove any popup menu before changing the list of matches.
ins_compl_del_pum();
// Allocate a new match structure.
// Copy the values to the new match structure.
match = ALLOC_CLEAR_ONE(compl_T);
if (match == NULL)
return FAIL;
match->cp_number = -1;
if (flags & CP_ORIGINAL_TEXT)
match->cp_number = 0;
if ((match->cp_str = vim_strnsave(str, len)) == NULL)
{
vim_free(match);
return FAIL;
}
// match-fname is:
// - compl_curr_match->cp_fname if it is a string equal to fname.
// - a copy of fname, CP_FREE_FNAME is set to free later THE allocated mem.
// - NULL otherwise. --Acevedo
if (fname != NULL
&& compl_curr_match != NULL
&& compl_curr_match->cp_fname != NULL
&& STRCMP(fname, compl_curr_match->cp_fname) == 0)
match->cp_fname = compl_curr_match->cp_fname;
else if (fname != NULL)
{
match->cp_fname = vim_strsave(fname);
flags |= CP_FREE_FNAME;
}
else
match->cp_fname = NULL;
match->cp_flags = flags;
if (cptext != NULL)
{
int i;
for (i = 0; i < CPT_COUNT; ++i)
if (cptext[i] != NULL && *cptext[i] != NUL)
match->cp_text[i] = vim_strsave(cptext[i]);
}
#ifdef FEAT_EVAL
if (user_data != NULL)
match->cp_user_data = *user_data;
#endif
// Link the new match structure after (FORWARD) or before (BACKWARD) the
// current match in the list of matches .
if (compl_first_match == NULL)
match->cp_next = match->cp_prev = NULL;
else if (dir == FORWARD)
{
match->cp_next = compl_curr_match->cp_next;
match->cp_prev = compl_curr_match;
}
else // BACKWARD
{
match->cp_next = compl_curr_match;
match->cp_prev = compl_curr_match->cp_prev;
}
if (match->cp_next)
match->cp_next->cp_prev = match;
if (match->cp_prev)
match->cp_prev->cp_next = match;
else // if there's nothing before, it is the first match
compl_first_match = match;
compl_curr_match = match;
// Find the longest common string if still doing that.
if (compl_get_longest && (flags & CP_ORIGINAL_TEXT) == 0)
ins_compl_longest_match(match);
return OK;
} | 481 | True | 1 |
|
CVE-2022-2345 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/1eed7009-db6d-487b-bc41-8f2fd260483f', 'name': 'https://huntr.dev/bounties/1eed7009-db6d-487b-bc41-8f2fd260483f', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/32acf1f1a72ebb9d8942b9c9d80023bf1bb668ea', 'name': 'https://github.com/vim/vim/commit/32acf1f1a72ebb9d8942b9c9d80023bf1bb668ea', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0046', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0046.'}] | 2022-08-26T17:59Z | 2022-07-08T22:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-07-07 22:20:31+01:00 | patch 9.0.0047: using freed memory with recursive substitute
Problem: Using freed memory with recursive substitute.
Solution: Always make a copy for reg_prev_sub. | 32acf1f1a72ebb9d8942b9c9d80023bf1bb668ea | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ex_substitute | ex_substitute( exarg_T * eap) | ['eap'] | ex_substitute(exarg_T *eap)
{
linenr_T lnum;
long i = 0;
regmmatch_T regmatch;
static subflags_T subflags = {FALSE, FALSE, FALSE, TRUE, FALSE,
FALSE, FALSE, 0};
#ifdef FEAT_EVAL
subflags_T subflags_save;
#endif
int save_do_all; // remember user specified 'g' flag
int save_do_ask; // remember user specified 'c' flag
char_u *pat = NULL, *sub = NULL; // init for GCC
char_u *sub_copy = NULL;
int delimiter;
int sublen;
int got_quit = FALSE;
int got_match = FALSE;
int temp;
int which_pat;
char_u *cmd;
int save_State;
linenr_T first_line = 0; // first changed line
linenr_T last_line= 0; // below last changed line AFTER the
// change
linenr_T old_line_count = curbuf->b_ml.ml_line_count;
linenr_T line2;
long nmatch; // number of lines in match
char_u *sub_firstline; // allocated copy of first sub line
int endcolumn = FALSE; // cursor in last column when done
pos_T old_cursor = curwin->w_cursor;
int start_nsubs;
#ifdef FEAT_EVAL
int save_ma = 0;
int save_sandbox = 0;
#endif
cmd = eap->arg;
if (!global_busy)
{
sub_nsubs = 0;
sub_nlines = 0;
}
start_nsubs = sub_nsubs;
if (eap->cmdidx == CMD_tilde)
which_pat = RE_LAST; // use last used regexp
else
which_pat = RE_SUBST; // use last substitute regexp
// new pattern and substitution
if (eap->cmd[0] == 's' && *cmd != NUL && !VIM_ISWHITE(*cmd)
&& vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL)
{
// don't accept alphanumeric for separator
if (check_regexp_delim(*cmd) == FAIL)
return;
#ifdef FEAT_EVAL
if (in_vim9script() && check_global_and_subst(eap->cmd, eap->arg)
== FAIL)
return;
#endif
/*
* undocumented vi feature:
* "\/sub/" and "\?sub?" use last used search pattern (almost like
* //sub/r). "\&sub&" use last substitute pattern (like //sub/).
*/
if (*cmd == '\\')
{
if (in_vim9script())
{
emsg(_(e_cannot_use_s_backslash_in_vim9_script));
return;
}
++cmd;
if (vim_strchr((char_u *)"/?&", *cmd) == NULL)
{
emsg(_(e_backslash_should_be_followed_by));
return;
}
if (*cmd != '&')
which_pat = RE_SEARCH; // use last '/' pattern
pat = (char_u *)""; // empty search pattern
delimiter = *cmd++; // remember delimiter character
}
else // find the end of the regexp
{
which_pat = RE_LAST; // use last used regexp
delimiter = *cmd++; // remember delimiter character
pat = cmd; // remember start of search pat
cmd = skip_regexp_ex(cmd, delimiter, magic_isset(),
&eap->arg, NULL, NULL);
if (cmd[0] == delimiter) // end delimiter found
*cmd++ = NUL; // replace it with a NUL
}
/*
* Small incompatibility: vi sees '\n' as end of the command, but in
* Vim we want to use '\n' to find/substitute a NUL.
*/
sub = cmd; // remember the start of the substitution
cmd = skip_substitute(cmd, delimiter);
if (!eap->skip)
{
// In POSIX vi ":s/pat/%/" uses the previous subst. string.
if (STRCMP(sub, "%") == 0
&& vim_strchr(p_cpo, CPO_SUBPERCENT) != NULL)
{
if (old_sub == NULL) // there is no previous command
{
emsg(_(e_no_previous_substitute_regular_expression));
return;
}
sub = old_sub;
}
else
{
vim_free(old_sub);
old_sub = vim_strsave(sub);
}
}
}
else if (!eap->skip) // use previous pattern and substitution
{
if (old_sub == NULL) // there is no previous command
{
emsg(_(e_no_previous_substitute_regular_expression));
return;
}
pat = NULL; // search_regcomp() will use previous pattern
sub = old_sub;
// Vi compatibility quirk: repeating with ":s" keeps the cursor in the
// last column after using "$".
endcolumn = (curwin->w_curswant == MAXCOL);
}
// Recognize ":%s/\n//" and turn it into a join command, which is much
// more efficient.
// TODO: find a generic solution to make line-joining operations more
// efficient, avoid allocating a string that grows in size.
if (pat != NULL && STRCMP(pat, "\\n") == 0
&& *sub == NUL
&& (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l'
|| *cmd == 'p' || *cmd == '#'))))
{
linenr_T joined_lines_count;
if (eap->skip)
return;
curwin->w_cursor.lnum = eap->line1;
if (*cmd == 'l')
eap->flags = EXFLAG_LIST;
else if (*cmd == '#')
eap->flags = EXFLAG_NR;
else if (*cmd == 'p')
eap->flags = EXFLAG_PRINT;
// The number of lines joined is the number of lines in the range plus
// one. One less when the last line is included.
joined_lines_count = eap->line2 - eap->line1 + 1;
if (eap->line2 < curbuf->b_ml.ml_line_count)
++joined_lines_count;
if (joined_lines_count > 1)
{
(void)do_join(joined_lines_count, FALSE, TRUE, FALSE, TRUE);
sub_nsubs = joined_lines_count - 1;
sub_nlines = 1;
(void)do_sub_msg(FALSE);
ex_may_print(eap);
}
if ((cmdmod.cmod_flags & CMOD_KEEPPATTERNS) == 0)
save_re_pat(RE_SUBST, pat, magic_isset());
// put pattern in history
add_to_history(HIST_SEARCH, pat, TRUE, NUL);
return;
}
/*
* Find trailing options. When '&' is used, keep old options.
*/
if (*cmd == '&')
++cmd;
else
{
#ifdef FEAT_EVAL
if (in_vim9script())
{
// ignore 'gdefault' and 'edcompatible'
subflags.do_all = FALSE;
subflags.do_ask = FALSE;
}
else
#endif
if (!p_ed)
{
if (p_gd) // default is global on
subflags.do_all = TRUE;
else
subflags.do_all = FALSE;
subflags.do_ask = FALSE;
}
subflags.do_error = TRUE;
subflags.do_print = FALSE;
subflags.do_list = FALSE;
subflags.do_count = FALSE;
subflags.do_number = FALSE;
subflags.do_ic = 0;
}
while (*cmd)
{
/*
* Note that 'g' and 'c' are always inverted, also when p_ed is off.
* 'r' is never inverted.
*/
if (*cmd == 'g')
subflags.do_all = !subflags.do_all;
else if (*cmd == 'c')
subflags.do_ask = !subflags.do_ask;
else if (*cmd == 'n')
subflags.do_count = TRUE;
else if (*cmd == 'e')
subflags.do_error = !subflags.do_error;
else if (*cmd == 'r') // use last used regexp
which_pat = RE_LAST;
else if (*cmd == 'p')
subflags.do_print = TRUE;
else if (*cmd == '#')
{
subflags.do_print = TRUE;
subflags.do_number = TRUE;
}
else if (*cmd == 'l')
{
subflags.do_print = TRUE;
subflags.do_list = TRUE;
}
else if (*cmd == 'i') // ignore case
subflags.do_ic = 'i';
else if (*cmd == 'I') // don't ignore case
subflags.do_ic = 'I';
else
break;
++cmd;
}
if (subflags.do_count)
subflags.do_ask = FALSE;
save_do_all = subflags.do_all;
save_do_ask = subflags.do_ask;
/*
* check for a trailing count
*/
cmd = skipwhite(cmd);
if (VIM_ISDIGIT(*cmd))
{
i = getdigits(&cmd);
if (i <= 0 && !eap->skip && subflags.do_error)
{
emsg(_(e_positive_count_required));
return;
}
eap->line1 = eap->line2;
eap->line2 += i - 1;
if (eap->line2 > curbuf->b_ml.ml_line_count)
eap->line2 = curbuf->b_ml.ml_line_count;
}
/*
* check for trailing command or garbage
*/
cmd = skipwhite(cmd);
if (*cmd && *cmd != '"') // if not end-of-line or comment
{
set_nextcmd(eap, cmd);
if (eap->nextcmd == NULL)
{
semsg(_(e_trailing_characters_str), cmd);
return;
}
}
if (eap->skip) // not executing commands, only parsing
return;
if (!subflags.do_count && !curbuf->b_p_ma)
{
// Substitution is not allowed in non-'modifiable' buffer
emsg(_(e_cannot_make_changes_modifiable_is_off));
return;
}
if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, ®match) == FAIL)
{
if (subflags.do_error)
emsg(_(e_invalid_command));
return;
}
// the 'i' or 'I' flag overrules 'ignorecase' and 'smartcase'
if (subflags.do_ic == 'i')
regmatch.rmm_ic = TRUE;
else if (subflags.do_ic == 'I')
regmatch.rmm_ic = FALSE;
sub_firstline = NULL;
/*
* If the substitute pattern starts with "\=" then it's an expression.
* Make a copy, a recursive function may free it.
* Otherwise, '~' in the substitute pattern is replaced with the old
* pattern. We do it here once to avoid it to be replaced over and over
* again.
*/
if (sub[0] == '\\' && sub[1] == '=')
{
sub = vim_strsave(sub);
if (sub == NULL)
return;
sub_copy = sub;
}
else
sub = regtilde(sub, magic_isset());
/*
* Check for a match on each line.
*/
line2 = eap->line2;
for (lnum = eap->line1; lnum <= line2 && !(got_quit
#if defined(FEAT_EVAL)
|| aborting()
#endif
); ++lnum)
{
nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum,
(colnr_T)0, NULL);
if (nmatch)
{
colnr_T copycol;
colnr_T matchcol;
colnr_T prev_matchcol = MAXCOL;
char_u *new_end, *new_start = NULL;
unsigned new_start_len = 0;
char_u *p1;
int did_sub = FALSE;
int lastone;
int len, copy_len, needed_len;
long nmatch_tl = 0; // nr of lines matched below lnum
int do_again; // do it again after joining lines
int skip_match = FALSE;
linenr_T sub_firstlnum; // nr of first sub line
#ifdef FEAT_PROP_POPUP
int apc_flags = APC_SAVE_FOR_UNDO | APC_SUBSTITUTE;
colnr_T total_added = 0;
#endif
/*
* The new text is build up step by step, to avoid too much
* copying. There are these pieces:
* sub_firstline The old text, unmodified.
* copycol Column in the old text where we started
* looking for a match; from here old text still
* needs to be copied to the new text.
* matchcol Column number of the old text where to look
* for the next match. It's just after the
* previous match or one further.
* prev_matchcol Column just after the previous match (if any).
* Mostly equal to matchcol, except for the first
* match and after skipping an empty match.
* regmatch.*pos Where the pattern matched in the old text.
* new_start The new text, all that has been produced so
* far.
* new_end The new text, where to append new text.
*
* lnum The line number where we found the start of
* the match. Can be below the line we searched
* when there is a \n before a \zs in the
* pattern.
* sub_firstlnum The line number in the buffer where to look
* for a match. Can be different from "lnum"
* when the pattern or substitute string contains
* line breaks.
*
* Special situations:
* - When the substitute string contains a line break, the part up
* to the line break is inserted in the text, but the copy of
* the original line is kept. "sub_firstlnum" is adjusted for
* the inserted lines.
* - When the matched pattern contains a line break, the old line
* is taken from the line at the end of the pattern. The lines
* in the match are deleted later, "sub_firstlnum" is adjusted
* accordingly.
*
* The new text is built up in new_start[]. It has some extra
* room to avoid using alloc()/free() too often. new_start_len is
* the length of the allocated memory at new_start.
*
* Make a copy of the old line, so it won't be taken away when
* updating the screen or handling a multi-line match. The "old_"
* pointers point into this copy.
*/
sub_firstlnum = lnum;
copycol = 0;
matchcol = 0;
// At first match, remember current cursor position.
if (!got_match)
{
setpcmark();
got_match = TRUE;
}
/*
* Loop until nothing more to replace in this line.
* 1. Handle match with empty string.
* 2. If do_ask is set, ask for confirmation.
* 3. substitute the string.
* 4. if do_all is set, find next match
* 5. break if there isn't another match in this line
*/
for (;;)
{
// Advance "lnum" to the line where the match starts. The
// match does not start in the first line when there is a line
// break before \zs.
if (regmatch.startpos[0].lnum > 0)
{
lnum += regmatch.startpos[0].lnum;
sub_firstlnum += regmatch.startpos[0].lnum;
nmatch -= regmatch.startpos[0].lnum;
VIM_CLEAR(sub_firstline);
}
// Match might be after the last line for "\n\zs" matching at
// the end of the last line.
if (lnum > curbuf->b_ml.ml_line_count)
break;
if (sub_firstline == NULL)
{
sub_firstline = vim_strsave(ml_get(sub_firstlnum));
if (sub_firstline == NULL)
{
vim_free(new_start);
goto outofmem;
}
}
// Save the line number of the last change for the final
// cursor position (just like Vi).
curwin->w_cursor.lnum = lnum;
do_again = FALSE;
/*
* 1. Match empty string does not count, except for first
* match. This reproduces the strange vi behaviour.
* This also catches endless loops.
*/
if (matchcol == prev_matchcol
&& regmatch.endpos[0].lnum == 0
&& matchcol == regmatch.endpos[0].col)
{
if (sub_firstline[matchcol] == NUL)
// We already were at the end of the line. Don't look
// for a match in this line again.
skip_match = TRUE;
else
{
// search for a match at next column
if (has_mbyte)
matchcol += mb_ptr2len(sub_firstline + matchcol);
else
++matchcol;
}
goto skip;
}
// Normally we continue searching for a match just after the
// previous match.
matchcol = regmatch.endpos[0].col;
prev_matchcol = matchcol;
/*
* 2. If do_count is set only increase the counter.
* If do_ask is set, ask for confirmation.
*/
if (subflags.do_count)
{
// For a multi-line match, put matchcol at the NUL at
// the end of the line and set nmatch to one, so that
// we continue looking for a match on the next line.
// Avoids that ":s/\nB\@=//gc" get stuck.
if (nmatch > 1)
{
matchcol = (colnr_T)STRLEN(sub_firstline);
nmatch = 1;
skip_match = TRUE;
}
sub_nsubs++;
did_sub = TRUE;
#ifdef FEAT_EVAL
// Skip the substitution, unless an expression is used,
// then it is evaluated in the sandbox.
if (!(sub[0] == '\\' && sub[1] == '='))
#endif
goto skip;
}
if (subflags.do_ask)
{
int typed = 0;
// change State to MODE_CONFIRM, so that the mouse works
// properly
save_State = State;
State = MODE_CONFIRM;
setmouse(); // disable mouse in xterm
curwin->w_cursor.col = regmatch.startpos[0].col;
if (curwin->w_p_crb)
do_check_cursorbind();
// When 'cpoptions' contains "u" don't sync undo when
// asking for confirmation.
if (vim_strchr(p_cpo, CPO_UNDO) != NULL)
++no_u_sync;
/*
* Loop until 'y', 'n', 'q', CTRL-E or CTRL-Y typed.
*/
while (subflags.do_ask)
{
if (exmode_active)
{
char_u *resp;
colnr_T sc, ec;
print_line_no_prefix(lnum,
subflags.do_number, subflags.do_list);
getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL);
curwin->w_cursor.col = regmatch.endpos[0].col - 1;
if (curwin->w_cursor.col < 0)
curwin->w_cursor.col = 0;
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &ec);
curwin->w_cursor.col = regmatch.startpos[0].col;
if (subflags.do_number || curwin->w_p_nu)
{
int numw = number_width(curwin) + 1;
sc += numw;
ec += numw;
}
msg_start();
for (i = 0; i < (long)sc; ++i)
msg_putchar(' ');
for ( ; i <= (long)ec; ++i)
msg_putchar('^');
resp = getexmodeline('?', NULL, 0, TRUE);
if (resp != NULL)
{
typed = *resp;
vim_free(resp);
// When ":normal" runs out of characters we get
// an empty line. Use "q" to get out of the
// loop.
if (ex_normal_busy && typed == NUL)
typed = 'q';
}
}
else
{
char_u *orig_line = NULL;
int len_change = 0;
int save_p_lz = p_lz;
#ifdef FEAT_FOLDING
int save_p_fen = curwin->w_p_fen;
curwin->w_p_fen = FALSE;
#endif
// Invert the matched string.
// Remove the inversion afterwards.
temp = RedrawingDisabled;
RedrawingDisabled = 0;
// avoid calling update_screen() in vgetorpeek()
p_lz = FALSE;
if (new_start != NULL)
{
// There already was a substitution, we would
// like to show this to the user. We cannot
// really update the line, it would change
// what matches. Temporarily replace the line
// and change it back afterwards.
orig_line = vim_strsave(ml_get(lnum));
if (orig_line != NULL)
{
char_u *new_line = concat_str(new_start,
sub_firstline + copycol);
if (new_line == NULL)
VIM_CLEAR(orig_line);
else
{
// Position the cursor relative to the
// end of the line, the previous
// substitute may have inserted or
// deleted characters before the
// cursor.
len_change = (int)STRLEN(new_line)
- (int)STRLEN(orig_line);
curwin->w_cursor.col += len_change;
ml_replace(lnum, new_line, FALSE);
}
}
}
search_match_lines = regmatch.endpos[0].lnum
- regmatch.startpos[0].lnum;
search_match_endcol = regmatch.endpos[0].col
+ len_change;
highlight_match = TRUE;
update_topline();
validate_cursor();
update_screen(SOME_VALID);
highlight_match = FALSE;
redraw_later(SOME_VALID);
#ifdef FEAT_FOLDING
curwin->w_p_fen = save_p_fen;
#endif
if (msg_row == Rows - 1)
msg_didout = FALSE; // avoid a scroll-up
msg_starthere();
i = msg_scroll;
msg_scroll = 0; // truncate msg when
// needed
msg_no_more = TRUE;
// write message same highlighting as for
// wait_return
smsg_attr(HL_ATTR(HLF_R),
_("replace with %s (y/n/a/q/l/^E/^Y)?"), sub);
msg_no_more = FALSE;
msg_scroll = i;
showruler(TRUE);
windgoto(msg_row, msg_col);
RedrawingDisabled = temp;
#ifdef USE_ON_FLY_SCROLL
dont_scroll = FALSE; // allow scrolling here
#endif
++no_mapping; // don't map this key
++allow_keys; // allow special keys
typed = plain_vgetc();
--allow_keys;
--no_mapping;
// clear the question
msg_didout = FALSE; // don't scroll up
msg_col = 0;
gotocmdline(TRUE);
p_lz = save_p_lz;
// restore the line
if (orig_line != NULL)
ml_replace(lnum, orig_line, FALSE);
}
need_wait_return = FALSE; // no hit-return prompt
if (typed == 'q' || typed == ESC || typed == Ctrl_C
#ifdef UNIX
|| typed == intr_char
#endif
)
{
got_quit = TRUE;
break;
}
if (typed == 'n')
break;
if (typed == 'y')
break;
if (typed == 'l')
{
// last: replace and then stop
subflags.do_all = FALSE;
line2 = lnum;
break;
}
if (typed == 'a')
{
subflags.do_ask = FALSE;
break;
}
if (typed == Ctrl_E)
scrollup_clamp();
else if (typed == Ctrl_Y)
scrolldown_clamp();
}
State = save_State;
setmouse();
if (vim_strchr(p_cpo, CPO_UNDO) != NULL)
--no_u_sync;
if (typed == 'n')
{
// For a multi-line match, put matchcol at the NUL at
// the end of the line and set nmatch to one, so that
// we continue looking for a match on the next line.
// Avoids that ":%s/\nB\@=//gc" and ":%s/\n/,\r/gc"
// get stuck when pressing 'n'.
if (nmatch > 1)
{
matchcol = (colnr_T)STRLEN(sub_firstline);
skip_match = TRUE;
}
goto skip;
}
if (got_quit)
goto skip;
}
// Move the cursor to the start of the match, so that we can
// use "\=col(".").
curwin->w_cursor.col = regmatch.startpos[0].col;
/*
* 3. substitute the string.
*/
#ifdef FEAT_EVAL
save_ma = curbuf->b_p_ma;
save_sandbox = sandbox;
if (subflags.do_count)
{
// prevent accidentally changing the buffer by a function
curbuf->b_p_ma = FALSE;
sandbox++;
}
// Save flags for recursion. They can change for e.g.
// :s/^/\=execute("s#^##gn")
subflags_save = subflags;
// Disallow changing text or switching window in an expression.
++textlock;
#endif
// Get length of substitution part, including the NUL.
// When it fails sublen is zero.
sublen = vim_regsub_multi(®match,
sub_firstlnum - regmatch.startpos[0].lnum,
sub, sub_firstline, 0,
REGSUB_BACKSLASH
| (magic_isset() ? REGSUB_MAGIC : 0));
#ifdef FEAT_EVAL
--textlock;
// If getting the substitute string caused an error, don't do
// the replacement.
// Don't keep flags set by a recursive call.
subflags = subflags_save;
if (sublen == 0 || aborting() || subflags.do_count)
{
curbuf->b_p_ma = save_ma;
sandbox = save_sandbox;
goto skip;
}
#endif
// When the match included the "$" of the last line it may
// go beyond the last line of the buffer.
if (nmatch > curbuf->b_ml.ml_line_count - sub_firstlnum + 1)
{
nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1;
skip_match = TRUE;
}
// Need room for:
// - result so far in new_start (not for first sub in line)
// - original text up to match
// - length of substituted part
// - original text after match
// Adjust text properties here, since we have all information
// needed.
if (nmatch == 1)
{
p1 = sub_firstline;
#ifdef FEAT_PROP_POPUP
if (curbuf->b_has_textprop)
{
int bytes_added = sublen - 1 - (regmatch.endpos[0].col
- regmatch.startpos[0].col);
// When text properties are changed, need to save for
// undo first, unless done already.
if (adjust_prop_columns(lnum,
total_added + regmatch.startpos[0].col,
bytes_added, apc_flags))
apc_flags &= ~APC_SAVE_FOR_UNDO;
// Offset for column byte number of the text property
// in the resulting buffer afterwards.
total_added += bytes_added;
}
#endif
}
else
{
p1 = ml_get(sub_firstlnum + nmatch - 1);
nmatch_tl += nmatch - 1;
}
copy_len = regmatch.startpos[0].col - copycol;
needed_len = copy_len + ((unsigned)STRLEN(p1)
- regmatch.endpos[0].col) + sublen + 1;
if (new_start == NULL)
{
/*
* Get some space for a temporary buffer to do the
* substitution into (and some extra space to avoid
* too many calls to alloc()/free()).
*/
new_start_len = needed_len + 50;
if ((new_start = alloc(new_start_len)) == NULL)
goto outofmem;
*new_start = NUL;
new_end = new_start;
}
else
{
/*
* Check if the temporary buffer is long enough to do the
* substitution into. If not, make it larger (with a bit
* extra to avoid too many calls to alloc()/free()).
*/
len = (unsigned)STRLEN(new_start);
needed_len += len;
if (needed_len > (int)new_start_len)
{
new_start_len = needed_len + 50;
if ((p1 = alloc(new_start_len)) == NULL)
{
vim_free(new_start);
goto outofmem;
}
mch_memmove(p1, new_start, (size_t)(len + 1));
vim_free(new_start);
new_start = p1;
}
new_end = new_start + len;
}
/*
* copy the text up to the part that matched
*/
mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len);
new_end += copy_len;
#ifdef FEAT_EVAL
++textlock;
#endif
(void)vim_regsub_multi(®match,
sub_firstlnum - regmatch.startpos[0].lnum,
sub, new_end, sublen,
REGSUB_COPY | REGSUB_BACKSLASH
| (magic_isset() ? REGSUB_MAGIC : 0));
#ifdef FEAT_EVAL
--textlock;
#endif
sub_nsubs++;
did_sub = TRUE;
// Move the cursor to the start of the line, to avoid that it
// is beyond the end of the line after the substitution.
curwin->w_cursor.col = 0;
// For a multi-line match, make a copy of the last matched
// line and continue in that one.
if (nmatch > 1)
{
sub_firstlnum += nmatch - 1;
vim_free(sub_firstline);
sub_firstline = vim_strsave(ml_get(sub_firstlnum));
// When going beyond the last line, stop substituting.
if (sub_firstlnum <= line2)
do_again = TRUE;
else
subflags.do_all = FALSE;
}
// Remember next character to be copied.
copycol = regmatch.endpos[0].col;
if (skip_match)
{
// Already hit end of the buffer, sub_firstlnum is one
// less than what it ought to be.
vim_free(sub_firstline);
sub_firstline = vim_strsave((char_u *)"");
copycol = 0;
}
/*
* Now the trick is to replace CTRL-M chars with a real line
* break. This would make it impossible to insert a CTRL-M in
* the text. The line break can be avoided by preceding the
* CTRL-M with a backslash. To be able to insert a backslash,
* they must be doubled in the string and are halved here.
* That is Vi compatible.
*/
for (p1 = new_end; *p1; ++p1)
{
if (p1[0] == '\\' && p1[1] != NUL) // remove backslash
{
STRMOVE(p1, p1 + 1);
#ifdef FEAT_PROP_POPUP
if (curbuf->b_has_textprop)
{
// When text properties are changed, need to save
// for undo first, unless done already.
if (adjust_prop_columns(lnum,
(colnr_T)(p1 - new_start), -1,
apc_flags))
apc_flags &= ~APC_SAVE_FOR_UNDO;
}
#endif
}
else if (*p1 == CAR)
{
if (u_inssub(lnum) == OK) // prepare for undo
{
colnr_T plen = (colnr_T)(p1 - new_start + 1);
*p1 = NUL; // truncate up to the CR
ml_append(lnum - 1, new_start, plen, FALSE);
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
if (subflags.do_ask)
appended_lines(lnum - 1, 1L);
else
{
if (first_line == 0)
first_line = lnum;
last_line = lnum + 1;
}
#ifdef FEAT_PROP_POPUP
adjust_props_for_split(lnum + 1, lnum, plen, 1);
#endif
// all line numbers increase
++sub_firstlnum;
++lnum;
++line2;
// move the cursor to the new line, like Vi
++curwin->w_cursor.lnum;
// copy the rest
STRMOVE(new_start, p1 + 1);
p1 = new_start - 1;
}
}
else if (has_mbyte)
p1 += (*mb_ptr2len)(p1) - 1;
}
/*
* 4. If do_all is set, find next match.
* Prevent endless loop with patterns that match empty
* strings, e.g. :s/$/pat/g or :s/[a-z]* /(&)/g.
* But ":s/\n/#/" is OK.
*/
skip:
// We already know that we did the last subst when we are at
// the end of the line, except that a pattern like
// "bar\|\nfoo" may match at the NUL. "lnum" can be below
// "line2" when there is a \zs in the pattern after a line
// break.
lastone = (skip_match
|| got_int
|| got_quit
|| lnum > line2
|| !(subflags.do_all || do_again)
|| (sub_firstline[matchcol] == NUL && nmatch <= 1
&& !re_multiline(regmatch.regprog)));
nmatch = -1;
/*
* Replace the line in the buffer when needed. This is
* skipped when there are more matches.
* The check for nmatch_tl is needed for when multi-line
* matching must replace the lines before trying to do another
* match, otherwise "\@<=" won't work.
* When the match starts below where we start searching also
* need to replace the line first (using \zs after \n).
*/
if (lastone
|| nmatch_tl > 0
|| (nmatch = vim_regexec_multi(®match, curwin,
curbuf, sub_firstlnum,
matchcol, NULL)) == 0
|| regmatch.startpos[0].lnum > 0)
{
if (new_start != NULL)
{
/*
* Copy the rest of the line, that didn't match.
* "matchcol" has to be adjusted, we use the end of
* the line as reference, because the substitute may
* have changed the number of characters. Same for
* "prev_matchcol".
*/
STRCAT(new_start, sub_firstline + copycol);
matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol;
prev_matchcol = (colnr_T)STRLEN(sub_firstline)
- prev_matchcol;
if (u_savesub(lnum) != OK)
break;
ml_replace(lnum, new_start, TRUE);
if (nmatch_tl > 0)
{
/*
* Matched lines have now been substituted and are
* useless, delete them. The part after the match
* has been appended to new_start, we don't need
* it in the buffer.
*/
++lnum;
if (u_savedel(lnum, nmatch_tl) != OK)
break;
for (i = 0; i < nmatch_tl; ++i)
ml_delete(lnum);
mark_adjust(lnum, lnum + nmatch_tl - 1,
(long)MAXLNUM, -nmatch_tl);
if (subflags.do_ask)
deleted_lines(lnum, nmatch_tl);
--lnum;
line2 -= nmatch_tl; // nr of lines decreases
nmatch_tl = 0;
}
// When asking, undo is saved each time, must also set
// changed flag each time.
if (subflags.do_ask)
changed_bytes(lnum, 0);
else
{
if (first_line == 0)
first_line = lnum;
last_line = lnum + 1;
}
sub_firstlnum = lnum;
vim_free(sub_firstline); // free the temp buffer
sub_firstline = new_start;
new_start = NULL;
matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol;
prev_matchcol = (colnr_T)STRLEN(sub_firstline)
- prev_matchcol;
copycol = 0;
}
if (nmatch == -1 && !lastone)
nmatch = vim_regexec_multi(®match, curwin, curbuf,
sub_firstlnum, matchcol, NULL);
/*
* 5. break if there isn't another match in this line
*/
if (nmatch <= 0)
{
// If the match found didn't start where we were
// searching, do the next search in the line where we
// found the match.
if (nmatch == -1)
lnum -= regmatch.startpos[0].lnum;
break;
}
}
line_breakcheck();
}
if (did_sub)
++sub_nlines;
vim_free(new_start); // for when substitute was cancelled
VIM_CLEAR(sub_firstline); // free the copy of the original line
}
line_breakcheck();
}
if (first_line != 0)
{
// Need to subtract the number of added lines from "last_line" to get
// the line number before the change (same as adding the number of
// deleted lines).
i = curbuf->b_ml.ml_line_count - old_line_count;
changed_lines(first_line, 0, last_line - i, i);
}
outofmem:
vim_free(sub_firstline); // may have to free allocated copy of the line
// ":s/pat//n" doesn't move the cursor
if (subflags.do_count)
curwin->w_cursor = old_cursor;
if (sub_nsubs > start_nsubs)
{
if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
{
// Set the '[ and '] marks.
curbuf->b_op_start.lnum = eap->line1;
curbuf->b_op_end.lnum = line2;
curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
}
if (!global_busy)
{
// when interactive leave cursor on the match
if (!subflags.do_ask)
{
if (endcolumn)
coladvance((colnr_T)MAXCOL);
else
beginline(BL_WHITE | BL_FIX);
}
if (!do_sub_msg(subflags.do_count) && subflags.do_ask)
msg("");
}
else
global_need_beginline = TRUE;
if (subflags.do_print)
print_line(curwin->w_cursor.lnum,
subflags.do_number, subflags.do_list);
}
else if (!global_busy)
{
if (got_int) // interrupted
emsg(_(e_interrupted));
else if (got_match) // did find something but nothing substituted
msg("");
else if (subflags.do_error) // nothing found
semsg(_(e_pattern_not_found_str), get_search_pat());
}
#ifdef FEAT_FOLDING
if (subflags.do_ask && hasAnyFolding(curwin))
// Cursor position may require updating
changed_window_setting();
#endif
vim_regfree(regmatch.regprog);
vim_free(sub_copy);
// Restore the flag values, they can be used for ":&&".
subflags.do_all = save_do_all;
subflags.do_ask = save_do_ask;
} | 4041 | True | 1 |
CVE-2022-2345 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://huntr.dev/bounties/1eed7009-db6d-487b-bc41-8f2fd260483f', 'name': 'https://huntr.dev/bounties/1eed7009-db6d-487b-bc41-8f2fd260483f', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/32acf1f1a72ebb9d8942b9c9d80023bf1bb668ea', 'name': 'https://github.com/vim/vim/commit/32acf1f1a72ebb9d8942b9c9d80023bf1bb668ea', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/43Y3VJPOTTY3NTREDIFUPITM2POG4ZLP/', 'name': 'FEDORA-2022-9d7a58e376', 'refsource': 'FEDORA', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://security.gentoo.org/glsa/202208-32', 'name': 'GLSA-202208-32', 'refsource': 'GENTOO', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0046', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:fedoraproject:fedora:35:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0046.'}] | 2022-08-26T17:59Z | 2022-07-08T22:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-07-07 22:20:31+01:00 | patch 9.0.0047: using freed memory with recursive substitute
Problem: Using freed memory with recursive substitute.
Solution: Always make a copy for reg_prev_sub. | 32acf1f1a72ebb9d8942b9c9d80023bf1bb668ea | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | regtilde | regtilde( char_u * source , int magic) | ['source', 'magic'] | regtilde(char_u *source, int magic)
{
char_u *newsub = source;
char_u *tmpsub;
char_u *p;
int len;
int prevlen;
for (p = newsub; *p; ++p)
{
if ((*p == '~' && magic) || (*p == '\\' && *(p + 1) == '~' && !magic))
{
if (reg_prev_sub != NULL)
{
// length = len(newsub) - 1 + len(prev_sub) + 1
prevlen = (int)STRLEN(reg_prev_sub);
tmpsub = alloc(STRLEN(newsub) + prevlen);
if (tmpsub != NULL)
{
// copy prefix
len = (int)(p - newsub); // not including ~
mch_memmove(tmpsub, newsub, (size_t)len);
// interpret tilde
mch_memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen);
// copy postfix
if (!magic)
++p; // back off backslash
STRCPY(tmpsub + len + prevlen, p + 1);
if (newsub != source) // already allocated newsub
vim_free(newsub);
newsub = tmpsub;
p = newsub + len + prevlen;
}
}
else if (magic)
STRMOVE(p, p + 1); // remove '~'
else
STRMOVE(p, p + 2); // remove '\~'
--p;
}
else
{
if (*p == '\\' && p[1]) // skip escaped characters
++p;
if (has_mbyte)
p += (*mb_ptr2len)(p) - 1;
}
}
vim_free(reg_prev_sub);
if (newsub != source) // newsub was allocated, just keep it
reg_prev_sub = newsub;
else // no ~ found, need to save newsub
reg_prev_sub = vim_strsave(newsub);
return newsub;
} | 283 | True | 1 |
CVE-2022-2522 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/5fa9f23a63651a8abdb074b4fc2ec9b1adc6b089', 'name': 'https://github.com/vim/vim/commit/5fa9f23a63651a8abdb074b4fc2ec9b1adc6b089', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/3a2d83af-9542-4d93-8784-98b115135a22', 'name': 'https://huntr.dev/bounties/3a2d83af-9542-4d93-8784-98b115135a22', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/3a2d83af-9542-4d93-8784-98b115135a22/', 'name': 'https://huntr.dev/bounties/3a2d83af-9542-4d93-8784-98b115135a22/', 'refsource': 'MISC', 'tags': []}, {'url': 'https://github.com/vim/vim/commit/b9e717367c395490149495cf375911b5d9de889e', 'name': 'https://github.com/vim/vim/commit/b9e717367c395490149495cf375911b5d9de889e', 'refsource': 'MISC', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0060', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0061.'}] | 2022-08-19T11:25Z | 2022-07-25T14:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-07-23 09:06:48+01:00 | patch 9.0.0061: ml_get error with nested autocommand
Problem: ml_get error with nested autocommand.
Solution: Also check line numbers for a nested autocommand. (closes #10761) | 5fa9f23a63651a8abdb074b4fc2ec9b1adc6b089 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | apply_autocmds_group | apply_autocmds_group( event_T event , char_u * fname , char_u * fname_io , int force , int group , buf_T * buf , exarg_T * eap UNUSED) | ['event', 'fname', 'fname_io', 'force', 'group', 'buf', 'UNUSED'] | apply_autocmds_group(
event_T event,
char_u *fname, // NULL or empty means use actual file name
char_u *fname_io, // fname to use for <afile> on cmdline, NULL means
// use fname
int force, // when TRUE, ignore autocmd_busy
int group, // group ID, or AUGROUP_ALL
buf_T *buf, // buffer for <abuf>
exarg_T *eap UNUSED) // command arguments
{
char_u *sfname = NULL; // short file name
char_u *tail;
int save_changed;
buf_T *old_curbuf;
int retval = FALSE;
char_u *save_autocmd_fname;
int save_autocmd_fname_full;
int save_autocmd_bufnr;
char_u *save_autocmd_match;
int save_autocmd_busy;
int save_autocmd_nested;
static int nesting = 0;
AutoPatCmd_T patcmd;
AutoPat *ap;
sctx_T save_current_sctx;
#ifdef FEAT_EVAL
funccal_entry_T funccal_entry;
char_u *save_cmdarg;
long save_cmdbang;
#endif
static int filechangeshell_busy = FALSE;
#ifdef FEAT_PROFILE
proftime_T wait_time;
#endif
int did_save_redobuff = FALSE;
save_redo_T save_redo;
int save_KeyTyped = KeyTyped;
int save_did_emsg;
ESTACK_CHECK_DECLARATION
/*
* Quickly return if there are no autocommands for this event or
* autocommands are blocked.
*/
if (event == NUM_EVENTS || first_autopat[(int)event] == NULL
|| autocmd_blocked > 0)
goto BYPASS_AU;
/*
* When autocommands are busy, new autocommands are only executed when
* explicitly enabled with the "nested" flag.
*/
if (autocmd_busy && !(force || autocmd_nested))
goto BYPASS_AU;
#ifdef FEAT_EVAL
/*
* Quickly return when immediately aborting on error, or when an interrupt
* occurred or an exception was thrown but not caught.
*/
if (aborting())
goto BYPASS_AU;
#endif
/*
* FileChangedShell never nests, because it can create an endless loop.
*/
if (filechangeshell_busy && (event == EVENT_FILECHANGEDSHELL
|| event == EVENT_FILECHANGEDSHELLPOST))
goto BYPASS_AU;
/*
* Ignore events in 'eventignore'.
*/
if (event_ignored(event))
goto BYPASS_AU;
/*
* Allow nesting of autocommands, but restrict the depth, because it's
* possible to create an endless loop.
*/
if (nesting == 10)
{
emsg(_(e_autocommand_nesting_too_deep));
goto BYPASS_AU;
}
/*
* Check if these autocommands are disabled. Used when doing ":all" or
* ":ball".
*/
if ( (autocmd_no_enter
&& (event == EVENT_WINENTER || event == EVENT_BUFENTER))
|| (autocmd_no_leave
&& (event == EVENT_WINLEAVE || event == EVENT_BUFLEAVE)))
goto BYPASS_AU;
/*
* Save the autocmd_* variables and info about the current buffer.
*/
save_autocmd_fname = autocmd_fname;
save_autocmd_fname_full = autocmd_fname_full;
save_autocmd_bufnr = autocmd_bufnr;
save_autocmd_match = autocmd_match;
save_autocmd_busy = autocmd_busy;
save_autocmd_nested = autocmd_nested;
save_changed = curbuf->b_changed;
old_curbuf = curbuf;
/*
* Set the file name to be used for <afile>.
* Make a copy to avoid that changing a buffer name or directory makes it
* invalid.
*/
if (fname_io == NULL)
{
if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
|| event == EVENT_OPTIONSET
|| event == EVENT_MODECHANGED)
autocmd_fname = NULL;
else if (fname != NULL && !ends_excmd(*fname))
autocmd_fname = fname;
else if (buf != NULL)
autocmd_fname = buf->b_ffname;
else
autocmd_fname = NULL;
}
else
autocmd_fname = fname_io;
if (autocmd_fname != NULL)
autocmd_fname = vim_strsave(autocmd_fname);
autocmd_fname_full = FALSE; // call FullName_save() later
/*
* Set the buffer number to be used for <abuf>.
*/
if (buf == NULL)
autocmd_bufnr = 0;
else
autocmd_bufnr = buf->b_fnum;
/*
* When the file name is NULL or empty, use the file name of buffer "buf".
* Always use the full path of the file name to match with, in case
* "allow_dirs" is set.
*/
if (fname == NULL || *fname == NUL)
{
if (buf == NULL)
fname = NULL;
else
{
#ifdef FEAT_SYN_HL
if (event == EVENT_SYNTAX)
fname = buf->b_p_syn;
else
#endif
if (event == EVENT_FILETYPE)
fname = buf->b_p_ft;
else
{
if (buf->b_sfname != NULL)
sfname = vim_strsave(buf->b_sfname);
fname = buf->b_ffname;
}
}
if (fname == NULL)
fname = (char_u *)"";
fname = vim_strsave(fname); // make a copy, so we can change it
}
else
{
sfname = vim_strsave(fname);
// Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
// ColorScheme, QuickFixCmd*, DirChanged and similar.
if (event == EVENT_FILETYPE
|| event == EVENT_SYNTAX
|| event == EVENT_CMDLINECHANGED
|| event == EVENT_CMDLINEENTER
|| event == EVENT_CMDLINELEAVE
|| event == EVENT_CMDWINENTER
|| event == EVENT_CMDWINLEAVE
|| event == EVENT_CMDUNDEFINED
|| event == EVENT_FUNCUNDEFINED
|| event == EVENT_REMOTEREPLY
|| event == EVENT_SPELLFILEMISSING
|| event == EVENT_QUICKFIXCMDPRE
|| event == EVENT_COLORSCHEME
|| event == EVENT_COLORSCHEMEPRE
|| event == EVENT_OPTIONSET
|| event == EVENT_QUICKFIXCMDPOST
|| event == EVENT_DIRCHANGED
|| event == EVENT_DIRCHANGEDPRE
|| event == EVENT_MODECHANGED
|| event == EVENT_USER
|| event == EVENT_WINCLOSED
|| event == EVENT_WINSCROLLED)
{
fname = vim_strsave(fname);
autocmd_fname_full = TRUE; // don't expand it later
}
else
fname = FullName_save(fname, FALSE);
}
if (fname == NULL) // out of memory
{
vim_free(sfname);
retval = FALSE;
goto BYPASS_AU;
}
#ifdef BACKSLASH_IN_FILENAME
/*
* Replace all backslashes with forward slashes. This makes the
* autocommand patterns portable between Unix and MS-DOS.
*/
if (sfname != NULL)
forward_slash(sfname);
forward_slash(fname);
#endif
#ifdef VMS
// remove version for correct match
if (sfname != NULL)
vms_remove_version(sfname);
vms_remove_version(fname);
#endif
/*
* Set the name to be used for <amatch>.
*/
autocmd_match = fname;
// Don't redraw while doing autocommands.
++RedrawingDisabled;
// name and lnum are filled in later
estack_push(ETYPE_AUCMD, NULL, 0);
ESTACK_CHECK_SETUP
save_current_sctx = current_sctx;
#ifdef FEAT_EVAL
# ifdef FEAT_PROFILE
if (do_profiling == PROF_YES)
prof_child_enter(&wait_time); // doesn't count for the caller itself
# endif
// Don't use local function variables, if called from a function.
save_funccal(&funccal_entry);
#endif
/*
* When starting to execute autocommands, save the search patterns.
*/
if (!autocmd_busy)
{
save_search_patterns();
if (!ins_compl_active())
{
saveRedobuff(&save_redo);
did_save_redobuff = TRUE;
}
did_filetype = keep_filetype;
}
/*
* Note that we are applying autocmds. Some commands need to know.
*/
autocmd_busy = TRUE;
filechangeshell_busy = (event == EVENT_FILECHANGEDSHELL);
++nesting; // see matching decrement below
// Remember that FileType was triggered. Used for did_filetype().
if (event == EVENT_FILETYPE)
did_filetype = TRUE;
tail = gettail(fname);
// Find first autocommand that matches
CLEAR_FIELD(patcmd);
patcmd.curpat = first_autopat[(int)event];
patcmd.group = group;
patcmd.fname = fname;
patcmd.sfname = sfname;
patcmd.tail = tail;
patcmd.event = event;
patcmd.arg_bufnr = autocmd_bufnr;
auto_next_pat(&patcmd, FALSE);
// found one, start executing the autocommands
if (patcmd.curpat != NULL)
{
// add to active_apc_list
patcmd.next = active_apc_list;
active_apc_list = &patcmd;
#ifdef FEAT_EVAL
// set v:cmdarg (only when there is a matching pattern)
save_cmdbang = (long)get_vim_var_nr(VV_CMDBANG);
if (eap != NULL)
{
save_cmdarg = set_cmdarg(eap, NULL);
set_vim_var_nr(VV_CMDBANG, (long)eap->forceit);
}
else
save_cmdarg = NULL; // avoid gcc warning
#endif
retval = TRUE;
// mark the last pattern, to avoid an endless loop when more patterns
// are added when executing autocommands
for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next)
ap->last = FALSE;
ap->last = TRUE;
if (nesting == 1)
// make sure cursor and topline are valid
check_lnums(TRUE);
save_did_emsg = did_emsg;
do_cmdline(NULL, getnextac, (void *)&patcmd,
DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
did_emsg += save_did_emsg;
if (nesting == 1)
// restore cursor and topline, unless they were changed
reset_lnums();
#ifdef FEAT_EVAL
if (eap != NULL)
{
(void)set_cmdarg(NULL, save_cmdarg);
set_vim_var_nr(VV_CMDBANG, save_cmdbang);
}
#endif
// delete from active_apc_list
if (active_apc_list == &patcmd) // just in case
active_apc_list = patcmd.next;
}
--RedrawingDisabled;
autocmd_busy = save_autocmd_busy;
filechangeshell_busy = FALSE;
autocmd_nested = save_autocmd_nested;
vim_free(SOURCING_NAME);
ESTACK_CHECK_NOW
estack_pop();
vim_free(autocmd_fname);
autocmd_fname = save_autocmd_fname;
autocmd_fname_full = save_autocmd_fname_full;
autocmd_bufnr = save_autocmd_bufnr;
autocmd_match = save_autocmd_match;
current_sctx = save_current_sctx;
#ifdef FEAT_EVAL
restore_funccal();
# ifdef FEAT_PROFILE
if (do_profiling == PROF_YES)
prof_child_exit(&wait_time);
# endif
#endif
KeyTyped = save_KeyTyped;
vim_free(fname);
vim_free(sfname);
--nesting; // see matching increment above
/*
* When stopping to execute autocommands, restore the search patterns and
* the redo buffer. Free any buffers in the au_pending_free_buf list and
* free any windows in the au_pending_free_win list.
*/
if (!autocmd_busy)
{
restore_search_patterns();
if (did_save_redobuff)
restoreRedobuff(&save_redo);
did_filetype = FALSE;
while (au_pending_free_buf != NULL)
{
buf_T *b = au_pending_free_buf->b_next;
vim_free(au_pending_free_buf);
au_pending_free_buf = b;
}
while (au_pending_free_win != NULL)
{
win_T *w = au_pending_free_win->w_next;
vim_free(au_pending_free_win);
au_pending_free_win = w;
}
}
/*
* Some events don't set or reset the Changed flag.
* Check if still in the same buffer!
*/
if (curbuf == old_curbuf
&& (event == EVENT_BUFREADPOST
|| event == EVENT_BUFWRITEPOST
|| event == EVENT_FILEAPPENDPOST
|| event == EVENT_VIMLEAVE
|| event == EVENT_VIMLEAVEPRE))
{
if (curbuf->b_changed != save_changed)
need_maketitle = TRUE;
curbuf->b_changed = save_changed;
}
au_cleanup(); // may really delete removed patterns/commands now
BYPASS_AU:
// When wiping out a buffer make sure all its buffer-local autocommands
// are deleted.
if (event == EVENT_BUFWIPEOUT && buf != NULL)
aubuflocal_remove(buf);
if (retval == OK && event == EVENT_FILETYPE)
au_did_filetype = TRUE;
return retval;
} | 1259 | True | 1 |
|
CVE-2022-2522 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/5fa9f23a63651a8abdb074b4fc2ec9b1adc6b089', 'name': 'https://github.com/vim/vim/commit/5fa9f23a63651a8abdb074b4fc2ec9b1adc6b089', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/3a2d83af-9542-4d93-8784-98b115135a22', 'name': 'https://huntr.dev/bounties/3a2d83af-9542-4d93-8784-98b115135a22', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/3a2d83af-9542-4d93-8784-98b115135a22/', 'name': 'https://huntr.dev/bounties/3a2d83af-9542-4d93-8784-98b115135a22/', 'refsource': 'MISC', 'tags': []}, {'url': 'https://github.com/vim/vim/commit/b9e717367c395490149495cf375911b5d9de889e', 'name': 'https://github.com/vim/vim/commit/b9e717367c395490149495cf375911b5d9de889e', 'refsource': 'MISC', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0060', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0061.'}] | 2022-08-19T11:25Z | 2022-07-25T14:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-07-23 09:06:48+01:00 | patch 9.0.0061: ml_get error with nested autocommand
Problem: ml_get error with nested autocommand.
Solution: Also check line numbers for a nested autocommand. (closes #10761) | 5fa9f23a63651a8abdb074b4fc2ec9b1adc6b089 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | check_lnums | check_lnums( int do_curwin) | ['do_curwin'] | check_lnums(int do_curwin)
{
win_T *wp;
tabpage_T *tp;
FOR_ALL_TAB_WINDOWS(tp, wp)
if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf)
{
// save the original cursor position and topline
wp->w_save_cursor.w_cursor_save = wp->w_cursor;
wp->w_save_cursor.w_topline_save = wp->w_topline;
if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count)
wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
if (wp->w_topline > curbuf->b_ml.ml_line_count)
wp->w_topline = curbuf->b_ml.ml_line_count;
// save the corrected cursor position and topline
wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
wp->w_save_cursor.w_topline_corr = wp->w_topline;
}
} | 127 | True | 1 |
|
CVE-2022-2598 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | nan | [{'url': 'https://github.com/vim/vim/commit/4e677b9c40ccbc5f090971b31dc2fe07bf05541d', 'name': 'https://github.com/vim/vim/commit/4e677b9c40ccbc5f090971b31dc2fe07bf05541d', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/2f08363a-47a2-422d-a7de-ce96a89ad08e', 'name': 'https://huntr.dev/bounties/2f08363a-47a2-422d-a7de-ce96a89ad08e', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-475'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0100', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Undefined Behavior for Input to API in GitHub repository vim/vim prior to 9.0.0100.'}] | 2022-08-05T03:43Z | 2022-08-01T15:15Z | Undefined Behavior for Input to API | The behavior of this function is undefined unless its control parameter is set to a specific value. | https://cwe.mitre.org/data/definitions/475.html | 0 | Bram Moolenaar | 2022-07-28 18:44:27+01:00 | patch 9.0.0101: invalid memory access in diff mode with "dp" and undo
Problem: Invalid memory access in diff mode with "dp" and undo.
Solution: Make sure the line number does not go below one. | 4e677b9c40ccbc5f090971b31dc2fe07bf05541d | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | diff_mark_adjust_tp | diff_mark_adjust_tp( tabpage_T * tp , int idx , linenr_T line1 , linenr_T line2 , long amount , long amount_after) | ['tp', 'idx', 'line1', 'line2', 'amount', 'amount_after'] | diff_mark_adjust_tp(
tabpage_T *tp,
int idx,
linenr_T line1,
linenr_T line2,
long amount,
long amount_after)
{
diff_T *dp;
diff_T *dprev;
diff_T *dnext;
int i;
int inserted, deleted;
int n, off;
linenr_T last;
linenr_T lnum_deleted = line1; // lnum of remaining deletion
int check_unchanged;
if (diff_internal())
{
// Will update diffs before redrawing. Set _invalid to update the
// diffs themselves, set _update to also update folds properly just
// before redrawing.
// Do update marks here, it is needed for :%diffput.
tp->tp_diff_invalid = TRUE;
tp->tp_diff_update = TRUE;
}
if (line2 == MAXLNUM)
{
// mark_adjust(99, MAXLNUM, 9, 0): insert lines
inserted = amount;
deleted = 0;
}
else if (amount_after > 0)
{
// mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines
inserted = amount_after;
deleted = 0;
}
else
{
// mark_adjust(98, 99, MAXLNUM, -2): delete lines
inserted = 0;
deleted = -amount_after;
}
dprev = NULL;
dp = tp->tp_first_diff;
for (;;)
{
// If the change is after the previous diff block and before the next
// diff block, thus not touching an existing change, create a new diff
// block. Don't do this when ex_diffgetput() is busy.
if ((dp == NULL || dp->df_lnum[idx] - 1 > line2
|| (line2 == MAXLNUM && dp->df_lnum[idx] > line1))
&& (dprev == NULL
|| dprev->df_lnum[idx] + dprev->df_count[idx] < line1)
&& !diff_busy)
{
dnext = diff_alloc_new(tp, dprev, dp);
if (dnext == NULL)
return;
dnext->df_lnum[idx] = line1;
dnext->df_count[idx] = inserted;
for (i = 0; i < DB_COUNT; ++i)
if (tp->tp_diffbuf[i] != NULL && i != idx)
{
if (dprev == NULL)
dnext->df_lnum[i] = line1;
else
dnext->df_lnum[i] = line1
+ (dprev->df_lnum[i] + dprev->df_count[i])
- (dprev->df_lnum[idx] + dprev->df_count[idx]);
dnext->df_count[i] = deleted;
}
}
// if at end of the list, quit
if (dp == NULL)
break;
/*
* Check for these situations:
* 1 2 3
* 1 2 3
* line1 2 3 4 5
* 2 3 4 5
* 2 3 4 5
* line2 2 3 4 5
* 3 5 6
* 3 5 6
*/
// compute last line of this change
last = dp->df_lnum[idx] + dp->df_count[idx] - 1;
// 1. change completely above line1: nothing to do
if (last >= line1 - 1)
{
// 6. change below line2: only adjust for amount_after; also when
// "deleted" became zero when deleted all lines between two diffs
if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2)
{
if (amount_after == 0)
break; // nothing left to change
dp->df_lnum[idx] += amount_after;
}
else
{
check_unchanged = FALSE;
// 2. 3. 4. 5.: inserted/deleted lines touching this diff.
if (deleted > 0)
{
off = 0;
if (dp->df_lnum[idx] >= line1)
{
if (last <= line2)
{
// 4. delete all lines of diff
if (dp->df_next != NULL
&& dp->df_next->df_lnum[idx] - 1 <= line2)
{
// delete continues in next diff, only do
// lines until that one
n = dp->df_next->df_lnum[idx] - lnum_deleted;
deleted -= n;
n -= dp->df_count[idx];
lnum_deleted = dp->df_next->df_lnum[idx];
}
else
n = deleted - dp->df_count[idx];
dp->df_count[idx] = 0;
}
else
{
// 5. delete lines at or just before top of diff
off = dp->df_lnum[idx] - lnum_deleted;
n = off;
dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1;
check_unchanged = TRUE;
}
dp->df_lnum[idx] = line1;
}
else
{
if (last < line2)
{
// 2. delete at end of diff
dp->df_count[idx] -= last - lnum_deleted + 1;
if (dp->df_next != NULL
&& dp->df_next->df_lnum[idx] - 1 <= line2)
{
// delete continues in next diff, only do
// lines until that one
n = dp->df_next->df_lnum[idx] - 1 - last;
deleted -= dp->df_next->df_lnum[idx]
- lnum_deleted;
lnum_deleted = dp->df_next->df_lnum[idx];
}
else
n = line2 - last;
check_unchanged = TRUE;
}
else
{
// 3. delete lines inside the diff
n = 0;
dp->df_count[idx] -= deleted;
}
}
for (i = 0; i < DB_COUNT; ++i)
if (tp->tp_diffbuf[i] != NULL && i != idx)
{
dp->df_lnum[i] -= off;
dp->df_count[i] += n;
}
}
else
{
if (dp->df_lnum[idx] <= line1)
{
// inserted lines somewhere in this diff
dp->df_count[idx] += inserted;
check_unchanged = TRUE;
}
else
// inserted lines somewhere above this diff
dp->df_lnum[idx] += inserted;
}
if (check_unchanged)
// Check if inserted lines are equal, may reduce the
// size of the diff. TODO: also check for equal lines
// in the middle and perhaps split the block.
diff_check_unchanged(tp, dp);
}
}
// check if this block touches the previous one, may merge them.
if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx]
== dp->df_lnum[idx])
{
for (i = 0; i < DB_COUNT; ++i)
if (tp->tp_diffbuf[i] != NULL)
dprev->df_count[i] += dp->df_count[i];
dprev->df_next = dp->df_next;
vim_free(dp);
dp = dprev->df_next;
}
else
{
// Advance to next entry.
dprev = dp;
dp = dp->df_next;
}
}
dprev = NULL;
dp = tp->tp_first_diff;
while (dp != NULL)
{
// All counts are zero, remove this entry.
for (i = 0; i < DB_COUNT; ++i)
if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0)
break;
if (i == DB_COUNT)
{
dnext = dp->df_next;
vim_free(dp);
dp = dnext;
if (dprev == NULL)
tp->tp_first_diff = dnext;
else
dprev->df_next = dnext;
}
else
{
// Advance to next entry.
dprev = dp;
dp = dp->df_next;
}
}
if (tp == curtab)
{
// Don't redraw right away, this updates the diffs, which can be slow.
need_diff_redraw = TRUE;
// Need to recompute the scroll binding, may remove or add filler
// lines (e.g., when adding lines above w_topline). But it's slow when
// making many changes, postpone until redrawing.
diff_need_scrollbind = TRUE;
}
} | 1013 | True | 1 |
|
CVE-2022-2598 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | nan | [{'url': 'https://github.com/vim/vim/commit/4e677b9c40ccbc5f090971b31dc2fe07bf05541d', 'name': 'https://github.com/vim/vim/commit/4e677b9c40ccbc5f090971b31dc2fe07bf05541d', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/2f08363a-47a2-422d-a7de-ce96a89ad08e', 'name': 'https://huntr.dev/bounties/2f08363a-47a2-422d-a7de-ce96a89ad08e', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-475'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0100', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Undefined Behavior for Input to API in GitHub repository vim/vim prior to 9.0.0100.'}] | 2022-08-05T03:43Z | 2022-08-01T15:15Z | Undefined Behavior for Input to API | The behavior of this function is undefined unless its control parameter is set to a specific value. | https://cwe.mitre.org/data/definitions/475.html | 0 | Bram Moolenaar | 2022-07-28 18:44:27+01:00 | patch 9.0.0101: invalid memory access in diff mode with "dp" and undo
Problem: Invalid memory access in diff mode with "dp" and undo.
Solution: Make sure the line number does not go below one. | 4e677b9c40ccbc5f090971b31dc2fe07bf05541d | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ex_diffgetput | ex_diffgetput( exarg_T * eap) | ['eap'] | ex_diffgetput(exarg_T *eap)
{
linenr_T lnum;
int count;
linenr_T off = 0;
diff_T *dp;
diff_T *dprev;
diff_T *dfree;
int idx_cur;
int idx_other;
int idx_from;
int idx_to;
int i;
int added;
char_u *p;
aco_save_T aco;
buf_T *buf;
int start_skip, end_skip;
int new_count;
int buf_empty;
int found_not_ma = FALSE;
// Find the current buffer in the list of diff buffers.
idx_cur = diff_buf_idx(curbuf);
if (idx_cur == DB_COUNT)
{
emsg(_(e_current_buffer_is_not_in_diff_mode));
return;
}
if (*eap->arg == NUL)
{
// No argument: Find the other buffer in the list of diff buffers.
for (idx_other = 0; idx_other < DB_COUNT; ++idx_other)
if (curtab->tp_diffbuf[idx_other] != curbuf
&& curtab->tp_diffbuf[idx_other] != NULL)
{
if (eap->cmdidx != CMD_diffput
|| curtab->tp_diffbuf[idx_other]->b_p_ma)
break;
found_not_ma = TRUE;
}
if (idx_other == DB_COUNT)
{
if (found_not_ma)
emsg(_(e_no_other_buffer_in_diff_mode_is_modifiable));
else
emsg(_(e_no_other_buffer_in_diff_mode));
return;
}
// Check that there isn't a third buffer in the list
for (i = idx_other + 1; i < DB_COUNT; ++i)
if (curtab->tp_diffbuf[i] != curbuf
&& curtab->tp_diffbuf[i] != NULL
&& (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma))
{
emsg(_(e_more_than_two_buffers_in_diff_mode_dont_know_which_one_to_use));
return;
}
}
else
{
// Buffer number or pattern given. Ignore trailing white space.
p = eap->arg + STRLEN(eap->arg);
while (p > eap->arg && VIM_ISWHITE(p[-1]))
--p;
for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i)
;
if (eap->arg + i == p) // digits only
i = atol((char *)eap->arg);
else
{
i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE);
if (i < 0)
return; // error message already given
}
buf = buflist_findnr(i);
if (buf == NULL)
{
semsg(_(e_cant_find_buffer_str), eap->arg);
return;
}
if (buf == curbuf)
return; // nothing to do
idx_other = diff_buf_idx(buf);
if (idx_other == DB_COUNT)
{
semsg(_(e_buffer_str_is_not_in_diff_mode), eap->arg);
return;
}
}
diff_busy = TRUE;
// When no range given include the line above or below the cursor.
if (eap->addr_count == 0)
{
// Make it possible that ":diffget" on the last line gets line below
// the cursor line when there is no difference above the cursor.
if (eap->cmdidx == CMD_diffget
&& eap->line1 == curbuf->b_ml.ml_line_count
&& diff_check(curwin, eap->line1) == 0
&& (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0))
++eap->line2;
else if (eap->line1 > 0)
--eap->line1;
}
if (eap->cmdidx == CMD_diffget)
{
idx_from = idx_other;
idx_to = idx_cur;
}
else
{
idx_from = idx_cur;
idx_to = idx_other;
// Need to make the other buffer the current buffer to be able to make
// changes in it.
// set curwin/curbuf to buf and save a few things
aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]);
}
// May give the warning for a changed buffer here, which can trigger the
// FileChangedRO autocommand, which may do nasty things and mess
// everything up.
if (!curbuf->b_changed)
{
change_warning(0);
if (diff_buf_idx(curbuf) != idx_to)
{
emsg(_(e_buffer_changed_unexpectedly));
goto theend;
}
}
dprev = NULL;
for (dp = curtab->tp_first_diff; dp != NULL; )
{
if (dp->df_lnum[idx_cur] > eap->line2 + off)
break; // past the range that was specified
dfree = NULL;
lnum = dp->df_lnum[idx_to];
count = dp->df_count[idx_to];
if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off
&& u_save(lnum - 1, lnum + count) != FAIL)
{
// Inside the specified range and saving for undo worked.
start_skip = 0;
end_skip = 0;
if (eap->addr_count > 0)
{
// A range was specified: check if lines need to be skipped.
start_skip = eap->line1 + off - dp->df_lnum[idx_cur];
if (start_skip > 0)
{
// range starts below start of current diff block
if (start_skip > count)
{
lnum += count;
count = 0;
}
else
{
count -= start_skip;
lnum += start_skip;
}
}
else
start_skip = 0;
end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1
- (eap->line2 + off);
if (end_skip > 0)
{
// range ends above end of current/from diff block
if (idx_cur == idx_from) // :diffput
{
i = dp->df_count[idx_cur] - start_skip - end_skip;
if (count > i)
count = i;
}
else // :diffget
{
count -= end_skip;
end_skip = dp->df_count[idx_from] - start_skip - count;
if (end_skip < 0)
end_skip = 0;
}
}
else
end_skip = 0;
}
buf_empty = BUFEMPTY();
added = 0;
for (i = 0; i < count; ++i)
{
// remember deleting the last line of the buffer
buf_empty = curbuf->b_ml.ml_line_count == 1;
ml_delete(lnum);
--added;
}
for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i)
{
linenr_T nr;
nr = dp->df_lnum[idx_from] + start_skip + i;
if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count)
break;
p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from],
nr, FALSE));
if (p != NULL)
{
ml_append(lnum + i - 1, p, 0, FALSE);
vim_free(p);
++added;
if (buf_empty && curbuf->b_ml.ml_line_count == 2)
{
// Added the first line into an empty buffer, need to
// delete the dummy empty line.
buf_empty = FALSE;
ml_delete((linenr_T)2);
}
}
}
new_count = dp->df_count[idx_to] + added;
dp->df_count[idx_to] = new_count;
if (start_skip == 0 && end_skip == 0)
{
// Check if there are any other buffers and if the diff is
// equal in them.
for (i = 0; i < DB_COUNT; ++i)
if (curtab->tp_diffbuf[i] != NULL && i != idx_from
&& i != idx_to
&& !diff_equal_entry(dp, idx_from, i))
break;
if (i == DB_COUNT)
{
// delete the diff entry, the buffers are now equal here
dfree = dp;
dp = dp->df_next;
if (dprev == NULL)
curtab->tp_first_diff = dp;
else
dprev->df_next = dp;
}
}
if (added != 0)
{
// Adjust marks. This will change the following entries!
mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added);
if (curwin->w_cursor.lnum >= lnum)
{
// Adjust the cursor position if it's in/after the changed
// lines.
if (curwin->w_cursor.lnum >= lnum + count)
curwin->w_cursor.lnum += added;
else if (added < 0)
curwin->w_cursor.lnum = lnum;
}
}
changed_lines(lnum, 0, lnum + count, (long)added);
if (dfree != NULL)
{
// Diff is deleted, update folds in other windows.
#ifdef FEAT_FOLDING
diff_fold_update(dfree, idx_to);
#endif
vim_free(dfree);
}
// mark_adjust() may have made "dp" invalid. We don't know where
// to continue then, bail out.
if (added != 0 && !valid_diff(dp))
break;
if (dfree == NULL)
// mark_adjust() may have changed the count in a wrong way
dp->df_count[idx_to] = new_count;
// When changing the current buffer, keep track of line numbers
if (idx_cur == idx_to)
off += added;
}
// If before the range or not deleted, go to next diff.
if (dfree == NULL)
{
dprev = dp;
dp = dp->df_next;
}
}
// restore curwin/curbuf and a few other things
if (eap->cmdidx != CMD_diffget)
{
// Syncing undo only works for the current buffer, but we change
// another buffer. Sync undo if the command was typed. This isn't
// 100% right when ":diffput" is used in a function or mapping.
if (KeyTyped)
u_sync(FALSE);
aucmd_restbuf(&aco);
}
theend:
diff_busy = FALSE;
if (diff_need_update)
ex_diffupdate(NULL);
// Check that the cursor is on a valid character and update its
// position. When there were filler lines the topline has become
// invalid.
check_cursor();
changed_line_abv_curs();
if (diff_need_update)
// redraw already done by ex_diffupdate()
diff_need_update = FALSE;
else
{
// Also need to redraw the other buffers.
diff_redraw(FALSE);
apply_autocmds(EVENT_DIFFUPDATED, NULL, NULL, FALSE, curbuf);
}
} | 1410 | True | 1 |
|
CVE-2022-2571 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/a6f9e300161f4cb54713da22f65b261595e8e614', 'name': 'https://github.com/vim/vim/commit/a6f9e300161f4cb54713da22f65b261595e8e614', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/2e5a1dc4-2dfb-4e5f-8c70-e1ede21f3571', 'name': 'https://huntr.dev/bounties/2e5a1dc4-2dfb-4e5f-8c70-e1ede21f3571', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0101', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0101.'}] | 2022-08-04T23:31Z | 2022-08-01T15:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-07-28 21:51:37+01:00 | patch 9.0.0102: reading past end of line with insert mode completion
Problem: Reading past end of line with insert mode completion.
Solution: Check text length. | a6f9e300161f4cb54713da22f65b261595e8e614 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | ins_comp_get_next_word_or_line | ins_comp_get_next_word_or_line( buf_T * ins_buf , pos_T * cur_match_pos , int * match_len , int * cont_s_ipos) | ['ins_buf', 'cur_match_pos', 'match_len', 'cont_s_ipos'] | ins_comp_get_next_word_or_line(
buf_T *ins_buf, // buffer being scanned
pos_T *cur_match_pos, // current match position
int *match_len,
int *cont_s_ipos) // next ^X<> will set initial_pos
{
char_u *ptr;
int len;
*match_len = 0;
ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, FALSE) +
cur_match_pos->col;
if (ctrl_x_mode_line_or_eval())
{
if (compl_status_adding())
{
if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count)
return NULL;
ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, FALSE);
if (!p_paste)
ptr = skipwhite(ptr);
}
len = (int)STRLEN(ptr);
}
else
{
char_u *tmp_ptr = ptr;
if (compl_status_adding())
{
tmp_ptr += compl_length;
// Skip if already inside a word.
if (vim_iswordp(tmp_ptr))
return NULL;
// Find start of next word.
tmp_ptr = find_word_start(tmp_ptr);
}
// Find end of this word.
tmp_ptr = find_word_end(tmp_ptr);
len = (int)(tmp_ptr - ptr);
if (compl_status_adding() && len == compl_length)
{
if (cur_match_pos->lnum < ins_buf->b_ml.ml_line_count)
{
// Try next line, if any. the new word will be
// "join" as if the normal command "J" was used.
// IOSIZE is always greater than
// compl_length, so the next STRNCPY always
// works -- Acevedo
STRNCPY(IObuff, ptr, len);
ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, FALSE);
tmp_ptr = ptr = skipwhite(ptr);
// Find start of next word.
tmp_ptr = find_word_start(tmp_ptr);
// Find end of next word.
tmp_ptr = find_word_end(tmp_ptr);
if (tmp_ptr > ptr)
{
if (*ptr != ')' && IObuff[len - 1] != TAB)
{
if (IObuff[len - 1] != ' ')
IObuff[len++] = ' ';
// IObuf =~ "\k.* ", thus len >= 2
if (p_js
&& (IObuff[len - 2] == '.'
|| (vim_strchr(p_cpo, CPO_JOINSP)
== NULL
&& (IObuff[len - 2] == '?'
|| IObuff[len - 2] == '!'))))
IObuff[len++] = ' ';
}
// copy as much as possible of the new word
if (tmp_ptr - ptr >= IOSIZE - len)
tmp_ptr = ptr + IOSIZE - len - 1;
STRNCPY(IObuff + len, ptr, tmp_ptr - ptr);
len += (int)(tmp_ptr - ptr);
*cont_s_ipos = TRUE;
}
IObuff[len] = NUL;
ptr = IObuff;
}
if (len == compl_length)
return NULL;
}
}
*match_len = len;
return ptr;
} | 422 | True | 1 |
|
CVE-2022-2581 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://huntr.dev/bounties/0bedbae2-82ae-46ae-aa68-1c28b309b60b', 'name': 'https://huntr.dev/bounties/0bedbae2-82ae-46ae-aa68-1c28b309b60b', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/f50940531dd57135fe60aa393ac9d3281f352d88', 'name': 'https://github.com/vim/vim/commit/f50940531dd57135fe60aa393ac9d3281f352d88', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-125'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0104', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Out-of-bounds Read in GitHub repository vim/vim prior to 9.0.0104.'}] | 2022-08-04T23:30Z | 2022-08-01T15:15Z | Out-of-bounds Read | The software reads data past the end, or before the beginning, of the intended buffer. | Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.
| https://cwe.mitre.org/data/definitions/125.html | 0 | Bram Moolenaar | 2022-07-29 16:22:25+01:00 | patch 9.0.0105: illegal memory access when pattern starts with illegal byte
Problem: Illegal memory access when pattern starts with illegal byte.
Solution: Do not match a character with an illegal byte. | f50940531dd57135fe60aa393ac9d3281f352d88 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | cstrchr | cstrchr( char_u * s , int c) | ['s', 'c'] | cstrchr(char_u *s, int c)
{
char_u *p;
int cc;
if (!rex.reg_ic || (!enc_utf8 && mb_char2len(c) > 1))
return vim_strchr(s, c);
// tolower() and toupper() can be slow, comparing twice should be a lot
// faster (esp. when using MS Visual C++!).
// For UTF-8 need to use folded case.
if (enc_utf8 && c > 0x80)
cc = utf_fold(c);
else
if (MB_ISUPPER(c))
cc = MB_TOLOWER(c);
else if (MB_ISLOWER(c))
cc = MB_TOUPPER(c);
else
return vim_strchr(s, c);
if (has_mbyte)
{
for (p = s; *p != NUL; p += (*mb_ptr2len)(p))
{
if (enc_utf8 && c > 0x80)
{
if (utf_fold(utf_ptr2char(p)) == cc)
return p;
}
else if (*p == c || *p == cc)
return p;
}
}
else
// Faster version for when there are no multi-byte characters.
for (p = s; *p != NUL; ++p)
if (*p == c || *p == cc)
return p;
return NULL;
} | 202 | True | 1 |
CVE-2022-2819 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://huntr.dev/bounties/0a9bd71e-66b8-4eb1-9566-7dfd9b097e59', 'name': 'https://huntr.dev/bounties/0a9bd71e-66b8-4eb1-9566-7dfd9b097e59', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/d1d8f6bacb489036d0fd479c9dd3c0102c988889', 'name': 'https://github.com/vim/vim/commit/d1d8f6bacb489036d0fd479c9dd3c0102c988889', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/CHFAR6OY6G77M6GXCJT75A4KITLNR6GO/', 'name': 'FEDORA-2022-6f5e420e52', 'refsource': 'FEDORA', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0210', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0211.'}] | 2022-08-23T17:15Z | 2022-08-15T11:21Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-08-14 21:28:32+01:00 | patch 9.0.0211: invalid memory access when compiling :lockvar
Problem: Invalid memory access when compiling :lockvar.
Solution: Don't read past the end of the line. | d1d8f6bacb489036d0fd479c9dd3c0102c988889 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | compile_lock_unlock | compile_lock_unlock( lval_T * lvp , char_u * name_end , exarg_T * eap , int deep , void * coookie) | ['lvp', 'name_end', 'eap', 'deep', 'coookie'] | compile_lock_unlock(
lval_T *lvp,
char_u *name_end,
exarg_T *eap,
int deep,
void *coookie)
{
cctx_T *cctx = coookie;
int cc = *name_end;
char_u *p = lvp->ll_name;
int ret = OK;
size_t len;
char_u *buf;
isntype_T isn = ISN_EXEC;
if (cctx->ctx_skip == SKIP_YES)
return OK;
// Cannot use :lockvar and :unlockvar on local variables.
if (p[1] != ':')
{
char_u *end = find_name_end(p, NULL, NULL, FNE_CHECK_START);
if (lookup_local(p, end - p, NULL, cctx) == OK)
{
char_u *s = p;
if (*end != '.' && *end != '[')
{
emsg(_(e_cannot_lock_unlock_local_variable));
return FAIL;
}
// For "d.member" put the local variable on the stack, it will be
// passed to ex_lockvar() indirectly.
if (compile_load(&s, end, cctx, FALSE, FALSE) == FAIL)
return FAIL;
isn = ISN_LOCKUNLOCK;
}
}
// Checking is done at runtime.
*name_end = NUL;
len = name_end - p + 20;
buf = alloc(len);
if (buf == NULL)
ret = FAIL;
else
{
char *cmd = eap->cmdidx == CMD_lockvar ? "lockvar" : "unlockvar";
if (deep < 0)
vim_snprintf((char *)buf, len, "%s! %s", cmd, p);
else
vim_snprintf((char *)buf, len, "%s %d %s", cmd, deep, p);
ret = generate_EXEC_copy(cctx, isn, buf);
vim_free(buf);
*name_end = cc;
}
return ret;
} | 286 | True | 1 |
|
CVE-2022-2817 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/249e1b903a9c0460d618f6dcc59aeb8c03b24b20', 'name': 'https://github.com/vim/vim/commit/249e1b903a9c0460d618f6dcc59aeb8c03b24b20', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/a7b7d242-3d88-4bde-a681-6c986aff886f', 'name': 'https://huntr.dev/bounties/a7b7d242-3d88-4bde-a681-6c986aff886f', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.fedoraproject.org/archives/list/[email protected]/message/CHFAR6OY6G77M6GXCJT75A4KITLNR6GO/', 'name': 'FEDORA-2022-6f5e420e52', 'refsource': 'FEDORA', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0213', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0213.'}] | 2022-08-23T17:15Z | 2022-08-15T23:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-08-14 22:23:02+01:00 | patch 9.0.0213: using freed memory with error in assert argument
Problem: Using freed memory with error in assert argument.
Solution: Make a copy of the error. | 249e1b903a9c0460d618f6dcc59aeb8c03b24b20 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | f_assert_fails | f_assert_fails( typval_T * argvars , typval_T * rettv) | ['argvars', 'rettv'] | f_assert_fails(typval_T *argvars, typval_T *rettv)
{
char_u *cmd;
garray_T ga;
int save_trylevel = trylevel;
int called_emsg_before = called_emsg;
char *wrong_arg_msg = NULL;
if (check_for_string_or_number_arg(argvars, 0) == FAIL
|| check_for_opt_string_or_list_arg(argvars, 1) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN
&& (argvars[2].v_type != VAR_UNKNOWN
&& (check_for_opt_number_arg(argvars, 3) == FAIL
|| (argvars[3].v_type != VAR_UNKNOWN
&& check_for_opt_string_arg(argvars, 4) == FAIL)))))
return;
cmd = tv_get_string_chk(&argvars[0]);
// trylevel must be zero for a ":throw" command to be considered failed
trylevel = 0;
suppress_errthrow = TRUE;
in_assert_fails = TRUE;
do_cmdline_cmd(cmd);
if (called_emsg == called_emsg_before)
{
prepare_assert_error(&ga);
ga_concat(&ga, (char_u *)"command did not fail: ");
assert_append_cmd_or_arg(&ga, argvars, cmd);
assert_error(&ga);
ga_clear(&ga);
rettv->vval.v_number = 1;
}
else if (argvars[1].v_type != VAR_UNKNOWN)
{
char_u buf[NUMBUFLEN];
char_u *expected;
char_u *expected_str = NULL;
int error_found = FALSE;
int error_found_index = 1;
char_u *actual = emsg_assert_fails_msg == NULL ? (char_u *)"[unknown]"
: emsg_assert_fails_msg;
if (argvars[1].v_type == VAR_STRING)
{
expected = tv_get_string_buf_chk(&argvars[1], buf);
error_found = expected == NULL
|| strstr((char *)actual, (char *)expected) == NULL;
}
else if (argvars[1].v_type == VAR_LIST)
{
list_T *list = argvars[1].vval.v_list;
typval_T *tv;
if (list == NULL || list->lv_len < 1 || list->lv_len > 2)
{
wrong_arg_msg = e_assert_fails_second_arg;
goto theend;
}
CHECK_LIST_MATERIALIZE(list);
tv = &list->lv_first->li_tv;
expected = tv_get_string_buf_chk(tv, buf);
if (!pattern_match(expected, actual, FALSE))
{
error_found = TRUE;
expected_str = expected;
}
else if (list->lv_len == 2)
{
tv = &list->lv_u.mat.lv_last->li_tv;
actual = get_vim_var_str(VV_ERRMSG);
expected = tv_get_string_buf_chk(tv, buf);
if (!pattern_match(expected, actual, FALSE))
{
error_found = TRUE;
expected_str = expected;
}
}
}
else
{
wrong_arg_msg = e_assert_fails_second_arg;
goto theend;
}
if (!error_found && argvars[2].v_type != VAR_UNKNOWN
&& argvars[3].v_type != VAR_UNKNOWN)
{
if (argvars[3].v_type != VAR_NUMBER)
{
wrong_arg_msg = e_assert_fails_fourth_argument;
goto theend;
}
else if (argvars[3].vval.v_number >= 0
&& argvars[3].vval.v_number != emsg_assert_fails_lnum)
{
error_found = TRUE;
error_found_index = 3;
}
if (!error_found && argvars[4].v_type != VAR_UNKNOWN)
{
if (argvars[4].v_type != VAR_STRING)
{
wrong_arg_msg = e_assert_fails_fifth_argument;
goto theend;
}
else if (argvars[4].vval.v_string != NULL
&& !pattern_match(argvars[4].vval.v_string,
emsg_assert_fails_context, FALSE))
{
error_found = TRUE;
error_found_index = 4;
}
}
}
if (error_found)
{
typval_T actual_tv;
prepare_assert_error(&ga);
if (error_found_index == 3)
{
actual_tv.v_type = VAR_NUMBER;
actual_tv.vval.v_number = emsg_assert_fails_lnum;
}
else if (error_found_index == 4)
{
actual_tv.v_type = VAR_STRING;
actual_tv.vval.v_string = emsg_assert_fails_context;
}
else
{
actual_tv.v_type = VAR_STRING;
actual_tv.vval.v_string = actual;
}
fill_assert_error(&ga, &argvars[2], expected_str,
&argvars[error_found_index], &actual_tv, ASSERT_OTHER);
ga_concat(&ga, (char_u *)": ");
assert_append_cmd_or_arg(&ga, argvars, cmd);
assert_error(&ga);
ga_clear(&ga);
rettv->vval.v_number = 1;
}
}
theend:
trylevel = save_trylevel;
suppress_errthrow = FALSE;
in_assert_fails = FALSE;
did_emsg = FALSE;
got_int = FALSE;
msg_col = 0;
need_wait_return = FALSE;
emsg_on_display = FALSE;
msg_scrolled = 0;
lines_left = Rows;
VIM_CLEAR(emsg_assert_fails_msg);
set_vim_var_string(VV_ERRMSG, NULL, 0);
if (wrong_arg_msg != NULL)
emsg(_(wrong_arg_msg));
} | 845 | True | 1 |
CVE-2022-2845 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://huntr.dev/bounties/3e1d31ac-1cfd-4a9f-bc5c-213376b69445', 'name': 'https://huntr.dev/bounties/3e1d31ac-1cfd-4a9f-bc5c-213376b69445', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/e98c88c44c308edaea5994b8ad4363e65030968c', 'name': 'https://github.com/vim/vim/commit/e98c88c44c308edaea5994b8ad4363e65030968c', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-126'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0218', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Buffer Over-read in GitHub repository vim/vim prior to 9.0.0218.'}] | 2022-08-19T11:25Z | 2022-08-17T15:15Z | Buffer Over-read | The software reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations after the targeted buffer. | This typically occurs when the pointer or its index is incremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in exposure of sensitive information or possibly a crash.
| https://cwe.mitre.org/data/definitions/126.html | 0 | Bram Moolenaar | 2022-08-16 14:51:53+01:00 | patch 9.0.0218: reading before the start of the line
Problem: Reading before the start of the line.
Solution: When displaying "$" check the column is not negative. | e98c88c44c308edaea5994b8ad4363e65030968c | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | display_dollar | display_dollar( colnr_T col) | ['col'] | display_dollar(colnr_T col)
{
colnr_T save_col;
if (!redrawing())
return;
cursor_off();
save_col = curwin->w_cursor.col;
curwin->w_cursor.col = col;
if (has_mbyte)
{
char_u *p;
// If on the last byte of a multi-byte move to the first byte.
p = ml_get_curline();
curwin->w_cursor.col -= (*mb_head_off)(p, p + col);
}
curs_columns(FALSE); // recompute w_wrow and w_wcol
if (curwin->w_wcol < curwin->w_width)
{
edit_putchar('$', FALSE);
dollar_vcol = curwin->w_virtcol;
}
curwin->w_cursor.col = save_col;
} | 111 | True | 1 |
CVE-2022-2849 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://huntr.dev/bounties/389aeccd-deb9-49ae-9b6a-24c12d79b02e', 'name': 'https://huntr.dev/bounties/389aeccd-deb9-49ae-9b6a-24c12d79b02e', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Issue Tracking', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/f6d39c31d2177549a986d170e192d8351bd571e2', 'name': 'https://github.com/vim/vim/commit/f6d39c31d2177549a986d170e192d8351bd571e2', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0220', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0220.'}] | 2022-08-19T11:25Z | 2022-08-17T18:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-08-16 17:50:38+01:00 | patch 9.0.0220: invalid memory access with for loop over NULL string
Problem: Invalid memory access with for loop over NULL string.
Solution: Make sure mb_ptr2len() consistently returns zero for NUL. | f6d39c31d2177549a986d170e192d8351bd571e2 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | dbcs_ptr2len | dbcs_ptr2len( char_u * p) | ['p'] | dbcs_ptr2len(
char_u *p)
{
int len;
// Check if second byte is not missing.
len = MB_BYTE2LEN(*p);
if (len == 2 && p[1] == NUL)
len = 1;
return len;
} | 39 | True | 1 |
|
CVE-2022-2849 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://huntr.dev/bounties/389aeccd-deb9-49ae-9b6a-24c12d79b02e', 'name': 'https://huntr.dev/bounties/389aeccd-deb9-49ae-9b6a-24c12d79b02e', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Issue Tracking', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/f6d39c31d2177549a986d170e192d8351bd571e2', 'name': 'https://github.com/vim/vim/commit/f6d39c31d2177549a986d170e192d8351bd571e2', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-122'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0220', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Heap-based Buffer Overflow in GitHub repository vim/vim prior to 9.0.0220.'}] | 2022-08-19T11:25Z | 2022-08-17T18:15Z | Heap-based Buffer Overflow | A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). | https://cwe.mitre.org/data/definitions/122.html | 0 | Bram Moolenaar | 2022-08-16 17:50:38+01:00 | patch 9.0.0220: invalid memory access with for loop over NULL string
Problem: Invalid memory access with for loop over NULL string.
Solution: Make sure mb_ptr2len() consistently returns zero for NUL. | f6d39c31d2177549a986d170e192d8351bd571e2 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | latin_ptr2len | latin_ptr2len( char_u * p) | ['p'] | latin_ptr2len(char_u *p)
{
return MB_BYTE2LEN(*p);
} | 15 | True | 1 |
|
CVE-2022-2862 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/1889f499a4f248cd84e0e0bf6d0d820016774494', 'name': 'https://github.com/vim/vim/commit/1889f499a4f248cd84e0e0bf6d0d820016774494', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/71180988-1ab6-4311-bca8-e9a879b06765', 'name': 'https://huntr.dev/bounties/71180988-1ab6-4311-bca8-e9a879b06765', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Issue Tracking', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0221', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0221.'}] | 2022-08-19T11:25Z | 2022-08-17T20:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-08-16 19:34:44+01:00 | patch 9.0.0221: accessing freed memory if compiling nested function fails
Problem: Accessing freed memory if compiling nested function fails.
Solution: Mess up the variable name so that it won't be found. | 1889f499a4f248cd84e0e0bf6d0d820016774494 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | compile_nested_function | compile_nested_function( exarg_T * eap , cctx_T * cctx , garray_T * lines_to_free) | ['eap', 'cctx', 'lines_to_free'] | compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free)
{
int is_global = *eap->arg == 'g' && eap->arg[1] == ':';
char_u *name_start = eap->arg;
char_u *name_end = to_name_end(eap->arg, TRUE);
int off;
char_u *func_name;
char_u *lambda_name;
ufunc_T *ufunc;
int r = FAIL;
compiletype_T compile_type;
isn_T *funcref_isn = NULL;
if (eap->forceit)
{
emsg(_(e_cannot_use_bang_with_nested_def));
return NULL;
}
if (*name_start == '/')
{
name_end = skip_regexp(name_start + 1, '/', TRUE);
if (*name_end == '/')
++name_end;
set_nextcmd(eap, name_end);
}
if (name_end == name_start || *skipwhite(name_end) != '(')
{
if (!ends_excmd2(name_start, name_end))
{
if (*skipwhite(name_end) == '.')
semsg(_(e_cannot_define_dict_func_in_vim9_script_str),
eap->cmd);
else
semsg(_(e_invalid_command_str), eap->cmd);
return NULL;
}
// "def" or "def Name": list functions
if (generate_DEF(cctx, name_start, name_end - name_start) == FAIL)
return NULL;
return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
}
// Only g:Func() can use a namespace.
if (name_start[1] == ':' && !is_global)
{
semsg(_(e_namespace_not_supported_str), name_start);
return NULL;
}
if (cctx->ctx_skip != SKIP_YES
&& check_defined(name_start, name_end - name_start, cctx,
NULL, FALSE) == FAIL)
return NULL;
if (!ASCII_ISUPPER(is_global ? name_start[2] : name_start[0]))
{
semsg(_(e_function_name_must_start_with_capital_str), name_start);
return NULL;
}
eap->arg = name_end;
fill_exarg_from_cctx(eap, cctx);
eap->forceit = FALSE;
// We use the special <Lamba>99 name, but it's not really a lambda.
lambda_name = vim_strsave(get_lambda_name());
if (lambda_name == NULL)
return NULL;
// This may free the current line, make a copy of the name.
off = is_global ? 2 : 0;
func_name = vim_strnsave(name_start + off, name_end - name_start - off);
if (func_name == NULL)
{
r = FAIL;
goto theend;
}
ufunc = define_function(eap, lambda_name, lines_to_free);
if (ufunc == NULL)
{
r = eap->skip ? OK : FAIL;
goto theend;
}
if (eap->nextcmd != NULL)
{
semsg(_(e_text_found_after_str_str),
eap->cmdidx == CMD_def ? "enddef" : "endfunction", eap->nextcmd);
r = FAIL;
func_ptr_unref(ufunc);
goto theend;
}
// copy over the block scope IDs before compiling
if (!is_global && cctx->ctx_ufunc->uf_block_depth > 0)
{
int block_depth = cctx->ctx_ufunc->uf_block_depth;
ufunc->uf_block_ids = ALLOC_MULT(int, block_depth);
if (ufunc->uf_block_ids != NULL)
{
mch_memmove(ufunc->uf_block_ids, cctx->ctx_ufunc->uf_block_ids,
sizeof(int) * block_depth);
ufunc->uf_block_depth = block_depth;
}
}
// Define the funcref before compiling, so that it is found by any
// recursive call.
if (is_global)
{
r = generate_NEWFUNC(cctx, lambda_name, func_name);
func_name = NULL;
lambda_name = NULL;
}
else
{
// Define a local variable for the function reference.
lvar_T *lvar = reserve_local(cctx, func_name, name_end - name_start,
TRUE, ufunc->uf_func_type);
if (lvar == NULL)
goto theend;
if (generate_FUNCREF(cctx, ufunc, &funcref_isn) == FAIL)
goto theend;
r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL);
}
compile_type = get_compile_type(ufunc);
#ifdef FEAT_PROFILE
// If the outer function is profiled, also compile the nested function for
// profiling.
if (cctx->ctx_compile_type == CT_PROFILE)
compile_type = CT_PROFILE;
#endif
if (func_needs_compiling(ufunc, compile_type)
&& compile_def_function(ufunc, TRUE, compile_type, cctx) == FAIL)
{
func_ptr_unref(ufunc);
goto theend;
}
#ifdef FEAT_PROFILE
// When the outer function is compiled for profiling, the nested function
// may be called without profiling. Compile it here in the right context.
if (compile_type == CT_PROFILE && func_needs_compiling(ufunc, CT_NONE))
compile_def_function(ufunc, FALSE, CT_NONE, cctx);
#endif
// If a FUNCREF instruction was generated, set the index after compiling.
if (funcref_isn != NULL && ufunc->uf_def_status == UF_COMPILED)
funcref_isn->isn_arg.funcref.fr_dfunc_idx = ufunc->uf_dfunc_idx;
theend:
vim_free(lambda_name);
vim_free(func_name);
return r == FAIL ? NULL : (char_u *)"";
} | 768 | True | 1 |
CVE-2022-2874 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | nan | [{'url': 'https://github.com/vim/vim/commit/4875d6ab068f09df88d24d81de40dcd8d56e243d', 'name': 'https://github.com/vim/vim/commit/4875d6ab068f09df88d24d81de40dcd8d56e243d', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/95f97dfe-247d-475d-9740-b7adc71f4c79', 'name': 'https://huntr.dev/bounties/95f97dfe-247d-475d-9740-b7adc71f4c79', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0223', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 9.0.0224.'}] | 2022-08-19T11:25Z | 2022-08-18T16:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-08-17 15:55:51+01:00 | patch 9.0.0224: Using NULL pointer when skipping compiled code
Problem: Using NULL pointer when skipping compiled code.
Solution: Check for skipping. | 4875d6ab068f09df88d24d81de40dcd8d56e243d | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | generate_loadvar | generate_loadvar( cctx_T * cctx , assign_dest_T dest , char_u * name , lvar_T * lvar , type_T * type) | ['cctx', 'dest', 'name', 'lvar', 'type'] | generate_loadvar(
cctx_T *cctx,
assign_dest_T dest,
char_u *name,
lvar_T *lvar,
type_T *type)
{
switch (dest)
{
case dest_option:
case dest_func_option:
generate_LOAD(cctx, ISN_LOADOPT, 0, name, type);
break;
case dest_global:
if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
{
if (name[2] == NUL)
generate_instr_type(cctx, ISN_LOADGDICT, &t_dict_any);
else
generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
}
else
generate_LOAD(cctx, ISN_LOADAUTO, 0, name, type);
break;
case dest_buffer:
generate_LOAD(cctx, ISN_LOADB, 0, name + 2, type);
break;
case dest_window:
generate_LOAD(cctx, ISN_LOADW, 0, name + 2, type);
break;
case dest_tab:
generate_LOAD(cctx, ISN_LOADT, 0, name + 2, type);
break;
case dest_script:
compile_load_scriptvar(cctx,
name + (name[1] == ':' ? 2 : 0), NULL, NULL);
break;
case dest_env:
// Include $ in the name here
generate_LOAD(cctx, ISN_LOADENV, 0, name, type);
break;
case dest_reg:
generate_LOAD(cctx, ISN_LOADREG, name[1], NULL, &t_string);
break;
case dest_vimvar:
generate_LOADV(cctx, name + 2);
break;
case dest_local:
if (lvar->lv_from_outer > 0)
generate_LOADOUTER(cctx, lvar->lv_idx, lvar->lv_from_outer,
type);
else
generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type);
break;
case dest_expr:
// list or dict value should already be on the stack.
break;
}
} | 309 | True | 1 |
CVE-2022-2889 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'name': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'name': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}, {'lang': 'en', 'value': 'CWE-416'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0225', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0225.'}] | 2022-08-19T18:45Z | 2022-08-19T13:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-08-18 13:28:31+01:00 | patch 9.0.0225: using freed memory with multiple line breaks in expression
Problem: Using freed memory with multiple line breaks in expression.
Solution: Free eval_tofree later. | 91c7cbfe31bbef57d5fcf7d76989fc159f73ef15 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | clear_evalarg | clear_evalarg( evalarg_T * evalarg , exarg_T * eap) | ['evalarg', 'eap'] | clear_evalarg(evalarg_T *evalarg, exarg_T *eap)
{
if (evalarg != NULL)
{
if (evalarg->eval_tofree != NULL)
{
if (eap != NULL)
{
// We may need to keep the original command line, e.g. for
// ":let" it has the variable names. But we may also need the
// new one, "nextcmd" points into it. Keep both.
vim_free(eap->cmdline_tofree);
eap->cmdline_tofree = *eap->cmdlinep;
*eap->cmdlinep = evalarg->eval_tofree;
}
else
vim_free(evalarg->eval_tofree);
evalarg->eval_tofree = NULL;
}
ga_clear_strings(&evalarg->eval_tofree_ga);
VIM_CLEAR(evalarg->eval_tofree_lambda);
}
} | 92 | True | 1 |
CVE-2022-2889 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'name': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'name': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}, {'lang': 'en', 'value': 'CWE-416'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0225', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0225.'}] | 2022-08-19T18:45Z | 2022-08-19T13:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-08-18 13:28:31+01:00 | patch 9.0.0225: using freed memory with multiple line breaks in expression
Problem: Using freed memory with multiple line breaks in expression.
Solution: Free eval_tofree later. | 91c7cbfe31bbef57d5fcf7d76989fc159f73ef15 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | eval_next_line | eval_next_line( char_u * arg , evalarg_T * evalarg) | ['arg', 'evalarg'] | eval_next_line(char_u *arg, evalarg_T *evalarg)
{
garray_T *gap = &evalarg->eval_ga;
char_u *line;
if (arg != NULL)
{
if (*arg == NL)
return newline_skip_comments(arg);
// Truncate before a trailing comment, so that concatenating the lines
// won't turn the rest into a comment.
if (*skipwhite(arg) == '#')
*arg = NUL;
}
if (evalarg->eval_cookie != NULL)
line = evalarg->eval_getline(0, evalarg->eval_cookie, 0,
GETLINE_CONCAT_ALL);
else
line = next_line_from_context(evalarg->eval_cctx, TRUE);
if (line == NULL)
return NULL;
++evalarg->eval_break_count;
if (gap->ga_itemsize > 0 && ga_grow(gap, 1) == OK)
{
char_u *p = skipwhite(line);
// Going to concatenate the lines after parsing. For an empty or
// comment line use an empty string.
if (*p == NUL || vim9_comment_start(p))
{
vim_free(line);
line = vim_strsave((char_u *)"");
}
((char_u **)gap->ga_data)[gap->ga_len] = line;
++gap->ga_len;
}
else if (evalarg->eval_cookie != NULL)
{
vim_free(evalarg->eval_tofree);
evalarg->eval_tofree = line;
}
// Advanced to the next line, "arg" no longer points into the previous
// line.
evalarg->eval_using_cmdline = FALSE;
return skipwhite(line);
} | 228 | True | 1 |
CVE-2022-2889 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'name': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'name': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}, {'lang': 'en', 'value': 'CWE-416'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0225', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0225.'}] | 2022-08-19T18:45Z | 2022-08-19T13:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-08-18 13:28:31+01:00 | patch 9.0.0225: using freed memory with multiple line breaks in expression
Problem: Using freed memory with multiple line breaks in expression.
Solution: Free eval_tofree later. | 91c7cbfe31bbef57d5fcf7d76989fc159f73ef15 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | init_evalarg | init_evalarg( evalarg_T * evalarg) | ['evalarg'] | init_evalarg(evalarg_T *evalarg)
{
CLEAR_POINTER(evalarg);
ga_init2(&evalarg->eval_tofree_ga, sizeof(char_u *), 20);
} | 29 | True | 1 |
CVE-2022-2889 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'name': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'name': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}, {'lang': 'en', 'value': 'CWE-416'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0225', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0225.'}] | 2022-08-19T18:45Z | 2022-08-19T13:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-08-18 13:28:31+01:00 | patch 9.0.0225: using freed memory with multiple line breaks in expression
Problem: Using freed memory with multiple line breaks in expression.
Solution: Free eval_tofree later. | 91c7cbfe31bbef57d5fcf7d76989fc159f73ef15 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | skip_expr_concatenate | skip_expr_concatenate( char_u ** arg , char_u ** start , char_u ** end , evalarg_T * evalarg) | ['arg', 'start', 'end', 'evalarg'] | skip_expr_concatenate(
char_u **arg,
char_u **start,
char_u **end,
evalarg_T *evalarg)
{
typval_T rettv;
int res;
int vim9script = in_vim9script();
garray_T *gap = evalarg == NULL ? NULL : &evalarg->eval_ga;
garray_T *freegap = evalarg == NULL ? NULL : &evalarg->eval_freega;
int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
int evaluate = evalarg == NULL
? FALSE : (evalarg->eval_flags & EVAL_EVALUATE);
if (vim9script && evaluate
&& (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL))
{
ga_init2(gap, sizeof(char_u *), 10);
// leave room for "start"
if (ga_grow(gap, 1) == OK)
++gap->ga_len;
ga_init2(freegap, sizeof(char_u *), 10);
}
*start = *arg;
// Don't evaluate the expression.
if (evalarg != NULL)
evalarg->eval_flags &= ~EVAL_EVALUATE;
*arg = skipwhite(*arg);
res = eval1(arg, &rettv, evalarg);
*end = *arg;
if (evalarg != NULL)
evalarg->eval_flags = save_flags;
if (vim9script && evaluate
&& (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL))
{
if (evalarg->eval_ga.ga_len == 1)
{
// just the one line, no need to concatenate
ga_clear(gap);
gap->ga_itemsize = 0;
}
else
{
char_u *p;
size_t endoff = STRLEN(*arg);
// Line breaks encountered, concatenate all the lines.
*((char_u **)gap->ga_data) = *start;
p = ga_concat_strings(gap, " ");
// free the lines only when using getsourceline()
if (evalarg->eval_cookie != NULL)
{
// Do not free the first line, the caller can still use it.
*((char_u **)gap->ga_data) = NULL;
// Do not free the last line, "arg" points into it, free it
// later.
vim_free(evalarg->eval_tofree);
evalarg->eval_tofree =
((char_u **)gap->ga_data)[gap->ga_len - 1];
((char_u **)gap->ga_data)[gap->ga_len - 1] = NULL;
ga_clear_strings(gap);
}
else
{
ga_clear(gap);
// free lines that were explicitly marked for freeing
ga_clear_strings(freegap);
}
gap->ga_itemsize = 0;
if (p == NULL)
return FAIL;
*start = p;
vim_free(evalarg->eval_tofree_lambda);
evalarg->eval_tofree_lambda = p;
// Compute "end" relative to the end.
*end = *start + STRLEN(*start) - endoff;
}
}
return res;
} | 436 | True | 1 |
CVE-2022-2889 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'name': 'https://github.com/vim/vim/commit/91c7cbfe31bbef57d5fcf7d76989fc159f73ef15', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'name': 'https://huntr.dev/bounties/d1ac9817-825d-49ce-b514-1d5b12b6bdaa', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}, {'lang': 'en', 'value': 'CWE-416'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0225', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0225.'}] | 2022-08-19T18:45Z | 2022-08-19T13:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-08-18 13:28:31+01:00 | patch 9.0.0225: using freed memory with multiple line breaks in expression
Problem: Using freed memory with multiple line breaks in expression.
Solution: Free eval_tofree later. | 91c7cbfe31bbef57d5fcf7d76989fc159f73ef15 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | get_lambda_tv | get_lambda_tv( char_u ** arg , typval_T * rettv , int types_optional , evalarg_T * evalarg) | ['arg', 'rettv', 'types_optional', 'evalarg'] | get_lambda_tv(
char_u **arg,
typval_T *rettv,
int types_optional,
evalarg_T *evalarg)
{
int evaluate = evalarg != NULL
&& (evalarg->eval_flags & EVAL_EVALUATE);
garray_T newargs;
garray_T newlines;
garray_T *pnewargs;
garray_T argtypes;
garray_T default_args;
ufunc_T *fp = NULL;
partial_T *pt = NULL;
int varargs;
char_u *ret_type = NULL;
int ret;
char_u *s;
char_u *start, *end;
int *old_eval_lavars = eval_lavars_used;
int eval_lavars = FALSE;
char_u *tofree1 = NULL;
char_u *tofree2 = NULL;
int equal_arrow = **arg == '(';
int white_error = FALSE;
int called_emsg_start = called_emsg;
int vim9script = in_vim9script();
long start_lnum = SOURCING_LNUM;
if (equal_arrow && !vim9script)
return NOTDONE;
ga_init(&newargs);
ga_init(&newlines);
// First, check if this is really a lambda expression. "->" or "=>" must
// be found after the arguments.
s = *arg + 1;
ret = get_function_args(&s, equal_arrow ? ')' : '-', NULL,
types_optional ? &argtypes : NULL, types_optional, evalarg,
NULL, &default_args, TRUE, NULL, NULL);
if (ret == FAIL || skip_arrow(s, equal_arrow, &ret_type, NULL) == NULL)
{
if (types_optional)
ga_clear_strings(&argtypes);
return called_emsg == called_emsg_start ? NOTDONE : FAIL;
}
// Parse the arguments for real.
if (evaluate)
pnewargs = &newargs;
else
pnewargs = NULL;
*arg += 1;
ret = get_function_args(arg, equal_arrow ? ')' : '-', pnewargs,
types_optional ? &argtypes : NULL, types_optional, evalarg,
&varargs, &default_args,
FALSE, NULL, NULL);
if (ret == FAIL
|| (s = skip_arrow(*arg, equal_arrow, &ret_type,
equal_arrow || vim9script ? &white_error : NULL)) == NULL)
{
if (types_optional)
ga_clear_strings(&argtypes);
ga_clear_strings(&newargs);
return white_error ? FAIL : NOTDONE;
}
*arg = s;
// Skipping over linebreaks may make "ret_type" invalid, make a copy.
if (ret_type != NULL)
{
ret_type = vim_strsave(ret_type);
tofree2 = ret_type;
}
// Set up a flag for checking local variables and arguments.
if (evaluate)
eval_lavars_used = &eval_lavars;
*arg = skipwhite_and_linebreak(*arg, evalarg);
// Recognize "{" as the start of a function body.
if (equal_arrow && **arg == '{')
{
if (evalarg == NULL)
// cannot happen?
goto theend;
SOURCING_LNUM = start_lnum; // used for where lambda is defined
if (lambda_function_body(arg, rettv, evalarg, pnewargs,
types_optional ? &argtypes : NULL, varargs,
&default_args, ret_type) == FAIL)
goto errret;
goto theend;
}
if (default_args.ga_len > 0)
{
emsg(_(e_cannot_use_default_values_in_lambda));
goto errret;
}
// Get the start and the end of the expression.
start = *arg;
ret = skip_expr_concatenate(arg, &start, &end, evalarg);
if (ret == FAIL)
goto errret;
if (evalarg != NULL)
{
// avoid that the expression gets freed when another line break follows
tofree1 = evalarg->eval_tofree;
evalarg->eval_tofree = NULL;
}
if (!equal_arrow)
{
*arg = skipwhite_and_linebreak(*arg, evalarg);
if (**arg != '}')
{
semsg(_(e_expected_right_curly_str), *arg);
goto errret;
}
++*arg;
}
if (evaluate)
{
int len;
int flags = FC_LAMBDA;
char_u *p;
char_u *line_end;
char_u *name = get_lambda_name();
fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
if (fp == NULL)
goto errret;
fp->uf_def_status = UF_NOT_COMPILED;
pt = ALLOC_CLEAR_ONE(partial_T);
if (pt == NULL)
goto errret;
ga_init2(&newlines, sizeof(char_u *), 1);
if (ga_grow(&newlines, 1) == FAIL)
goto errret;
// If there are line breaks, we need to split up the string.
line_end = vim_strchr(start, '\n');
if (line_end == NULL || line_end > end)
line_end = end;
// Add "return " before the expression (or the first line).
len = 7 + (int)(line_end - start) + 1;
p = alloc(len);
if (p == NULL)
goto errret;
((char_u **)(newlines.ga_data))[newlines.ga_len++] = p;
STRCPY(p, "return ");
vim_strncpy(p + 7, start, line_end - start);
if (line_end != end)
{
// Add more lines, split by line breaks. Thus is used when a
// lambda with { cmds } is encountered.
while (*line_end == '\n')
{
if (ga_grow(&newlines, 1) == FAIL)
goto errret;
start = line_end + 1;
line_end = vim_strchr(start, '\n');
if (line_end == NULL)
line_end = end;
((char_u **)(newlines.ga_data))[newlines.ga_len++] =
vim_strnsave(start, line_end - start);
}
}
if (strstr((char *)p + 7, "a:") == NULL)
// No a: variables are used for sure.
flags |= FC_NOARGS;
fp->uf_refcount = 1;
set_ufunc_name(fp, name);
fp->uf_args = newargs;
ga_init(&fp->uf_def_args);
if (types_optional)
{
if (parse_argument_types(fp, &argtypes,
vim9script && varargs) == FAIL)
goto errret;
if (ret_type != NULL)
{
fp->uf_ret_type = parse_type(&ret_type,
&fp->uf_type_list, TRUE);
if (fp->uf_ret_type == NULL)
goto errret;
}
else
fp->uf_ret_type = &t_unknown;
}
fp->uf_lines = newlines;
if (current_funccal != NULL && eval_lavars)
{
flags |= FC_CLOSURE;
if (register_closure(fp) == FAIL)
goto errret;
}
#ifdef FEAT_PROFILE
if (prof_def_func())
func_do_profile(fp);
#endif
if (sandbox)
flags |= FC_SANDBOX;
// In legacy script a lambda can be called with more args than
// uf_args.ga_len. In Vim9 script "...name" has to be used.
fp->uf_varargs = !vim9script || varargs;
fp->uf_flags = flags;
fp->uf_calls = 0;
fp->uf_script_ctx = current_sctx;
// Use the line number of the arguments.
fp->uf_script_ctx.sc_lnum += start_lnum;
function_using_block_scopes(fp, evalarg->eval_cstack);
pt->pt_func = fp;
pt->pt_refcount = 1;
rettv->vval.v_partial = pt;
rettv->v_type = VAR_PARTIAL;
hash_add(&func_hashtab, UF2HIKEY(fp));
}
theend:
eval_lavars_used = old_eval_lavars;
if (evalarg != NULL && evalarg->eval_tofree == NULL)
evalarg->eval_tofree = tofree1;
else
vim_free(tofree1);
vim_free(tofree2);
if (types_optional)
ga_clear_strings(&argtypes);
return OK;
errret:
ga_clear_strings(&newargs);
ga_clear_strings(&newlines);
ga_clear_strings(&default_args);
if (types_optional)
{
ga_clear_strings(&argtypes);
if (fp != NULL)
vim_free(fp->uf_arg_types);
}
vim_free(fp);
vim_free(pt);
if (evalarg != NULL && evalarg->eval_tofree == NULL)
evalarg->eval_tofree = tofree1;
else
vim_free(tofree1);
vim_free(tofree2);
eval_lavars_used = old_eval_lavars;
return FAIL;
} | 1253 | True | 1 |
CVE-2022-2946 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://huntr.dev/bounties/5d389a18-5026-47df-a5d0-1548a9b555d5', 'name': 'https://huntr.dev/bounties/5d389a18-5026-47df-a5d0-1548a9b555d5', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/adce965162dd89bf29ee0e5baf53652e7515762c', 'name': 'https://github.com/vim/vim/commit/adce965162dd89bf29ee0e5baf53652e7515762c', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0246', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Use After Free in GitHub repository vim/vim prior to 9.0.0246.'}] | 2022-08-25T02:56Z | 2022-08-23T17:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2022-08-22 16:35:45+01:00 | patch 9.0.0246: using freed memory when 'tagfunc' deletes the buffer
Problem: Using freed memory when 'tagfunc' deletes the buffer.
Solution: Make a copy of the tag name. | adce965162dd89bf29ee0e5baf53652e7515762c | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | do_tag | do_tag( char_u * tag , int type , int count , int forceit , int verbose) | ['tag', 'type', 'count', 'forceit', 'verbose'] | do_tag(
char_u *tag, // tag (pattern) to jump to
int type,
int count,
int forceit, // :ta with !
int verbose) // print "tag not found" message
{
taggy_T *tagstack = curwin->w_tagstack;
int tagstackidx = curwin->w_tagstackidx;
int tagstacklen = curwin->w_tagstacklen;
int cur_match = 0;
int cur_fnum = curbuf->b_fnum;
int oldtagstackidx = tagstackidx;
int prevtagstackidx = tagstackidx;
int prev_num_matches;
int new_tag = FALSE;
int i;
int ic;
int no_regexp = FALSE;
int error_cur_match = 0;
int save_pos = FALSE;
fmark_T saved_fmark;
#ifdef FEAT_CSCOPE
int jumped_to_tag = FALSE;
#endif
int new_num_matches;
char_u **new_matches;
int use_tagstack;
int skip_msg = FALSE;
char_u *buf_ffname = curbuf->b_ffname; // name to use for
// priority computation
int use_tfu = 1;
// remember the matches for the last used tag
static int num_matches = 0;
static int max_num_matches = 0; // limit used for match search
static char_u **matches = NULL;
static int flags;
#ifdef FEAT_EVAL
if (tfu_in_use)
{
emsg(_(e_cannot_modify_tag_stack_within_tagfunc));
return FALSE;
}
#endif
#ifdef EXITFREE
if (type == DT_FREE)
{
// remove the list of matches
FreeWild(num_matches, matches);
# ifdef FEAT_CSCOPE
cs_free_tags();
# endif
num_matches = 0;
return FALSE;
}
#endif
if (type == DT_HELP)
{
type = DT_TAG;
no_regexp = TRUE;
use_tfu = 0;
}
prev_num_matches = num_matches;
free_string_option(nofile_fname);
nofile_fname = NULL;
CLEAR_POS(&saved_fmark.mark); // shutup gcc 4.0
saved_fmark.fnum = 0;
/*
* Don't add a tag to the tagstack if 'tagstack' has been reset.
*/
if ((!p_tgst && *tag != NUL))
{
use_tagstack = FALSE;
new_tag = TRUE;
#if defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
tagstack_clear_entry(&ptag_entry);
if ((ptag_entry.tagname = vim_strsave(tag)) == NULL)
goto end_do_tag;
}
#endif
}
else
{
#if defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
use_tagstack = FALSE;
else
#endif
use_tagstack = TRUE;
// new pattern, add to the tag stack
if (*tag != NUL
&& (type == DT_TAG || type == DT_SELECT || type == DT_JUMP
#ifdef FEAT_QUICKFIX
|| type == DT_LTAG
#endif
#ifdef FEAT_CSCOPE
|| type == DT_CSCOPE
#endif
))
{
#if defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
if (ptag_entry.tagname != NULL
&& STRCMP(ptag_entry.tagname, tag) == 0)
{
// Jumping to same tag: keep the current match, so that
// the CursorHold autocommand example works.
cur_match = ptag_entry.cur_match;
cur_fnum = ptag_entry.cur_fnum;
}
else
{
tagstack_clear_entry(&ptag_entry);
if ((ptag_entry.tagname = vim_strsave(tag)) == NULL)
goto end_do_tag;
}
}
else
#endif
{
/*
* If the last used entry is not at the top, delete all tag
* stack entries above it.
*/
while (tagstackidx < tagstacklen)
tagstack_clear_entry(&tagstack[--tagstacklen]);
// if the tagstack is full: remove oldest entry
if (++tagstacklen > TAGSTACKSIZE)
{
tagstacklen = TAGSTACKSIZE;
tagstack_clear_entry(&tagstack[0]);
for (i = 1; i < tagstacklen; ++i)
tagstack[i - 1] = tagstack[i];
--tagstackidx;
}
/*
* put the tag name in the tag stack
*/
if ((tagstack[tagstackidx].tagname = vim_strsave(tag)) == NULL)
{
curwin->w_tagstacklen = tagstacklen - 1;
goto end_do_tag;
}
curwin->w_tagstacklen = tagstacklen;
save_pos = TRUE; // save the cursor position below
}
new_tag = TRUE;
}
else
{
if (
#if defined(FEAT_QUICKFIX)
g_do_tagpreview != 0 ? ptag_entry.tagname == NULL :
#endif
tagstacklen == 0)
{
// empty stack
emsg(_(e_tag_stack_empty));
goto end_do_tag;
}
if (type == DT_POP) // go to older position
{
#ifdef FEAT_FOLDING
int old_KeyTyped = KeyTyped;
#endif
if ((tagstackidx -= count) < 0)
{
emsg(_(e_at_bottom_of_tag_stack));
if (tagstackidx + count == 0)
{
// We did [num]^T from the bottom of the stack
tagstackidx = 0;
goto end_do_tag;
}
// We weren't at the bottom of the stack, so jump all the
// way to the bottom now.
tagstackidx = 0;
}
else if (tagstackidx >= tagstacklen) // count == 0?
{
emsg(_(e_at_top_of_tag_stack));
goto end_do_tag;
}
// Make a copy of the fmark, autocommands may invalidate the
// tagstack before it's used.
saved_fmark = tagstack[tagstackidx].fmark;
if (saved_fmark.fnum != curbuf->b_fnum)
{
/*
* Jump to other file. If this fails (e.g. because the
* file was changed) keep original position in tag stack.
*/
if (buflist_getfile(saved_fmark.fnum, saved_fmark.mark.lnum,
GETF_SETMARK, forceit) == FAIL)
{
tagstackidx = oldtagstackidx; // back to old posn
goto end_do_tag;
}
// An BufReadPost autocommand may jump to the '" mark, but
// we don't what that here.
curwin->w_cursor.lnum = saved_fmark.mark.lnum;
}
else
{
setpcmark();
curwin->w_cursor.lnum = saved_fmark.mark.lnum;
}
curwin->w_cursor.col = saved_fmark.mark.col;
curwin->w_set_curswant = TRUE;
check_cursor();
#ifdef FEAT_FOLDING
if ((fdo_flags & FDO_TAG) && old_KeyTyped)
foldOpenCursor();
#endif
// remove the old list of matches
FreeWild(num_matches, matches);
#ifdef FEAT_CSCOPE
cs_free_tags();
#endif
num_matches = 0;
tag_freematch();
goto end_do_tag;
}
if (type == DT_TAG
#if defined(FEAT_QUICKFIX)
|| type == DT_LTAG
#endif
)
{
#if defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
cur_match = ptag_entry.cur_match;
cur_fnum = ptag_entry.cur_fnum;
}
else
#endif
{
// ":tag" (no argument): go to newer pattern
save_pos = TRUE; // save the cursor position below
if ((tagstackidx += count - 1) >= tagstacklen)
{
/*
* Beyond the last one, just give an error message and
* go to the last one. Don't store the cursor
* position.
*/
tagstackidx = tagstacklen - 1;
emsg(_(e_at_top_of_tag_stack));
save_pos = FALSE;
}
else if (tagstackidx < 0) // must have been count == 0
{
emsg(_(e_at_bottom_of_tag_stack));
tagstackidx = 0;
goto end_do_tag;
}
cur_match = tagstack[tagstackidx].cur_match;
cur_fnum = tagstack[tagstackidx].cur_fnum;
}
new_tag = TRUE;
}
else // go to other matching tag
{
// Save index for when selection is cancelled.
prevtagstackidx = tagstackidx;
#if defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
cur_match = ptag_entry.cur_match;
cur_fnum = ptag_entry.cur_fnum;
}
else
#endif
{
if (--tagstackidx < 0)
tagstackidx = 0;
cur_match = tagstack[tagstackidx].cur_match;
cur_fnum = tagstack[tagstackidx].cur_fnum;
}
switch (type)
{
case DT_FIRST: cur_match = count - 1; break;
case DT_SELECT:
case DT_JUMP:
#ifdef FEAT_CSCOPE
case DT_CSCOPE:
#endif
case DT_LAST: cur_match = MAXCOL - 1; break;
case DT_NEXT: cur_match += count; break;
case DT_PREV: cur_match -= count; break;
}
if (cur_match >= MAXCOL)
cur_match = MAXCOL - 1;
else if (cur_match < 0)
{
emsg(_(e_cannot_go_before_first_matching_tag));
skip_msg = TRUE;
cur_match = 0;
cur_fnum = curbuf->b_fnum;
}
}
}
#if defined(FEAT_QUICKFIX)
if (g_do_tagpreview != 0)
{
if (type != DT_SELECT && type != DT_JUMP)
{
ptag_entry.cur_match = cur_match;
ptag_entry.cur_fnum = cur_fnum;
}
}
else
#endif
{
/*
* For ":tag [arg]" or ":tselect" remember position before the jump.
*/
saved_fmark = tagstack[tagstackidx].fmark;
if (save_pos)
{
tagstack[tagstackidx].fmark.mark = curwin->w_cursor;
tagstack[tagstackidx].fmark.fnum = curbuf->b_fnum;
}
// Curwin will change in the call to jumpto_tag() if ":stag" was
// used or an autocommand jumps to another window; store value of
// tagstackidx now.
curwin->w_tagstackidx = tagstackidx;
if (type != DT_SELECT && type != DT_JUMP)
{
curwin->w_tagstack[tagstackidx].cur_match = cur_match;
curwin->w_tagstack[tagstackidx].cur_fnum = cur_fnum;
}
}
}
// When not using the current buffer get the name of buffer "cur_fnum".
// Makes sure that the tag order doesn't change when using a remembered
// position for "cur_match".
if (cur_fnum != curbuf->b_fnum)
{
buf_T *buf = buflist_findnr(cur_fnum);
if (buf != NULL)
buf_ffname = buf->b_ffname;
}
/*
* Repeat searching for tags, when a file has not been found.
*/
for (;;)
{
int other_name;
char_u *name;
/*
* When desired match not found yet, try to find it (and others).
*/
if (use_tagstack)
name = tagstack[tagstackidx].tagname;
#if defined(FEAT_QUICKFIX)
else if (g_do_tagpreview != 0)
name = ptag_entry.tagname;
#endif
else
name = tag;
other_name = (tagmatchname == NULL || STRCMP(tagmatchname, name) != 0);
if (new_tag
|| (cur_match >= num_matches && max_num_matches != MAXCOL)
|| other_name)
{
if (other_name)
{
vim_free(tagmatchname);
tagmatchname = vim_strsave(name);
}
if (type == DT_SELECT || type == DT_JUMP
#if defined(FEAT_QUICKFIX)
|| type == DT_LTAG
#endif
)
cur_match = MAXCOL - 1;
if (type == DT_TAG)
max_num_matches = MAXCOL;
else
max_num_matches = cur_match + 1;
// when the argument starts with '/', use it as a regexp
if (!no_regexp && *name == '/')
{
flags = TAG_REGEXP;
++name;
}
else
flags = TAG_NOIC;
#ifdef FEAT_CSCOPE
if (type == DT_CSCOPE)
flags = TAG_CSCOPE;
#endif
if (verbose)
flags |= TAG_VERBOSE;
if (!use_tfu)
flags |= TAG_NO_TAGFUNC;
if (find_tags(name, &new_num_matches, &new_matches, flags,
max_num_matches, buf_ffname) == OK
&& new_num_matches < max_num_matches)
max_num_matches = MAXCOL; // If less than max_num_matches
// found: all matches found.
// If there already were some matches for the same name, move them
// to the start. Avoids that the order changes when using
// ":tnext" and jumping to another file.
if (!new_tag && !other_name)
{
int j, k;
int idx = 0;
tagptrs_T tagp, tagp2;
// Find the position of each old match in the new list. Need
// to use parse_match() to find the tag line.
for (j = 0; j < num_matches; ++j)
{
parse_match(matches[j], &tagp);
for (i = idx; i < new_num_matches; ++i)
{
parse_match(new_matches[i], &tagp2);
if (STRCMP(tagp.tagname, tagp2.tagname) == 0)
{
char_u *p = new_matches[i];
for (k = i; k > idx; --k)
new_matches[k] = new_matches[k - 1];
new_matches[idx++] = p;
break;
}
}
}
}
FreeWild(num_matches, matches);
num_matches = new_num_matches;
matches = new_matches;
}
if (num_matches <= 0)
{
if (verbose)
semsg(_(e_tag_not_found_str), name);
#if defined(FEAT_QUICKFIX)
g_do_tagpreview = 0;
#endif
}
else
{
int ask_for_selection = FALSE;
#ifdef FEAT_CSCOPE
if (type == DT_CSCOPE && num_matches > 1)
{
cs_print_tags();
ask_for_selection = TRUE;
}
else
#endif
if (type == DT_TAG && *tag != NUL)
// If a count is supplied to the ":tag <name>" command, then
// jump to count'th matching tag.
cur_match = count > 0 ? count - 1 : 0;
else if (type == DT_SELECT || (type == DT_JUMP && num_matches > 1))
{
print_tag_list(new_tag, use_tagstack, num_matches, matches);
ask_for_selection = TRUE;
}
#if defined(FEAT_QUICKFIX) && defined(FEAT_EVAL)
else if (type == DT_LTAG)
{
if (add_llist_tags(tag, num_matches, matches) == FAIL)
goto end_do_tag;
cur_match = 0; // Jump to the first tag
}
#endif
if (ask_for_selection == TRUE)
{
/*
* Ask to select a tag from the list.
*/
i = prompt_for_number(NULL);
if (i <= 0 || i > num_matches || got_int)
{
// no valid choice: don't change anything
if (use_tagstack)
{
tagstack[tagstackidx].fmark = saved_fmark;
tagstackidx = prevtagstackidx;
}
#ifdef FEAT_CSCOPE
cs_free_tags();
jumped_to_tag = TRUE;
#endif
break;
}
cur_match = i - 1;
}
if (cur_match >= num_matches)
{
// Avoid giving this error when a file wasn't found and we're
// looking for a match in another file, which wasn't found.
// There will be an emsg("file doesn't exist") below then.
if ((type == DT_NEXT || type == DT_FIRST)
&& nofile_fname == NULL)
{
if (num_matches == 1)
emsg(_(e_there_is_only_one_matching_tag));
else
emsg(_(e_cannot_go_beyond_last_matching_tag));
skip_msg = TRUE;
}
cur_match = num_matches - 1;
}
if (use_tagstack)
{
tagptrs_T tagp;
tagstack[tagstackidx].cur_match = cur_match;
tagstack[tagstackidx].cur_fnum = cur_fnum;
// store user-provided data originating from tagfunc
if (use_tfu && parse_match(matches[cur_match], &tagp) == OK
&& tagp.user_data)
{
VIM_CLEAR(tagstack[tagstackidx].user_data);
tagstack[tagstackidx].user_data = vim_strnsave(
tagp.user_data, tagp.user_data_end - tagp.user_data);
}
++tagstackidx;
}
#if defined(FEAT_QUICKFIX)
else if (g_do_tagpreview != 0)
{
ptag_entry.cur_match = cur_match;
ptag_entry.cur_fnum = cur_fnum;
}
#endif
/*
* Only when going to try the next match, report that the previous
* file didn't exist. Otherwise an emsg() is given below.
*/
if (nofile_fname != NULL && error_cur_match != cur_match)
smsg(_("File \"%s\" does not exist"), nofile_fname);
ic = (matches[cur_match][0] & MT_IC_OFF);
if (type != DT_TAG && type != DT_SELECT && type != DT_JUMP
#ifdef FEAT_CSCOPE
&& type != DT_CSCOPE
#endif
&& (num_matches > 1 || ic)
&& !skip_msg)
{
// Give an indication of the number of matching tags
sprintf((char *)IObuff, _("tag %d of %d%s"),
cur_match + 1,
num_matches,
max_num_matches != MAXCOL ? _(" or more") : "");
if (ic)
STRCAT(IObuff, _(" Using tag with different case!"));
if ((num_matches > prev_num_matches || new_tag)
&& num_matches > 1)
{
if (ic)
msg_attr((char *)IObuff, HL_ATTR(HLF_W));
else
msg((char *)IObuff);
msg_scroll = TRUE; // don't overwrite this message
}
else
give_warning(IObuff, ic);
if (ic && !msg_scrolled && msg_silent == 0)
{
out_flush();
ui_delay(1007L, TRUE);
}
}
#if defined(FEAT_EVAL)
// Let the SwapExists event know what tag we are jumping to.
vim_snprintf((char *)IObuff, IOSIZE, ":ta %s\r", name);
set_vim_var_string(VV_SWAPCOMMAND, IObuff, -1);
#endif
/*
* Jump to the desired match.
*/
i = jumpto_tag(matches[cur_match], forceit, type != DT_CSCOPE);
#if defined(FEAT_EVAL)
set_vim_var_string(VV_SWAPCOMMAND, NULL, -1);
#endif
if (i == NOTAGFILE)
{
// File not found: try again with another matching tag
if ((type == DT_PREV && cur_match > 0)
|| ((type == DT_TAG || type == DT_NEXT
|| type == DT_FIRST)
&& (max_num_matches != MAXCOL
|| cur_match < num_matches - 1)))
{
error_cur_match = cur_match;
if (use_tagstack)
--tagstackidx;
if (type == DT_PREV)
--cur_match;
else
{
type = DT_NEXT;
++cur_match;
}
continue;
}
semsg(_(e_file_str_does_not_exist), nofile_fname);
}
else
{
// We may have jumped to another window, check that
// tagstackidx is still valid.
if (use_tagstack && tagstackidx > curwin->w_tagstacklen)
tagstackidx = curwin->w_tagstackidx;
#ifdef FEAT_CSCOPE
jumped_to_tag = TRUE;
#endif
}
}
break;
}
end_do_tag:
// Only store the new index when using the tagstack and it's valid.
if (use_tagstack && tagstackidx <= curwin->w_tagstacklen)
curwin->w_tagstackidx = tagstackidx;
postponed_split = 0; // don't split next time
# ifdef FEAT_QUICKFIX
g_do_tagpreview = 0; // don't do tag preview next time
# endif
#ifdef FEAT_CSCOPE
return jumped_to_tag;
#else
return FALSE;
#endif
} | 2322 | True | 1 |
CVE-2022-2980 | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | NONE | NONE | HIGH | 5.5 | MEDIUM | 1.8 | 3.6 | nan | [{'url': 'https://github.com/vim/vim/commit/80525751c5ce9ed82c41d83faf9ef38667bf61b1', 'name': 'https://github.com/vim/vim/commit/80525751c5ce9ed82c41d83faf9ef38667bf61b1', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://huntr.dev/bounties/6e7b12a5-242c-453d-b39e-9625d563b0ea', 'name': 'https://huntr.dev/bounties/6e7b12a5-242c-453d-b39e-9625d563b0ea', 'refsource': 'CONFIRM', 'tags': ['Exploit', 'Issue Tracking', 'Patch', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}, {'lang': 'en', 'value': 'CWE-476'}]}] | nan | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '9.0.0259', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'NULL Pointer Dereference in GitHub repository vim/vim prior to 9.0.0259.'}] | 2022-08-27T03:36Z | 2022-08-25T20:15Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2022-08-24 19:27:45+01:00 | patch 9.0.0259: crash with mouse click when not initialized
Problem: Crash with mouse click when not initialized.
Solution: Check TabPageIdxs[] is not NULL. | 80525751c5ce9ed82c41d83faf9ef38667bf61b1 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | do_mouse | do_mouse( oparg_T * oap , int c , int dir , long count , int fixindent) | ['oap', 'c', 'dir', 'count', 'fixindent'] | do_mouse(
oparg_T *oap, // operator argument, can be NULL
int c, // K_LEFTMOUSE, etc
int dir, // Direction to 'put' if necessary
long count,
int fixindent) // PUT_FIXINDENT if fixing indent necessary
{
static int do_always = FALSE; // ignore 'mouse' setting next time
static int got_click = FALSE; // got a click some time back
int which_button; // MOUSE_LEFT, _MIDDLE or _RIGHT
int is_click = FALSE; // If FALSE it's a drag or release event
int is_drag = FALSE; // If TRUE it's a drag event
int jump_flags = 0; // flags for jump_to_mouse()
pos_T start_visual;
int moved; // Has cursor moved?
int in_status_line; // mouse in status line
static int in_tab_line = FALSE; // mouse clicked in tab line
int in_sep_line; // mouse in vertical separator line
int c1, c2;
#if defined(FEAT_FOLDING)
pos_T save_cursor;
#endif
win_T *old_curwin = curwin;
static pos_T orig_cursor;
colnr_T leftcol, rightcol;
pos_T end_visual;
int diff;
int old_active = VIsual_active;
int old_mode = VIsual_mode;
int regname;
#if defined(FEAT_FOLDING)
save_cursor = curwin->w_cursor;
#endif
// When GUI is active, always recognize mouse events, otherwise:
// - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'.
// - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'.
// - For command line and insert mode 'mouse' is checked before calling
// do_mouse().
if (do_always)
do_always = FALSE;
else
#ifdef FEAT_GUI
if (!gui.in_use)
#endif
{
if (VIsual_active)
{
if (!mouse_has(MOUSE_VISUAL))
return FALSE;
}
else if (State == MODE_NORMAL && !mouse_has(MOUSE_NORMAL))
return FALSE;
}
for (;;)
{
which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag);
if (is_drag)
{
// If the next character is the same mouse event then use that
// one. Speeds up dragging the status line.
// Note: Since characters added to the stuff buffer in the code
// below need to come before the next character, do not do this
// when the current character was stuffed.
if (!KeyStuffed && vpeekc() != NUL)
{
int nc;
int save_mouse_row = mouse_row;
int save_mouse_col = mouse_col;
// Need to get the character, peeking doesn't get the actual
// one.
nc = safe_vgetc();
if (c == nc)
continue;
vungetc(nc);
mouse_row = save_mouse_row;
mouse_col = save_mouse_col;
}
}
break;
}
if (c == K_MOUSEMOVE)
{
// Mouse moved without a button pressed.
#ifdef FEAT_BEVAL_TERM
ui_may_remove_balloon();
if (p_bevalterm)
{
profile_setlimit(p_bdlay, &bevalexpr_due);
bevalexpr_due_set = TRUE;
}
#endif
#ifdef FEAT_PROP_POPUP
popup_handle_mouse_moved();
#endif
return FALSE;
}
#ifdef FEAT_MOUSESHAPE
// May have stopped dragging the status or separator line. The pointer is
// most likely still on the status or separator line.
if (!is_drag && drag_status_line)
{
drag_status_line = FALSE;
update_mouseshape(SHAPE_IDX_STATUS);
}
if (!is_drag && drag_sep_line)
{
drag_sep_line = FALSE;
update_mouseshape(SHAPE_IDX_VSEP);
}
#endif
// Ignore drag and release events if we didn't get a click.
if (is_click)
got_click = TRUE;
else
{
if (!got_click) // didn't get click, ignore
return FALSE;
if (!is_drag) // release, reset got_click
{
got_click = FALSE;
if (in_tab_line)
{
in_tab_line = FALSE;
return FALSE;
}
}
}
// CTRL right mouse button does CTRL-T
if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT)
{
if (State & MODE_INSERT)
stuffcharReadbuff(Ctrl_O);
if (count > 1)
stuffnumReadbuff(count);
stuffcharReadbuff(Ctrl_T);
got_click = FALSE; // ignore drag&release now
return FALSE;
}
// CTRL only works with left mouse button
if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT)
return FALSE;
// When a modifier is down, ignore drag and release events, as well as
// multiple clicks and the middle mouse button.
// Accept shift-leftmouse drags when 'mousemodel' is "popup.*".
if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT
| MOD_MASK_META))
&& (!is_click
|| (mod_mask & MOD_MASK_MULTI_CLICK)
|| which_button == MOUSE_MIDDLE)
&& !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))
&& mouse_model_popup()
&& which_button == MOUSE_LEFT)
&& !((mod_mask & MOD_MASK_ALT)
&& !mouse_model_popup()
&& which_button == MOUSE_RIGHT)
)
return FALSE;
// If the button press was used as the movement command for an operator
// (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
// drag/release events.
if (!is_click && which_button == MOUSE_MIDDLE)
return FALSE;
if (oap != NULL)
regname = oap->regname;
else
regname = 0;
// Middle mouse button does a 'put' of the selected text
if (which_button == MOUSE_MIDDLE)
{
if (State == MODE_NORMAL)
{
// If an operator was pending, we don't know what the user wanted
// to do. Go back to normal mode: Clear the operator and beep().
if (oap != NULL && oap->op_type != OP_NOP)
{
clearopbeep(oap);
return FALSE;
}
// If visual was active, yank the highlighted text and put it
// before the mouse pointer position.
// In Select mode replace the highlighted text with the clipboard.
if (VIsual_active)
{
if (VIsual_select)
{
stuffcharReadbuff(Ctrl_G);
stuffReadbuff((char_u *)"\"+p");
}
else
{
stuffcharReadbuff('y');
stuffcharReadbuff(K_MIDDLEMOUSE);
}
do_always = TRUE; // ignore 'mouse' setting next time
return FALSE;
}
// The rest is below jump_to_mouse()
}
else if ((State & MODE_INSERT) == 0)
return FALSE;
// Middle click in insert mode doesn't move the mouse, just insert the
// contents of a register. '.' register is special, can't insert that
// with do_put().
// Also paste at the cursor if the current mode isn't in 'mouse' (only
// happens for the GUI).
if ((State & MODE_INSERT) || !mouse_has(MOUSE_NORMAL))
{
if (regname == '.')
insert_reg(regname, TRUE);
else
{
#ifdef FEAT_CLIPBOARD
if (clip_star.available && regname == 0)
regname = '*';
#endif
if ((State & REPLACE_FLAG) && !yank_register_mline(regname))
insert_reg(regname, TRUE);
else
{
do_put(regname, NULL, BACKWARD, 1L,
fixindent | PUT_CURSEND);
// Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r
AppendCharToRedobuff(Ctrl_R);
AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O);
AppendCharToRedobuff(regname == 0 ? '"' : regname);
}
}
return FALSE;
}
}
// When dragging or button-up stay in the same window.
if (!is_click)
jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE;
start_visual.lnum = 0;
// Check for clicking in the tab page line.
if (mouse_row == 0 && firstwin->w_winrow > 0)
{
if (is_drag)
{
if (in_tab_line)
{
c1 = TabPageIdxs[mouse_col];
tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab)
? c1 - 1 : c1);
}
return FALSE;
}
// click in a tab selects that tab page
if (is_click
# ifdef FEAT_CMDWIN
&& cmdwin_type == 0
# endif
&& mouse_col < Columns)
{
in_tab_line = TRUE;
c1 = TabPageIdxs[mouse_col];
if (c1 >= 0)
{
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
{
// double click opens new page
end_visual_mode_keep_button();
tabpage_new();
tabpage_move(c1 == 0 ? 9999 : c1 - 1);
}
else
{
// Go to specified tab page, or next one if not clicking
// on a label.
goto_tabpage(c1);
// It's like clicking on the status line of a window.
if (curwin != old_curwin)
end_visual_mode_keep_button();
}
}
else
{
tabpage_T *tp;
// Close the current or specified tab page.
if (c1 == -999)
tp = curtab;
else
tp = find_tabpage(-c1);
if (tp == curtab)
{
if (first_tabpage->tp_next != NULL)
tabpage_close(FALSE);
}
else if (tp != NULL)
tabpage_close_other(tp, FALSE);
}
}
return TRUE;
}
else if (is_drag && in_tab_line)
{
c1 = TabPageIdxs[mouse_col];
tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
return FALSE;
}
// When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
// right button up -> pop-up menu
// shift-left button -> right button
// alt-left button -> alt-right button
if (mouse_model_popup())
{
if (which_button == MOUSE_RIGHT
&& !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
{
#ifdef USE_POPUP_SETPOS
# ifdef FEAT_GUI
if (gui.in_use)
{
# if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
|| defined(FEAT_GUI_PHOTON)
if (!is_click)
// Ignore right button release events, only shows the popup
// menu on the button down event.
return FALSE;
# endif
# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_HAIKU)
if (is_click || is_drag)
// Ignore right button down and drag mouse events. Windows
// only shows the popup menu on the button up event.
return FALSE;
# endif
}
# endif
# if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU)
else
# endif
# if defined(FEAT_TERM_POPUP_MENU)
if (!is_click)
// Ignore right button release events, only shows the popup
// menu on the button down event.
return FALSE;
#endif
jump_flags = 0;
if (STRCMP(p_mousem, "popup_setpos") == 0)
{
// First set the cursor position before showing the popup
// menu.
if (VIsual_active)
{
pos_T m_pos;
// set MOUSE_MAY_STOP_VIS if we are outside the
// selection or the current window (might have false
// negative here)
if (mouse_row < curwin->w_winrow
|| mouse_row
> (curwin->w_winrow + curwin->w_height))
jump_flags = MOUSE_MAY_STOP_VIS;
else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER)
jump_flags = MOUSE_MAY_STOP_VIS;
else
{
if ((LT_POS(curwin->w_cursor, VIsual)
&& (LT_POS(m_pos, curwin->w_cursor)
|| LT_POS(VIsual, m_pos)))
|| (LT_POS(VIsual, curwin->w_cursor)
&& (LT_POS(m_pos, VIsual)
|| LT_POS(curwin->w_cursor, m_pos))))
{
jump_flags = MOUSE_MAY_STOP_VIS;
}
else if (VIsual_mode == Ctrl_V)
{
getvcols(curwin, &curwin->w_cursor, &VIsual,
&leftcol, &rightcol);
getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL);
if (m_pos.col < leftcol || m_pos.col > rightcol)
jump_flags = MOUSE_MAY_STOP_VIS;
}
}
}
else
jump_flags = MOUSE_MAY_STOP_VIS;
}
if (jump_flags)
{
jump_flags = jump_to_mouse(jump_flags, NULL, which_button);
update_curbuf(VIsual_active ? UPD_INVERTED : UPD_VALID);
setcursor();
out_flush(); // Update before showing popup menu
}
# ifdef FEAT_MENU
show_popupmenu();
got_click = FALSE; // ignore release events
# endif
return (jump_flags & CURSOR_MOVED) != 0;
#else
return FALSE;
#endif
}
if (which_button == MOUSE_LEFT
&& (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)))
{
which_button = MOUSE_RIGHT;
mod_mask &= ~MOD_MASK_SHIFT;
}
}
if ((State & (MODE_NORMAL | MODE_INSERT))
&& !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
{
if (which_button == MOUSE_LEFT)
{
if (is_click)
{
// stop Visual mode for a left click in a window, but not when
// on a status line
if (VIsual_active)
jump_flags |= MOUSE_MAY_STOP_VIS;
}
else if (mouse_has(MOUSE_VISUAL))
jump_flags |= MOUSE_MAY_VIS;
}
else if (which_button == MOUSE_RIGHT)
{
if (is_click && VIsual_active)
{
// Remember the start and end of visual before moving the
// cursor.
if (LT_POS(curwin->w_cursor, VIsual))
{
start_visual = curwin->w_cursor;
end_visual = VIsual;
}
else
{
start_visual = VIsual;
end_visual = curwin->w_cursor;
}
}
jump_flags |= MOUSE_FOCUS;
if (mouse_has(MOUSE_VISUAL))
jump_flags |= MOUSE_MAY_VIS;
}
}
// If an operator is pending, ignore all drags and releases until the
// next mouse click.
if (!is_drag && oap != NULL && oap->op_type != OP_NOP)
{
got_click = FALSE;
oap->motion_type = MCHAR;
}
// When releasing the button let jump_to_mouse() know.
if (!is_click && !is_drag)
jump_flags |= MOUSE_RELEASED;
// JUMP!
jump_flags = jump_to_mouse(jump_flags,
oap == NULL ? NULL : &(oap->inclusive), which_button);
#ifdef FEAT_MENU
// A click in the window toolbar has no side effects.
if (jump_flags & MOUSE_WINBAR)
return FALSE;
#endif
moved = (jump_flags & CURSOR_MOVED);
in_status_line = (jump_flags & IN_STATUS_LINE);
in_sep_line = (jump_flags & IN_SEP_LINE);
#ifdef FEAT_NETBEANS_INTG
if (isNetbeansBuffer(curbuf)
&& !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE)))
{
int key = KEY2TERMCAP1(c);
if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE
|| key == (int)KE_RIGHTRELEASE)
netbeans_button_release(which_button);
}
#endif
// When jumping to another window, clear a pending operator. That's a bit
// friendlier than beeping and not jumping to that window.
if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP)
clearop(oap);
#ifdef FEAT_FOLDING
if (mod_mask == 0
&& !is_drag
&& (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN))
&& which_button == MOUSE_LEFT)
{
// open or close a fold at this line
if (jump_flags & MOUSE_FOLD_OPEN)
openFold(curwin->w_cursor.lnum, 1L);
else
closeFold(curwin->w_cursor.lnum, 1L);
// don't move the cursor if still in the same window
if (curwin == old_curwin)
curwin->w_cursor = save_cursor;
}
#endif
#if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN)
if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available)
{
clip_modeless(which_button, is_click, is_drag);
return FALSE;
}
#endif
// Set global flag that we are extending the Visual area with mouse
// dragging; temporarily minimize 'scrolloff'.
if (VIsual_active && is_drag && get_scrolloff_value())
{
// In the very first line, allow scrolling one line
if (mouse_row == 0)
mouse_dragging = 2;
else
mouse_dragging = 1;
}
// When dragging the mouse above the window, scroll down.
if (is_drag && mouse_row < 0 && !in_status_line)
{
scroll_redraw(FALSE, 1L);
mouse_row = 0;
}
if (start_visual.lnum) // right click in visual mode
{
// When ALT is pressed make Visual mode blockwise.
if (mod_mask & MOD_MASK_ALT)
VIsual_mode = Ctrl_V;
// In Visual-block mode, divide the area in four, pick up the corner
// that is in the quarter that the cursor is in.
if (VIsual_mode == Ctrl_V)
{
getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol);
if (curwin->w_curswant > (leftcol + rightcol) / 2)
end_visual.col = leftcol;
else
end_visual.col = rightcol;
if (curwin->w_cursor.lnum >=
(start_visual.lnum + end_visual.lnum) / 2)
end_visual.lnum = start_visual.lnum;
// move VIsual to the right column
start_visual = curwin->w_cursor; // save the cursor pos
curwin->w_cursor = end_visual;
coladvance(end_visual.col);
VIsual = curwin->w_cursor;
curwin->w_cursor = start_visual; // restore the cursor
}
else
{
// If the click is before the start of visual, change the start.
// If the click is after the end of visual, change the end. If
// the click is inside the visual, change the closest side.
if (LT_POS(curwin->w_cursor, start_visual))
VIsual = end_visual;
else if (LT_POS(end_visual, curwin->w_cursor))
VIsual = start_visual;
else
{
// In the same line, compare column number
if (end_visual.lnum == start_visual.lnum)
{
if (curwin->w_cursor.col - start_visual.col >
end_visual.col - curwin->w_cursor.col)
VIsual = start_visual;
else
VIsual = end_visual;
}
// In different lines, compare line number
else
{
diff = (curwin->w_cursor.lnum - start_visual.lnum) -
(end_visual.lnum - curwin->w_cursor.lnum);
if (diff > 0) // closest to end
VIsual = start_visual;
else if (diff < 0) // closest to start
VIsual = end_visual;
else // in the middle line
{
if (curwin->w_cursor.col <
(start_visual.col + end_visual.col) / 2)
VIsual = end_visual;
else
VIsual = start_visual;
}
}
}
}
}
// If Visual mode started in insert mode, execute "CTRL-O"
else if ((State & MODE_INSERT) && VIsual_active)
stuffcharReadbuff(Ctrl_O);
// Middle mouse click: Put text before cursor.
if (which_button == MOUSE_MIDDLE)
{
#ifdef FEAT_CLIPBOARD
if (clip_star.available && regname == 0)
regname = '*';
#endif
if (yank_register_mline(regname))
{
if (mouse_past_bottom)
dir = FORWARD;
}
else if (mouse_past_eol)
dir = FORWARD;
if (fixindent)
{
c1 = (dir == BACKWARD) ? '[' : ']';
c2 = 'p';
}
else
{
c1 = (dir == FORWARD) ? 'p' : 'P';
c2 = NUL;
}
prep_redo(regname, count, NUL, c1, NUL, c2, NUL);
// Remember where the paste started, so in edit() Insstart can be set
// to this position
if (restart_edit != 0)
where_paste_started = curwin->w_cursor;
do_put(regname, NULL, dir, count, fixindent | PUT_CURSEND);
}
#if defined(FEAT_QUICKFIX)
// Ctrl-Mouse click or double click in a quickfix window jumps to the
// error under the mouse pointer.
else if (((mod_mask & MOD_MASK_CTRL)
|| (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
&& bt_quickfix(curbuf))
{
if (curwin->w_llist_ref == NULL) // quickfix window
do_cmdline_cmd((char_u *)".cc");
else // location list window
do_cmdline_cmd((char_u *)".ll");
got_click = FALSE; // ignore drag&release now
}
#endif
// Ctrl-Mouse click (or double click in a help window) jumps to the tag
// under the mouse pointer.
else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help
&& (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK))
{
if (State & MODE_INSERT)
stuffcharReadbuff(Ctrl_O);
stuffcharReadbuff(Ctrl_RSB);
got_click = FALSE; // ignore drag&release now
}
// Shift-Mouse click searches for the next occurrence of the word under
// the mouse pointer
else if ((mod_mask & MOD_MASK_SHIFT))
{
if ((State & MODE_INSERT) || (VIsual_active && VIsual_select))
stuffcharReadbuff(Ctrl_O);
if (which_button == MOUSE_LEFT)
stuffcharReadbuff('*');
else // MOUSE_RIGHT
stuffcharReadbuff('#');
}
// Handle double clicks, unless on status line
else if (in_status_line)
{
#ifdef FEAT_MOUSESHAPE
if ((is_drag || is_click) && !drag_status_line)
{
drag_status_line = TRUE;
update_mouseshape(-1);
}
#endif
}
else if (in_sep_line)
{
#ifdef FEAT_MOUSESHAPE
if ((is_drag || is_click) && !drag_sep_line)
{
drag_sep_line = TRUE;
update_mouseshape(-1);
}
#endif
}
else if ((mod_mask & MOD_MASK_MULTI_CLICK)
&& (State & (MODE_NORMAL | MODE_INSERT))
&& mouse_has(MOUSE_VISUAL))
{
if (is_click || !VIsual_active)
{
if (VIsual_active)
orig_cursor = VIsual;
else
{
check_visual_highlight();
VIsual = curwin->w_cursor;
orig_cursor = VIsual;
VIsual_active = TRUE;
VIsual_reselect = TRUE;
// start Select mode if 'selectmode' contains "mouse"
may_start_select('o');
setmouse();
}
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
{
// Double click with ALT pressed makes it blockwise.
if (mod_mask & MOD_MASK_ALT)
VIsual_mode = Ctrl_V;
else
VIsual_mode = 'v';
}
else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK)
VIsual_mode = 'V';
else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK)
VIsual_mode = Ctrl_V;
#ifdef FEAT_CLIPBOARD
// Make sure the clipboard gets updated. Needed because start and
// end may still be the same, and the selection needs to be owned
clip_star.vmode = NUL;
#endif
}
// A double click selects a word or a block.
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
{
pos_T *pos = NULL;
int gc;
if (is_click)
{
// If the character under the cursor (skipping white space) is
// not a word character, try finding a match and select a (),
// {}, [], #if/#endif, etc. block.
end_visual = curwin->w_cursor;
while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc))
inc(&end_visual);
if (oap != NULL)
oap->motion_type = MCHAR;
if (oap != NULL
&& VIsual_mode == 'v'
&& !vim_iswordc(gchar_pos(&end_visual))
&& EQUAL_POS(curwin->w_cursor, VIsual)
&& (pos = findmatch(oap, NUL)) != NULL)
{
curwin->w_cursor = *pos;
if (oap->motion_type == MLINE)
VIsual_mode = 'V';
else if (*p_sel == 'e')
{
if (LT_POS(curwin->w_cursor, VIsual))
++VIsual.col;
else
++curwin->w_cursor.col;
}
}
}
if (pos == NULL && (is_click || is_drag))
{
// When not found a match or when dragging: extend to include
// a word.
if (LT_POS(curwin->w_cursor, orig_cursor))
{
find_start_of_word(&curwin->w_cursor);
find_end_of_word(&VIsual);
}
else
{
find_start_of_word(&VIsual);
if (*p_sel == 'e' && *ml_get_cursor() != NUL)
curwin->w_cursor.col +=
(*mb_ptr2len)(ml_get_cursor());
find_end_of_word(&curwin->w_cursor);
}
}
curwin->w_set_curswant = TRUE;
}
if (is_click)
redraw_curbuf_later(UPD_INVERTED); // update the inversion
}
else if (VIsual_active && !old_active)
{
if (mod_mask & MOD_MASK_ALT)
VIsual_mode = Ctrl_V;
else
VIsual_mode = 'v';
}
// If Visual mode changed show it later.
if ((!VIsual_active && old_active && mode_displayed)
|| (VIsual_active && p_smd && msg_silent == 0
&& (!old_active || VIsual_mode != old_mode)))
redraw_cmdline = TRUE;
return moved;
} | 2905 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | realloc_buffer | realloc_buffer( VTermScreen * screen , ScreenCell * buffer , int new_rows , int new_cols) | ['screen', 'buffer', 'new_rows', 'new_cols'] | static ScreenCell *realloc_buffer(VTermScreen *screen, ScreenCell *buffer, int new_rows, int new_cols)
{
ScreenCell *new_buffer = vterm_allocator_malloc(screen->vt, sizeof(ScreenCell) * new_rows * new_cols);
int row, col;
for(row = 0; row < new_rows; row++) {
for(col = 0; col < new_cols; col++) {
ScreenCell *new_cell = new_buffer + row*new_cols + col;
if(buffer && row < screen->rows && col < screen->cols)
*new_cell = buffer[row * screen->cols + col];
else {
new_cell->chars[0] = 0;
new_cell->pen = screen->pen;
}
}
}
if(buffer)
vterm_allocator_free(screen->vt, buffer);
return new_buffer;
} | 151 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | resize | resize( int new_rows , int new_cols , VTermPos * delta , void * user) | ['new_rows', 'new_cols', 'delta', 'user'] | static int resize(int new_rows, int new_cols, VTermPos *delta, void *user)
{
VTermScreen *screen = user;
int is_altscreen = (screen->buffers[1] && screen->buffer == screen->buffers[1]);
int old_rows = screen->rows;
int old_cols = screen->cols;
int first_blank_row;
if(!is_altscreen && new_rows < old_rows) {
// Fewer rows - determine if we're going to scroll at all, and if so, push
// those lines to scrollback
VTermPos pos = { 0, 0 };
VTermPos cursor = screen->state->pos;
// Find the first blank row after the cursor.
for(pos.row = old_rows - 1; pos.row >= new_rows; pos.row--)
if(!vterm_screen_is_eol(screen, pos) || cursor.row == pos.row)
break;
first_blank_row = pos.row + 1;
if(first_blank_row > new_rows) {
VTermRect rect = {0,0,0,0};
rect.end_row = old_rows;
rect.end_col = old_cols;
scrollrect(rect, first_blank_row - new_rows, 0, user);
vterm_screen_flush_damage(screen);
delta->row -= first_blank_row - new_rows;
}
}
screen->buffers[0] = realloc_buffer(screen, screen->buffers[0], new_rows, new_cols);
if(screen->buffers[1])
screen->buffers[1] = realloc_buffer(screen, screen->buffers[1], new_rows, new_cols);
screen->buffer = is_altscreen ? screen->buffers[1] : screen->buffers[0];
screen->rows = new_rows;
screen->cols = new_cols;
if(screen->sb_buffer)
vterm_allocator_free(screen->vt, screen->sb_buffer);
screen->sb_buffer = vterm_allocator_malloc(screen->vt, sizeof(VTermScreenCell) * new_cols);
if(new_cols > old_cols) {
VTermRect rect;
rect.start_row = 0;
rect.end_row = old_rows;
rect.start_col = old_cols;
rect.end_col = new_cols;
damagerect(screen, rect);
}
if(new_rows > old_rows) {
if(!is_altscreen && screen->callbacks && screen->callbacks->sb_popline) {
int rows = new_rows - old_rows;
while(rows) {
VTermRect rect = {0,0,0,0};
VTermPos pos = { 0, 0 };
if(!(screen->callbacks->sb_popline(screen->cols, screen->sb_buffer, screen->cbdata)))
break;
rect.end_row = screen->rows;
rect.end_col = screen->cols;
scrollrect(rect, -1, 0, user);
for(pos.col = 0; pos.col < screen->cols; pos.col += screen->sb_buffer[pos.col].width)
vterm_screen_set_cell(screen, pos, screen->sb_buffer + pos.col);
rect.end_row = 1;
damagerect(screen, rect);
vterm_screen_flush_damage(screen);
rows--;
delta->row++;
}
}
{
VTermRect rect;
rect.start_row = old_rows;
rect.end_row = new_rows;
rect.start_col = 0;
rect.end_col = new_cols;
damagerect(screen, rect);
}
}
if(screen->callbacks && screen->callbacks->resize)
return (*screen->callbacks->resize)(new_rows, new_cols, screen->cbdata);
return 1;
} | 621 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | screen_new | screen_new( VTerm * vt) | ['vt'] | static VTermScreen *screen_new(VTerm *vt)
{
VTermState *state = vterm_obtain_state(vt);
VTermScreen *screen;
int rows, cols;
if(!state)
return NULL;
screen = vterm_allocator_malloc(vt, sizeof(VTermScreen));
vterm_get_size(vt, &rows, &cols);
screen->vt = vt;
screen->state = state;
screen->damage_merge = VTERM_DAMAGE_CELL;
screen->damaged.start_row = -1;
screen->pending_scrollrect.start_row = -1;
screen->rows = rows;
screen->cols = cols;
screen->callbacks = NULL;
screen->cbdata = NULL;
screen->buffers[0] = realloc_buffer(screen, NULL, rows, cols);
screen->buffer = screen->buffers[0];
screen->sb_buffer = vterm_allocator_malloc(screen->vt, sizeof(VTermScreenCell) * cols);
vterm_state_set_callbacks(screen->state, &state_cbs, screen);
return screen;
} | 179 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | vterm_screen_free | vterm_screen_free( VTermScreen * screen) | ['screen'] | INTERNAL void vterm_screen_free(VTermScreen *screen)
{
vterm_allocator_free(screen->vt, screen->buffers[0]);
if(screen->buffers[1])
vterm_allocator_free(screen->vt, screen->buffers[1]);
vterm_allocator_free(screen->vt, screen->sb_buffer);
vterm_allocator_free(screen->vt, screen);
} | 65 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | vterm_allocator_free | vterm_allocator_free( VTerm * vt , void * ptr) | ['vt', 'ptr'] | INTERNAL void vterm_allocator_free(VTerm *vt, void *ptr)
{
(*vt->allocator->free)(ptr, vt->allocdata);
} | 28 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | create_pty_only | create_pty_only( term_T * term , jobopt_T * opt) | ['term', 'opt'] | create_pty_only(term_T *term, jobopt_T *opt)
{
create_vterm(term, term->tl_rows, term->tl_cols);
term->tl_job = job_alloc();
if (term->tl_job == NULL)
return FAIL;
++term->tl_job->jv_refcount;
/* behave like the job is already finished */
term->tl_job->jv_status = JOB_FINISHED;
return mch_create_pty_channel(term->tl_job, opt);
} | 69 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | create_pty_only | create_pty_only( term_T * term , jobopt_T * options) | ['term', 'options'] | create_pty_only(term_T *term, jobopt_T *options)
{
HANDLE hPipeIn = INVALID_HANDLE_VALUE;
HANDLE hPipeOut = INVALID_HANDLE_VALUE;
char in_name[80], out_name[80];
channel_T *channel = NULL;
create_vterm(term, term->tl_rows, term->tl_cols);
vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d",
GetCurrentProcessId(),
curbuf->b_fnum);
hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND,
PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
PIPE_UNLIMITED_INSTANCES,
0, 0, NMPWAIT_NOWAIT, NULL);
if (hPipeIn == INVALID_HANDLE_VALUE)
goto failed;
vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d",
GetCurrentProcessId(),
curbuf->b_fnum);
hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND,
PIPE_TYPE_MESSAGE | PIPE_NOWAIT,
PIPE_UNLIMITED_INSTANCES,
0, 0, 0, NULL);
if (hPipeOut == INVALID_HANDLE_VALUE)
goto failed;
ConnectNamedPipe(hPipeIn, NULL);
ConnectNamedPipe(hPipeOut, NULL);
term->tl_job = job_alloc();
if (term->tl_job == NULL)
goto failed;
++term->tl_job->jv_refcount;
/* behave like the job is already finished */
term->tl_job->jv_status = JOB_FINISHED;
channel = add_channel();
if (channel == NULL)
goto failed;
term->tl_job->jv_channel = channel;
channel->ch_keep_open = TRUE;
channel->ch_named_pipe = TRUE;
channel_set_pipes(channel,
(sock_T)hPipeIn,
(sock_T)hPipeOut,
(sock_T)hPipeOut);
channel_set_job(channel, term->tl_job, options);
term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name);
term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name);
return OK;
failed:
if (hPipeIn != NULL)
CloseHandle(hPipeIn);
if (hPipeOut != NULL)
CloseHandle(hPipeOut);
return FAIL;
} | 330 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | create_vterm | create_vterm( term_T * term , int rows , int cols) | ['term', 'rows', 'cols'] | create_vterm(term_T *term, int rows, int cols)
{
VTerm *vterm;
VTermScreen *screen;
VTermState *state;
VTermValue value;
vterm = vterm_new_with_allocator(rows, cols, &vterm_allocator, NULL);
term->tl_vterm = vterm;
screen = vterm_obtain_screen(vterm);
vterm_screen_set_callbacks(screen, &screen_callbacks, term);
/* TODO: depends on 'encoding'. */
vterm_set_utf8(vterm, 1);
init_default_colors(term);
vterm_state_set_default_colors(
vterm_obtain_state(vterm),
&term->tl_default_color.fg,
&term->tl_default_color.bg);
if (t_colors >= 16)
vterm_state_set_bold_highbright(vterm_obtain_state(vterm), 1);
/* Required to initialize most things. */
vterm_screen_reset(screen, 1 /* hard */);
/* Allow using alternate screen. */
vterm_screen_enable_altscreen(screen, 1);
/* For unix do not use a blinking cursor. In an xterm this causes the
* cursor to blink if it's blinking in the xterm.
* For Windows we respect the system wide setting. */
#ifdef WIN3264
if (GetCaretBlinkTime() == INFINITE)
value.boolean = 0;
else
value.boolean = 1;
#else
value.boolean = 0;
#endif
state = vterm_obtain_state(vterm);
vterm_state_set_termprop(state, VTERM_PROP_CURSORBLINK, &value);
vterm_state_set_unrecognised_fallbacks(state, &parser_fallbacks, term);
} | 184 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | term_and_job_init | term_and_job_init( term_T * term , typval_T * argvar , char ** argv , jobopt_T * opt , jobopt_T * orig_opt UNUSED) | ['term', 'argvar', 'argv', 'opt', 'UNUSED'] | term_and_job_init(
term_T *term,
typval_T *argvar,
char **argv,
jobopt_T *opt,
jobopt_T *orig_opt UNUSED)
{
create_vterm(term, term->tl_rows, term->tl_cols);
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
if (opt->jo_set2 & JO2_ANSI_COLORS)
set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors);
else
init_vterm_ansi_colors(term->tl_vterm);
#endif
/* This may change a string in "argvar". */
term->tl_job = job_start(argvar, argv, opt, TRUE);
if (term->tl_job != NULL)
++term->tl_job->jv_refcount;
return term->tl_job != NULL
&& term->tl_job->jv_channel != NULL
&& term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
} | 122 | True | 1 |
CVE-2018-20786 | False | False | False | False | AV:N/AC:L/Au:N/C:N/I:N/A:P | NETWORK | LOW | NONE | NONE | NONE | PARTIAL | 5.0 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | NONE | NONE | HIGH | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/vim/vim/issues/3711', 'name': 'https://github.com/vim/vim/issues/3711', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'name': 'https://github.com/vim/vim/commit/cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-476'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:leonerd:libvterm:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0\\+bzr726', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libvterm through 0+bzr726, as used in Vim and other products, mishandles certain out-of-memory conditions, leading to a denial of service (application crash), related to screen.c, state.c, and vterm.c.'}] | 2020-03-30T20:15Z | 2019-02-24T14:29Z | NULL Pointer Dereference | A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit. | NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
| https://cwe.mitre.org/data/definitions/476.html | 0 | Bram Moolenaar | 2018-12-24 21:38:45+01:00 | patch 8.1.0633: crash when out of memory while opening a terminal window
Problem: Crash when out of memory while opening a terminal window.
Solution: Handle out-of-memory more gracefully. | cd929f7ba8cc5b6d6dcf35c8b34124e969fed6b8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | term_and_job_init | term_and_job_init( term_T * term , typval_T * argvar , char ** argv UNUSED , jobopt_T * opt , jobopt_T * orig_opt) | ['term', 'argvar', 'UNUSED', 'opt', 'orig_opt'] | term_and_job_init(
term_T *term,
typval_T *argvar,
char **argv UNUSED,
jobopt_T *opt,
jobopt_T *orig_opt)
{
WCHAR *cmd_wchar = NULL;
WCHAR *cwd_wchar = NULL;
WCHAR *env_wchar = NULL;
channel_T *channel = NULL;
job_T *job = NULL;
DWORD error;
HANDLE jo = NULL;
HANDLE child_process_handle;
HANDLE child_thread_handle;
void *winpty_err = NULL;
void *spawn_config = NULL;
garray_T ga_cmd, ga_env;
char_u *cmd = NULL;
if (dyn_winpty_init(TRUE) == FAIL)
return FAIL;
ga_init2(&ga_cmd, (int)sizeof(char*), 20);
ga_init2(&ga_env, (int)sizeof(char*), 20);
if (argvar->v_type == VAR_STRING)
{
cmd = argvar->vval.v_string;
}
else if (argvar->v_type == VAR_LIST)
{
if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL)
goto failed;
cmd = ga_cmd.ga_data;
}
if (cmd == NULL || *cmd == NUL)
{
EMSG(_(e_invarg));
goto failed;
}
cmd_wchar = enc_to_utf16(cmd, NULL);
ga_clear(&ga_cmd);
if (cmd_wchar == NULL)
goto failed;
if (opt->jo_cwd != NULL)
cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL);
win32_build_env(opt->jo_env, &ga_env, TRUE);
env_wchar = ga_env.ga_data;
term->tl_winpty_config = winpty_config_new(0, &winpty_err);
if (term->tl_winpty_config == NULL)
goto failed;
winpty_config_set_mouse_mode(term->tl_winpty_config,
WINPTY_MOUSE_MODE_FORCE);
winpty_config_set_initial_size(term->tl_winpty_config,
term->tl_cols, term->tl_rows);
term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err);
if (term->tl_winpty == NULL)
goto failed;
spawn_config = winpty_spawn_config_new(
WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN |
WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN,
NULL,
cmd_wchar,
cwd_wchar,
env_wchar,
&winpty_err);
if (spawn_config == NULL)
goto failed;
channel = add_channel();
if (channel == NULL)
goto failed;
job = job_alloc();
if (job == NULL)
goto failed;
if (argvar->v_type == VAR_STRING)
{
int argc;
build_argv_from_string(cmd, &job->jv_argv, &argc);
}
else
{
int argc;
build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc);
}
if (opt->jo_set & JO_IN_BUF)
job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]);
if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle,
&child_thread_handle, &error, &winpty_err))
goto failed;
channel_set_pipes(channel,
(sock_T)CreateFileW(
winpty_conin_name(term->tl_winpty),
GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL),
(sock_T)CreateFileW(
winpty_conout_name(term->tl_winpty),
GENERIC_READ, 0, NULL,
OPEN_EXISTING, 0, NULL),
(sock_T)CreateFileW(
winpty_conerr_name(term->tl_winpty),
GENERIC_READ, 0, NULL,
OPEN_EXISTING, 0, NULL));
/* Write lines with CR instead of NL. */
channel->ch_write_text_mode = TRUE;
jo = CreateJobObject(NULL, NULL);
if (jo == NULL)
goto failed;
if (!AssignProcessToJobObject(jo, child_process_handle))
{
/* Failed, switch the way to terminate process with TerminateProcess. */
CloseHandle(jo);
jo = NULL;
}
winpty_spawn_config_free(spawn_config);
vim_free(cmd_wchar);
vim_free(cwd_wchar);
vim_free(env_wchar);
create_vterm(term, term->tl_rows, term->tl_cols);
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
if (opt->jo_set2 & JO2_ANSI_COLORS)
set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors);
else
init_vterm_ansi_colors(term->tl_vterm);
#endif
channel_set_job(channel, job, opt);
job_set_options(job, opt);
job->jv_channel = channel;
job->jv_proc_info.hProcess = child_process_handle;
job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle);
job->jv_job_object = jo;
job->jv_status = JOB_STARTED;
job->jv_tty_in = utf16_to_enc(
(short_u*)winpty_conin_name(term->tl_winpty), NULL);
job->jv_tty_out = utf16_to_enc(
(short_u*)winpty_conout_name(term->tl_winpty), NULL);
++job->jv_refcount;
term->tl_job = job;
/* Redirecting stdout and stderr doesn't work at the job level. Instead
* open the file here and handle it in. opt->jo_io was changed in
* setup_job_options(), use the original flags here. */
if (orig_opt->jo_io[PART_OUT] == JIO_FILE)
{
char_u *fname = opt->jo_io_name[PART_OUT];
ch_log(channel, "Opening output file %s", fname);
term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN);
if (term->tl_out_fd == NULL)
EMSG2(_(e_notopen), fname);
}
return OK;
failed:
ga_clear(&ga_cmd);
ga_clear(&ga_env);
vim_free(cmd_wchar);
vim_free(cwd_wchar);
if (spawn_config != NULL)
winpty_spawn_config_free(spawn_config);
if (channel != NULL)
channel_clear(channel);
if (job != NULL)
{
job->jv_channel = NULL;
job_cleanup(job);
}
term->tl_job = NULL;
if (jo != NULL)
CloseHandle(jo);
if (term->tl_winpty != NULL)
winpty_free(term->tl_winpty);
term->tl_winpty = NULL;
if (term->tl_winpty_config != NULL)
winpty_config_free(term->tl_winpty_config);
term->tl_winpty_config = NULL;
if (winpty_err != NULL)
{
char_u *msg = utf16_to_enc(
(short_u *)winpty_error_msg(winpty_err), NULL);
EMSG(msg);
winpty_error_free(winpty_err);
}
return FAIL;
} | 1027 | True | 1 |
CVE-2019-20807 | False | False | False | False | AV:L/AC:L/Au:N/C:P/I:P/A:P | LOCAL | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 4.6 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L | LOCAL | LOW | LOW | NONE | UNCHANGED | LOW | LOW | LOW | 5.3 | MEDIUM | 1.8 | 3.4 | False | [{'url': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'name': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'name': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2020-06/msg00018.html', 'name': 'openSUSE-SU-2020:0794', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://support.apple.com/kb/HT211289', 'name': 'https://support.apple.com/kb/HT211289', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://seclists.org/fulldisclosure/2020/Jul/24', 'name': '20200717 APPLE-SA-2020-07-15-2 macOS Catalina 10.15.6, Security Update 2020-004 Mojave, Security Update 2020-004 High Sierra', 'refsource': 'FULLDISC', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4582-1/', 'name': 'USN-4582-1', 'refsource': 'UBUNTU', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/01/msg00003.html', 'name': '[debian-lts-announce] 20220110 [SECURITY] [DLA 2876-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'name': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'refsource': 'MISC', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-78'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.1.0881', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:15.1:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:esm:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.13.6:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.14.6:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'In Vim before 8.1.0881, users can circumvent the rvim restricted mode and execute arbitrary OS commands via scripting interfaces (e.g., Python, Ruby, or Lua).'}] | 2022-08-15T12:15Z | 2020-05-28T14:15Z | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The software constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. |
This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
There are at least two subtypes of OS command injection:
The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
| https://cwe.mitre.org/data/definitions/78.html | 0 | Bram Moolenaar | 2019-02-08 14:34:10+01:00 | patch 8.1.0881: can execute shell commands in rvim through interfaces
Problem: Can execute shell commands in rvim through interfaces.
Solution: Disable using interfaces in restricted mode. Allow for writing
file with writefile(), histadd() and a few others. | 8c62a08faf89663e5633dc5036cd8695c80f1075 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | f_histadd | f_histadd( typval_T * argvars UNUSED , typval_T * rettv) | ['UNUSED', 'rettv'] | f_histadd(typval_T *argvars UNUSED, typval_T *rettv)
{
#ifdef FEAT_CMDHIST
int histype;
char_u *str;
char_u buf[NUMBUFLEN];
#endif
rettv->vval.v_number = FALSE;
if (check_restricted() || check_secure())
return;
#ifdef FEAT_CMDHIST
str = tv_get_string_chk(&argvars[0]); /* NULL on type error */
histype = str != NULL ? get_histtype(str) : -1;
if (histype >= 0)
{
str = tv_get_string_buf(&argvars[1], buf);
if (*str != NUL)
{
init_history();
add_to_history(histype, str, FALSE, NUL);
rettv->vval.v_number = TRUE;
return;
}
}
#endif
} | 126 | True | 1 |
CVE-2019-20807 | False | False | False | False | AV:L/AC:L/Au:N/C:P/I:P/A:P | LOCAL | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 4.6 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L | LOCAL | LOW | LOW | NONE | UNCHANGED | LOW | LOW | LOW | 5.3 | MEDIUM | 1.8 | 3.4 | False | [{'url': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'name': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'name': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2020-06/msg00018.html', 'name': 'openSUSE-SU-2020:0794', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://support.apple.com/kb/HT211289', 'name': 'https://support.apple.com/kb/HT211289', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://seclists.org/fulldisclosure/2020/Jul/24', 'name': '20200717 APPLE-SA-2020-07-15-2 macOS Catalina 10.15.6, Security Update 2020-004 Mojave, Security Update 2020-004 High Sierra', 'refsource': 'FULLDISC', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4582-1/', 'name': 'USN-4582-1', 'refsource': 'UBUNTU', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/01/msg00003.html', 'name': '[debian-lts-announce] 20220110 [SECURITY] [DLA 2876-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'name': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'refsource': 'MISC', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-78'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.1.0881', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:15.1:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:esm:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.13.6:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.14.6:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'In Vim before 8.1.0881, users can circumvent the rvim restricted mode and execute arbitrary OS commands via scripting interfaces (e.g., Python, Ruby, or Lua).'}] | 2022-08-15T12:15Z | 2020-05-28T14:15Z | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The software constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. |
This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
There are at least two subtypes of OS command injection:
The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
| https://cwe.mitre.org/data/definitions/78.html | 0 | Bram Moolenaar | 2019-02-08 14:34:10+01:00 | patch 8.1.0881: can execute shell commands in rvim through interfaces
Problem: Can execute shell commands in rvim through interfaces.
Solution: Disable using interfaces in restricted mode. Allow for writing
file with writefile(), histadd() and a few others. | 8c62a08faf89663e5633dc5036cd8695c80f1075 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | f_setbufvar | f_setbufvar( typval_T * argvars , typval_T * rettv UNUSED) | ['argvars', 'UNUSED'] | f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
{
buf_T *buf;
char_u *varname, *bufvarname;
typval_T *varp;
char_u nbuf[NUMBUFLEN];
if (check_restricted() || check_secure())
return;
(void)tv_get_number(&argvars[0]); /* issue errmsg if type error */
varname = tv_get_string_chk(&argvars[1]);
buf = tv_get_buf(&argvars[0], FALSE);
varp = &argvars[2];
if (buf != NULL && varname != NULL && varp != NULL)
{
if (*varname == '&')
{
long numval;
char_u *strval;
int error = FALSE;
aco_save_T aco;
/* set curbuf to be our buf, temporarily */
aucmd_prepbuf(&aco, buf);
++varname;
numval = (long)tv_get_number_chk(varp, &error);
strval = tv_get_string_buf_chk(varp, nbuf);
if (!error && strval != NULL)
set_option_value(varname, numval, strval, OPT_LOCAL);
/* reset notion of buffer */
aucmd_restbuf(&aco);
}
else
{
buf_T *save_curbuf = curbuf;
bufvarname = alloc((unsigned)STRLEN(varname) + 3);
if (bufvarname != NULL)
{
curbuf = buf;
STRCPY(bufvarname, "b:");
STRCPY(bufvarname + 2, varname);
set_var(bufvarname, varp, TRUE);
vim_free(bufvarname);
curbuf = save_curbuf;
}
}
}
} | 259 | True | 1 |
CVE-2019-20807 | False | False | False | False | AV:L/AC:L/Au:N/C:P/I:P/A:P | LOCAL | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 4.6 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L | LOCAL | LOW | LOW | NONE | UNCHANGED | LOW | LOW | LOW | 5.3 | MEDIUM | 1.8 | 3.4 | False | [{'url': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'name': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'name': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2020-06/msg00018.html', 'name': 'openSUSE-SU-2020:0794', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://support.apple.com/kb/HT211289', 'name': 'https://support.apple.com/kb/HT211289', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://seclists.org/fulldisclosure/2020/Jul/24', 'name': '20200717 APPLE-SA-2020-07-15-2 macOS Catalina 10.15.6, Security Update 2020-004 Mojave, Security Update 2020-004 High Sierra', 'refsource': 'FULLDISC', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4582-1/', 'name': 'USN-4582-1', 'refsource': 'UBUNTU', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/01/msg00003.html', 'name': '[debian-lts-announce] 20220110 [SECURITY] [DLA 2876-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'name': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'refsource': 'MISC', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-78'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.1.0881', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:15.1:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:esm:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.13.6:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.14.6:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'In Vim before 8.1.0881, users can circumvent the rvim restricted mode and execute arbitrary OS commands via scripting interfaces (e.g., Python, Ruby, or Lua).'}] | 2022-08-15T12:15Z | 2020-05-28T14:15Z | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The software constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. |
This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
There are at least two subtypes of OS command injection:
The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
| https://cwe.mitre.org/data/definitions/78.html | 0 | Bram Moolenaar | 2019-02-08 14:34:10+01:00 | patch 8.1.0881: can execute shell commands in rvim through interfaces
Problem: Can execute shell commands in rvim through interfaces.
Solution: Disable using interfaces in restricted mode. Allow for writing
file with writefile(), histadd() and a few others. | 8c62a08faf89663e5633dc5036cd8695c80f1075 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | f_settabvar | f_settabvar( typval_T * argvars , typval_T * rettv) | ['argvars', 'rettv'] | f_settabvar(typval_T *argvars, typval_T *rettv)
{
tabpage_T *save_curtab;
tabpage_T *tp;
char_u *varname, *tabvarname;
typval_T *varp;
rettv->vval.v_number = 0;
if (check_restricted() || check_secure())
return;
tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL));
varname = tv_get_string_chk(&argvars[1]);
varp = &argvars[2];
if (varname != NULL && varp != NULL && tp != NULL)
{
save_curtab = curtab;
goto_tabpage_tp(tp, FALSE, FALSE);
tabvarname = alloc((unsigned)STRLEN(varname) + 3);
if (tabvarname != NULL)
{
STRCPY(tabvarname, "t:");
STRCPY(tabvarname + 2, varname);
set_var(tabvarname, varp, TRUE);
vim_free(tabvarname);
}
/* Restore current tabpage */
if (valid_tabpage(save_curtab))
goto_tabpage_tp(save_curtab, FALSE, FALSE);
}
} | 187 | True | 1 |
CVE-2019-20807 | False | False | False | False | AV:L/AC:L/Au:N/C:P/I:P/A:P | LOCAL | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 4.6 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L | LOCAL | LOW | LOW | NONE | UNCHANGED | LOW | LOW | LOW | 5.3 | MEDIUM | 1.8 | 3.4 | False | [{'url': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'name': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'name': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2020-06/msg00018.html', 'name': 'openSUSE-SU-2020:0794', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://support.apple.com/kb/HT211289', 'name': 'https://support.apple.com/kb/HT211289', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://seclists.org/fulldisclosure/2020/Jul/24', 'name': '20200717 APPLE-SA-2020-07-15-2 macOS Catalina 10.15.6, Security Update 2020-004 Mojave, Security Update 2020-004 High Sierra', 'refsource': 'FULLDISC', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4582-1/', 'name': 'USN-4582-1', 'refsource': 'UBUNTU', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/01/msg00003.html', 'name': '[debian-lts-announce] 20220110 [SECURITY] [DLA 2876-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'name': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'refsource': 'MISC', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-78'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.1.0881', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:15.1:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:esm:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.13.6:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.14.6:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'In Vim before 8.1.0881, users can circumvent the rvim restricted mode and execute arbitrary OS commands via scripting interfaces (e.g., Python, Ruby, or Lua).'}] | 2022-08-15T12:15Z | 2020-05-28T14:15Z | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The software constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. |
This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
There are at least two subtypes of OS command injection:
The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
| https://cwe.mitre.org/data/definitions/78.html | 0 | Bram Moolenaar | 2019-02-08 14:34:10+01:00 | patch 8.1.0881: can execute shell commands in rvim through interfaces
Problem: Can execute shell commands in rvim through interfaces.
Solution: Disable using interfaces in restricted mode. Allow for writing
file with writefile(), histadd() and a few others. | 8c62a08faf89663e5633dc5036cd8695c80f1075 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | f_writefile | f_writefile( typval_T * argvars , typval_T * rettv) | ['argvars', 'rettv'] | f_writefile(typval_T *argvars, typval_T *rettv)
{
int binary = FALSE;
int append = FALSE;
#ifdef HAVE_FSYNC
int do_fsync = p_fs;
#endif
char_u *fname;
FILE *fd;
int ret = 0;
listitem_T *li;
list_T *list = NULL;
blob_T *blob = NULL;
rettv->vval.v_number = -1;
if (check_restricted() || check_secure())
return;
if (argvars[0].v_type == VAR_LIST)
{
list = argvars[0].vval.v_list;
if (list == NULL)
return;
for (li = list->lv_first; li != NULL; li = li->li_next)
if (tv_get_string_chk(&li->li_tv) == NULL)
return;
}
else if (argvars[0].v_type == VAR_BLOB)
{
blob = argvars[0].vval.v_blob;
if (blob == NULL)
return;
}
else
{
semsg(_(e_invarg2), "writefile()");
return;
}
if (argvars[2].v_type != VAR_UNKNOWN)
{
char_u *arg2 = tv_get_string_chk(&argvars[2]);
if (arg2 == NULL)
return;
if (vim_strchr(arg2, 'b') != NULL)
binary = TRUE;
if (vim_strchr(arg2, 'a') != NULL)
append = TRUE;
#ifdef HAVE_FSYNC
if (vim_strchr(arg2, 's') != NULL)
do_fsync = TRUE;
else if (vim_strchr(arg2, 'S') != NULL)
do_fsync = FALSE;
#endif
}
fname = tv_get_string_chk(&argvars[1]);
if (fname == NULL)
return;
/* Always open the file in binary mode, library functions have a mind of
* their own about CR-LF conversion. */
if (*fname == NUL || (fd = mch_fopen((char *)fname,
append ? APPENDBIN : WRITEBIN)) == NULL)
{
semsg(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname);
ret = -1;
}
else if (blob)
{
if (write_blob(fd, blob) == FAIL)
ret = -1;
#ifdef HAVE_FSYNC
else if (do_fsync)
// Ignore the error, the user wouldn't know what to do about it.
// May happen for a device.
vim_ignored = fsync(fileno(fd));
#endif
fclose(fd);
}
else
{
if (write_list(fd, list, binary) == FAIL)
ret = -1;
#ifdef HAVE_FSYNC
else if (do_fsync)
/* Ignore the error, the user wouldn't know what to do about it.
* May happen for a device. */
vim_ignored = fsync(fileno(fd));
#endif
fclose(fd);
}
rettv->vval.v_number = ret;
} | 454 | True | 1 |
CVE-2019-20807 | False | False | False | False | AV:L/AC:L/Au:N/C:P/I:P/A:P | LOCAL | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 4.6 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L | LOCAL | LOW | LOW | NONE | UNCHANGED | LOW | LOW | LOW | 5.3 | MEDIUM | 1.8 | 3.4 | False | [{'url': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'name': 'https://github.com/vim/vim/commit/8c62a08faf89663e5633dc5036cd8695c80f1075', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'name': 'https://github.com/vim/vim/releases/tag/v8.1.0881', 'refsource': 'MISC', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-security-announce/2020-06/msg00018.html', 'name': 'openSUSE-SU-2020:0794', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://support.apple.com/kb/HT211289', 'name': 'https://support.apple.com/kb/HT211289', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://seclists.org/fulldisclosure/2020/Jul/24', 'name': '20200717 APPLE-SA-2020-07-15-2 macOS Catalina 10.15.6, Security Update 2020-004 Mojave, Security Update 2020-004 High Sierra', 'refsource': 'FULLDISC', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4582-1/', 'name': 'USN-4582-1', 'refsource': 'UBUNTU', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/01/msg00003.html', 'name': '[debian-lts-announce] 20220110 [SECURITY] [DLA 2876-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'name': 'https://www.starwindsoftware.com/security/sw-20220812-0003/', 'refsource': 'MISC', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-78'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.1.0881', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:15.1:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:esm:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.13.6:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:apple:mac_os_x:10.14.6:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'In Vim before 8.1.0881, users can circumvent the rvim restricted mode and execute arbitrary OS commands via scripting interfaces (e.g., Python, Ruby, or Lua).'}] | 2022-08-15T12:15Z | 2020-05-28T14:15Z | Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | The software constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. |
This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
There are at least two subtypes of OS command injection:
The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
| https://cwe.mitre.org/data/definitions/78.html | 0 | Bram Moolenaar | 2019-02-08 14:34:10+01:00 | patch 8.1.0881: can execute shell commands in rvim through interfaces
Problem: Can execute shell commands in rvim through interfaces.
Solution: Disable using interfaces in restricted mode. Allow for writing
file with writefile(), histadd() and a few others. | 8c62a08faf89663e5633dc5036cd8695c80f1075 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | check_restricted | check_restricted( void) | ['void'] | check_restricted(void)
{
if (restricted)
{
emsg(_("E145: Shell commands not allowed in rvim"));
return TRUE;
}
return FALSE;
} | 26 | True | 1 |
CVE-2019-20079 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | False | [{'url': 'https://packetstormsecurity.com/files/154898', 'name': 'https://packetstormsecurity.com/files/154898', 'refsource': 'MISC', 'tags': ['Third Party Advisory', 'VDB Entry']}, {'url': 'https://github.com/vim/vim/commit/ec66c41d84e574baf8009dbc0bd088d2bc5b2421', 'name': 'https://github.com/vim/vim/commit/ec66c41d84e574baf8009dbc0bd088d2bc5b2421', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/compare/v8.1.2135...v8.1.2136', 'name': 'https://github.com/vim/vim/compare/v8.1.2135...v8.1.2136', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-416'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionStartIncluding': '8.1.2121', 'versionEndExcluding': '8.1.2136', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:12.04:*:*:*:esm:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:14.04:*:*:*:esm:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:19.10:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'The autocmd feature in window.c in Vim before 8.1.2136 accesses freed memory.'}] | 2020-10-20T16:04Z | 2019-12-30T01:15Z | Use After Free | Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code. |
The use of previously-freed memory can have any number of adverse consequences, ranging from the corruption of valid data to the execution of arbitrary code, depending on the instantiation and timing of the flaw. The simplest way data corruption may occur involves the system's reuse of the freed memory. Use-after-free errors have two common and sometimes overlapping causes:
Error conditions and other exceptional circumstances.
Confusion over which part of the program is responsible for freeing the memory.
In this scenario, the memory in question is allocated to another pointer validly at some point after it has been freed. The original pointer to the freed memory is used again and points to somewhere within the new allocation. As the data is changed, it corrupts the validly used memory; this induces undefined behavior in the process.
If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.
| https://cwe.mitre.org/data/definitions/416.html | 0 | Bram Moolenaar | 2019-10-11 21:19:13+02:00 | patch 8.1.2136: using freed memory with autocmd from fuzzer
Problem: using freed memory with autocmd from fuzzer. (Dhiraj Mishra,
Dominique Pelle)
Solution: Avoid using "wp" after autocommands. (closes #5041) | ec66c41d84e574baf8009dbc0bd088d2bc5b2421 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | win_enter_ext | win_enter_ext( win_T * wp , int undo_sync , int curwin_invalid , int trigger_new_autocmds , int trigger_enter_autocmds , int trigger_leave_autocmds) | ['wp', 'undo_sync', 'curwin_invalid', 'trigger_new_autocmds', 'trigger_enter_autocmds', 'trigger_leave_autocmds'] | win_enter_ext(
win_T *wp,
int undo_sync,
int curwin_invalid,
int trigger_new_autocmds,
int trigger_enter_autocmds,
int trigger_leave_autocmds)
{
int other_buffer = FALSE;
if (wp == curwin && !curwin_invalid) /* nothing to do */
return;
#ifdef FEAT_JOB_CHANNEL
if (!curwin_invalid)
leaving_window(curwin);
#endif
if (!curwin_invalid && trigger_leave_autocmds)
{
/*
* Be careful: If autocommands delete the window, return now.
*/
if (wp->w_buffer != curbuf)
{
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
other_buffer = TRUE;
if (!win_valid(wp))
return;
}
apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf);
if (!win_valid(wp))
return;
#ifdef FEAT_EVAL
/* autocmds may abort script processing */
if (aborting())
return;
#endif
}
/* sync undo before leaving the current buffer */
if (undo_sync && curbuf != wp->w_buffer)
u_sync(FALSE);
/* Might need to scroll the old window before switching, e.g., when the
* cursor was moved. */
update_topline();
/* may have to copy the buffer options when 'cpo' contains 'S' */
if (wp->w_buffer != curbuf)
buf_copy_options(wp->w_buffer, BCO_ENTER | BCO_NOHELP);
if (!curwin_invalid)
{
prevwin = curwin; /* remember for CTRL-W p */
curwin->w_redr_status = TRUE;
}
curwin = wp;
curbuf = wp->w_buffer;
check_cursor();
if (!virtual_active())
curwin->w_cursor.coladd = 0;
changed_line_abv_curs(); /* assume cursor position needs updating */
if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL)
{
char_u *dirname;
// Window or tab has a local directory: Save current directory as
// global directory (unless that was done already) and change to the
// local directory.
if (globaldir == NULL)
{
char_u cwd[MAXPATHL];
if (mch_dirname(cwd, MAXPATHL) == OK)
globaldir = vim_strsave(cwd);
}
if (curwin->w_localdir != NULL)
dirname = curwin->w_localdir;
else
dirname = curtab->tp_localdir;
if (mch_chdir((char *)dirname) == 0)
shorten_fnames(TRUE);
}
else if (globaldir != NULL)
{
/* Window doesn't have a local directory and we are not in the global
* directory: Change to the global directory. */
vim_ignored = mch_chdir((char *)globaldir);
VIM_CLEAR(globaldir);
shorten_fnames(TRUE);
}
#ifdef FEAT_JOB_CHANNEL
entering_window(curwin);
#endif
if (trigger_new_autocmds)
apply_autocmds(EVENT_WINNEW, NULL, NULL, FALSE, curbuf);
if (trigger_enter_autocmds)
{
apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);
if (other_buffer)
apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
}
#ifdef FEAT_TITLE
maketitle();
#endif
curwin->w_redr_status = TRUE;
#ifdef FEAT_TERMINAL
if (bt_terminal(wp->w_buffer))
// terminal is likely in another mode
redraw_mode = TRUE;
#endif
redraw_tabline = TRUE;
if (restart_edit)
redraw_later(VALID); /* causes status line redraw */
/* set window height to desired minimal value */
if (curwin->w_height < p_wh && !curwin->w_p_wfh
#ifdef FEAT_TEXT_PROP
&& !popup_is_popup(curwin)
#endif
)
win_setheight((int)p_wh);
else if (curwin->w_height == 0)
win_setheight(1);
/* set window width to desired minimal value */
if (curwin->w_width < p_wiw && !curwin->w_p_wfw)
win_setwidth((int)p_wiw);
setmouse(); // in case jumped to/from help buffer
/* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR;
} | 497 | True | 1 |
CVE-2016-1248 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.0/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'http://openwall.com/lists/oss-security/2016/11/22/20', 'name': 'http://openwall.com/lists/oss-security/2016/11/22/20', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/releases/tag/v8.0.0056', 'name': 'https://github.com/vim/vim/releases/tag/v8.0.0056', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'https://github.com/vim/vim/commit/d0b5138ba4bccff8a744c99836041ef6322ed39a', 'name': 'https://github.com/vim/vim/commit/d0b5138ba4bccff8a744c99836041ef6322ed39a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'https://lists.debian.org/debian-security-announce/2016/msg00305.html', 'name': 'https://lists.debian.org/debian-security-announce/2016/msg00305.html', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'https://github.com/neovim/neovim/commit/4fad66fbe637818b6b3d6bc5d21923ba72795040', 'name': 'https://github.com/neovim/neovim/commit/4fad66fbe637818b6b3d6bc5d21923ba72795040', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'https://anonscm.debian.org/cgit/pkg-vim/vim.git/tree/debian/changelog', 'name': 'https://anonscm.debian.org/cgit/pkg-vim/vim.git/tree/debian/changelog', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2016/11/msg00025.html', 'name': '[debian-lts-announce] 20161122 [SECURITY] [DLA 718-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.securityfocus.com/bid/94478', 'name': '94478', 'refsource': 'BID', 'tags': []}, {'url': 'http://www.ubuntu.com/usn/USN-3139-1', 'name': 'USN-3139-1', 'refsource': 'UBUNTU', 'tags': []}, {'url': 'http://www.debian.org/security/2016/dsa-3722', 'name': 'DSA-3722', 'refsource': 'DEBIAN', 'tags': []}, {'url': 'http://rhn.redhat.com/errata/RHSA-2016-2972.html', 'name': 'RHSA-2016:2972', 'refsource': 'REDHAT', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/201701-29', 'name': 'GLSA-201701-29', 'refsource': 'GENTOO', 'tags': []}, {'url': 'http://www.securitytracker.com/id/1037338', 'name': '1037338', 'refsource': 'SECTRACK', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-20'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndIncluding': '8.0.0055', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': "vim before patch 8.0.0056 does not properly validate values for the 'filetype', 'syntax' and 'keymap' options, which may result in the execution of arbitrary code if a file with a specially crafted modeline is opened."}] | 2017-07-28T01:29Z | 2016-11-23T15:59Z | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. |
Input validation is a frequently-used technique
for checking potentially dangerous inputs in order to
ensure that the inputs are safe for processing within the
code, or when communicating with other components. When
software does not validate input properly, an attacker is
able to craft the input in a form that is not expected by
the rest of the application. This will lead to parts of the
system receiving unintended input, which may result in
altered control flow, arbitrary control of a resource, or
arbitrary code execution.
Input validation is not the only technique for
processing input, however. Other techniques attempt to
transform potentially-dangerous input into something safe, such
as filtering (CWE-790) - which attempts to remove dangerous
inputs - or encoding/escaping (CWE-116), which attempts to
ensure that the input is not misinterpreted when it is included
in output to another component. Other techniques exist as well
(see CWE-138 for more examples.)
Input validation can be applied to:
raw data - strings, numbers, parameters, file contents, etc.
metadata - information about the raw data, such as headers or size
Data can be simple or structured. Structured data
can be composed of many nested layers, composed of
combinations of metadata and raw data, with other simple or
structured data.
Many properties of raw data or metadata may need
to be validated upon entry into the code, such
as:
specified quantities such as size, length, frequency, price, rate, number of operations, time, etc.
implied or derived quantities, such as the actual size of a file instead of a specified size
indexes, offsets, or positions into more complex data structures
symbolic keys or other elements into hash tables, associative arrays, etc.
well-formedness, i.e. syntactic correctness - compliance with expected syntax
lexical token correctness - compliance with rules for what is treated as a token
specified or derived type - the actual type of the input (or what the input appears to be)
consistency - between individual data elements, between raw data and metadata, between references, etc.
conformance to domain-specific rules, e.g. business logic
equivalence - ensuring that equivalent inputs are treated the same
authenticity, ownership, or other attestations about the input, e.g. a cryptographic signature to prove the source of the data
Implied or derived properties of data must often
be calculated or inferred by the code itself. Errors in
deriving properties may be considered a contributing factor
to improper input validation.
Note that "input validation" has very different
meanings to different people, or within different
classification schemes. Caution must be used when
referencing this CWE entry or mapping to it. For example,
some weaknesses might involve inadvertently giving control
to an attacker over an input when they should not be able
to provide an input at all, but sometimes this is referred
to as input validation.
Finally, it is important to emphasize that the
distinctions between input validation and output escaping
are often blurred, and developers must be careful to
understand the difference, including how input validation
is not always sufficient to prevent vulnerabilities,
especially when less stringent data types must be
supported, such as free-form text. Consider a SQL injection
scenario in which a person's last name is inserted into a
query. The name "O'Reilly" would likely pass the validation
step since it is a common last name in the English
language. However, this valid name cannot be directly
inserted into the database because it contains the "'"
apostrophe character, which would need to be escaped or
otherwise transformed. In this case, removing the
apostrophe might reduce the risk of SQL injection, but it
would produce incorrect behavior because the wrong name
would be recorded.
| https://cwe.mitre.org/data/definitions/20.html | 0 | Bram Moolenaar | 2016-11-04 15:23:45+01:00 | patch 8.0.0056
Problem: When setting 'filetype' there is no check for a valid name.
Solution: Only allow valid characters in 'filetype', 'syntax' and 'keymap'. | d0b5138ba4bccff8a744c99836041ef6322ed39a | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | vimoptionoptions::did_set_string_option | vimoptionoptions::did_set_string_option( int opt_idx , char_u ** varp , int new_value_alloced , char_u * oldval , char_u * errbuf , int opt_flags) | ['opt_idx', 'varp', 'new_value_alloced', 'oldval', 'errbuf', 'opt_flags'] | did_set_string_option(
int opt_idx, /* index in options[] table */
char_u **varp, /* pointer to the option variable */
int new_value_alloced, /* new value was allocated */
char_u *oldval, /* previous value of the option */
char_u *errbuf, /* buffer for errors, or NULL */
int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
{
char_u *errmsg = NULL;
char_u *s, *p;
int did_chartab = FALSE;
char_u **gvarp;
long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
#ifdef FEAT_GUI
/* set when changing an option that only requires a redraw in the GUI */
int redraw_gui_only = FALSE;
#endif
/* Get the global option to compare with, otherwise we would have to check
* two values for all local options. */
gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
/* Disallow changing some options from secure mode */
if ((secure
#ifdef HAVE_SANDBOX
|| sandbox != 0
#endif
) && (options[opt_idx].flags & P_SECURE))
{
errmsg = e_secure;
}
/* Check for a "normal" file name in some options. Disallow a path
* separator (slash and/or backslash), wildcards and characters that are
* often illegal in a file name. */
else if ((options[opt_idx].flags & P_NFNAME)
&& vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
{
errmsg = e_invarg;
}
/* 'term' */
else if (varp == &T_NAME)
{
if (T_NAME[0] == NUL)
errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
#ifdef FEAT_GUI
if (gui.in_use)
errmsg = (char_u *)N_("E530: Cannot change term in GUI");
else if (term_is_gui(T_NAME))
errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
#endif
else if (set_termname(T_NAME) == FAIL)
errmsg = (char_u *)N_("E522: Not found in termcap");
else
/* Screen colors may have changed. */
redraw_later_clear();
}
/* 'backupcopy' */
else if (gvarp == &p_bkc)
{
char_u *bkc = p_bkc;
unsigned int *flags = &bkc_flags;
if (opt_flags & OPT_LOCAL)
{
bkc = curbuf->b_p_bkc;
flags = &curbuf->b_bkc_flags;
}
if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
/* make the local value empty: use the global value */
*flags = 0;
else
{
if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
errmsg = e_invarg;
if ((((int)*flags & BKC_AUTO) != 0)
+ (((int)*flags & BKC_YES) != 0)
+ (((int)*flags & BKC_NO) != 0) != 1)
{
/* Must have exactly one of "auto", "yes" and "no". */
(void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
errmsg = e_invarg;
}
}
}
/* 'backupext' and 'patchmode' */
else if (varp == &p_bex || varp == &p_pm)
{
if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
*p_pm == '.' ? p_pm + 1 : p_pm) == 0)
errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
}
#ifdef FEAT_LINEBREAK
/* 'breakindentopt' */
else if (varp == &curwin->w_p_briopt)
{
if (briopt_check(curwin) == FAIL)
errmsg = e_invarg;
}
#endif
/*
* 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
* If the new option is invalid, use old value. 'lisp' option: refill
* g_chartab[] for '-' char
*/
else if ( varp == &p_isi
|| varp == &(curbuf->b_p_isk)
|| varp == &p_isp
|| varp == &p_isf)
{
if (init_chartab() == FAIL)
{
did_chartab = TRUE; /* need to restore it below */
errmsg = e_invarg; /* error in value */
}
}
/* 'helpfile' */
else if (varp == &p_hf)
{
/* May compute new values for $VIM and $VIMRUNTIME */
if (didset_vim)
{
vim_setenv((char_u *)"VIM", (char_u *)"");
didset_vim = FALSE;
}
if (didset_vimruntime)
{
vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
didset_vimruntime = FALSE;
}
}
#ifdef FEAT_SYN_HL
/* 'colorcolumn' */
else if (varp == &curwin->w_p_cc)
errmsg = check_colorcolumn(curwin);
#endif
#ifdef FEAT_MULTI_LANG
/* 'helplang' */
else if (varp == &p_hlg)
{
/* Check for "", "ab", "ab,cd", etc. */
for (s = p_hlg; *s != NUL; s += 3)
{
if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
{
errmsg = e_invarg;
break;
}
if (s[2] == NUL)
break;
}
}
#endif
/* 'highlight' */
else if (varp == &p_hl)
{
if (highlight_changed() == FAIL)
errmsg = e_invarg; /* invalid flags */
}
/* 'nrformats' */
else if (gvarp == &p_nf)
{
if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
errmsg = e_invarg;
}
#ifdef FEAT_SESSION
/* 'sessionoptions' */
else if (varp == &p_ssop)
{
if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
errmsg = e_invarg;
if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
{
/* Don't allow both "sesdir" and "curdir". */
(void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
errmsg = e_invarg;
}
}
/* 'viewoptions' */
else if (varp == &p_vop)
{
if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
errmsg = e_invarg;
}
#endif
/* 'scrollopt' */
#ifdef FEAT_SCROLLBIND
else if (varp == &p_sbo)
{
if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
errmsg = e_invarg;
}
#endif
/* 'ambiwidth' */
#ifdef FEAT_MBYTE
else if (varp == &p_ambw || varp == &p_emoji)
{
if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
errmsg = e_invarg;
else if (set_chars_option(&p_lcs) != NULL)
errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
else if (set_chars_option(&p_fcs) != NULL)
errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
# endif
}
#endif
/* 'background' */
else if (varp == &p_bg)
{
if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
{
#ifdef FEAT_EVAL
int dark = (*p_bg == 'd');
#endif
init_highlight(FALSE, FALSE);
#ifdef FEAT_EVAL
if (dark != (*p_bg == 'd')
&& get_var_value((char_u *)"g:colors_name") != NULL)
{
/* The color scheme must have set 'background' back to another
* value, that's not what we want here. Disable the color
* scheme and set the colors again. */
do_unlet((char_u *)"g:colors_name", TRUE);
free_string_option(p_bg);
p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
check_string_option(&p_bg);
init_highlight(FALSE, FALSE);
}
#endif
}
else
errmsg = e_invarg;
}
/* 'wildmode' */
else if (varp == &p_wim)
{
if (check_opt_wim() == FAIL)
errmsg = e_invarg;
}
#ifdef FEAT_CMDL_COMPL
/* 'wildoptions' */
else if (varp == &p_wop)
{
if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
errmsg = e_invarg;
}
#endif
#ifdef FEAT_WAK
/* 'winaltkeys' */
else if (varp == &p_wak)
{
if (*p_wak == NUL
|| check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
errmsg = e_invarg;
# ifdef FEAT_MENU
# ifdef FEAT_GUI_MOTIF
else if (gui.in_use)
gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
# else
# ifdef FEAT_GUI_GTK
else if (gui.in_use)
gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
# endif
# endif
# endif
}
#endif
#ifdef FEAT_AUTOCMD
/* 'eventignore' */
else if (varp == &p_ei)
{
if (check_ei() == FAIL)
errmsg = e_invarg;
}
#endif
#ifdef FEAT_MBYTE
/* 'encoding' and 'fileencoding' */
else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
{
if (gvarp == &p_fenc)
{
if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
errmsg = e_modifiable;
else if (vim_strchr(*varp, ',') != NULL)
/* No comma allowed in 'fileencoding'; catches confusing it
* with 'fileencodings'. */
errmsg = e_invarg;
else
{
# ifdef FEAT_TITLE
/* May show a "+" in the title now. */
redraw_titles();
# endif
/* Add 'fileencoding' to the swap file. */
ml_setflags(curbuf);
}
}
if (errmsg == NULL)
{
/* canonize the value, so that STRCMP() can be used on it */
p = enc_canonize(*varp);
if (p != NULL)
{
vim_free(*varp);
*varp = p;
}
if (varp == &p_enc)
{
errmsg = mb_init();
# ifdef FEAT_TITLE
redraw_titles();
# endif
}
}
# if defined(FEAT_GUI_GTK)
if (errmsg == NULL && varp == &p_tenc && gui.in_use)
{
/* GTK+ 2 uses only a single encoding, and that is UTF-8. */
if (STRCMP(p_tenc, "utf-8") != 0)
errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
}
# endif
if (errmsg == NULL)
{
# ifdef FEAT_KEYMAP
/* When 'keymap' is used and 'encoding' changes, reload the keymap
* (with another encoding). */
if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
(void)keymap_init();
# endif
/* When 'termencoding' is not empty and 'encoding' changes or when
* 'termencoding' changes, need to setup for keyboard input and
* display output conversion. */
if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
{
convert_setup(&input_conv, p_tenc, p_enc);
convert_setup(&output_conv, p_enc, p_tenc);
}
# if defined(WIN3264) && defined(FEAT_MBYTE)
/* $HOME may have characters in active code page. */
if (varp == &p_enc)
init_homedir();
# endif
}
}
#endif
#if defined(FEAT_POSTSCRIPT)
else if (varp == &p_penc)
{
/* Canonize printencoding if VIM standard one */
p = enc_canonize(p_penc);
if (p != NULL)
{
vim_free(p_penc);
p_penc = p;
}
else
{
/* Ensure lower case and '-' for '_' */
for (s = p_penc; *s != NUL; s++)
{
if (*s == '_')
*s = '-';
else
*s = TOLOWER_ASC(*s);
}
}
}
#endif
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
else if (varp == &p_imak)
{
if (gui.in_use && !im_xim_isvalid_imactivate())
errmsg = e_invarg;
}
#endif
#ifdef FEAT_KEYMAP
else if (varp == &curbuf->b_p_keymap)
{
/* load or unload key mapping tables */
errmsg = keymap_init();
if (errmsg == NULL)
{
if (*curbuf->b_p_keymap != NUL)
{
/* Installed a new keymap, switch on using it. */
curbuf->b_p_iminsert = B_IMODE_LMAP;
if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
curbuf->b_p_imsearch = B_IMODE_LMAP;
}
else
{
/* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
if (curbuf->b_p_iminsert == B_IMODE_LMAP)
curbuf->b_p_iminsert = B_IMODE_NONE;
if (curbuf->b_p_imsearch == B_IMODE_LMAP)
curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
}
if ((opt_flags & OPT_LOCAL) == 0)
{
set_iminsert_global();
set_imsearch_global();
}
# ifdef FEAT_WINDOWS
status_redraw_curbuf();
# endif
}
}
#endif
/* 'fileformat' */
else if (gvarp == &p_ff)
{
if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
errmsg = e_modifiable;
else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
errmsg = e_invarg;
else
{
/* may also change 'textmode' */
if (get_fileformat(curbuf) == EOL_DOS)
curbuf->b_p_tx = TRUE;
else
curbuf->b_p_tx = FALSE;
#ifdef FEAT_TITLE
redraw_titles();
#endif
/* update flag in swap file */
ml_setflags(curbuf);
/* Redraw needed when switching to/from "mac": a CR in the text
* will be displayed differently. */
if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
redraw_curbuf_later(NOT_VALID);
}
}
/* 'fileformats' */
else if (varp == &p_ffs)
{
if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
errmsg = e_invarg;
else
{
/* also change 'textauto' */
if (*p_ffs == NUL)
p_ta = FALSE;
else
p_ta = TRUE;
}
}
#if defined(FEAT_CRYPT)
/* 'cryptkey' */
else if (gvarp == &p_key)
{
# if defined(FEAT_CMDHIST)
/* Make sure the ":set" command doesn't show the new value in the
* history. */
remove_key_from_history();
# endif
if (STRCMP(curbuf->b_p_key, oldval) != 0)
/* Need to update the swapfile. */
ml_set_crypt_key(curbuf, oldval,
*curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
}
else if (gvarp == &p_cm)
{
if (opt_flags & OPT_LOCAL)
p = curbuf->b_p_cm;
else
p = p_cm;
if (check_opt_strings(p, p_cm_values, TRUE) != OK)
errmsg = e_invarg;
else if (crypt_self_test() == FAIL)
errmsg = e_invarg;
else
{
/* When setting the global value to empty, make it "zip". */
if (*p_cm == NUL)
{
if (new_value_alloced)
free_string_option(p_cm);
p_cm = vim_strsave((char_u *)"zip");
new_value_alloced = TRUE;
}
/* When using ":set cm=name" the local value is going to be empty.
* Do that here, otherwise the crypt functions will still use the
* local value. */
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
{
free_string_option(curbuf->b_p_cm);
curbuf->b_p_cm = empty_option;
}
/* Need to update the swapfile when the effective method changed.
* Set "s" to the effective old value, "p" to the effective new
* method and compare. */
if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
s = p_cm; /* was previously using the global value */
else
s = oldval;
if (*curbuf->b_p_cm == NUL)
p = p_cm; /* is now using the global value */
else
p = curbuf->b_p_cm;
if (STRCMP(s, p) != 0)
ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
/* If the global value changes need to update the swapfile for all
* buffers using that value. */
if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
{
buf_T *buf;
FOR_ALL_BUFFERS(buf)
if (buf != curbuf && *buf->b_p_cm == NUL)
ml_set_crypt_key(buf, buf->b_p_key, oldval);
}
}
}
#endif
/* 'matchpairs' */
else if (gvarp == &p_mps)
{
#ifdef FEAT_MBYTE
if (has_mbyte)
{
for (p = *varp; *p != NUL; ++p)
{
int x2 = -1;
int x3 = -1;
if (*p != NUL)
p += mb_ptr2len(p);
if (*p != NUL)
x2 = *p++;
if (*p != NUL)
{
x3 = mb_ptr2char(p);
p += mb_ptr2len(p);
}
if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
{
errmsg = e_invarg;
break;
}
if (*p == NUL)
break;
}
}
else
#endif
{
/* Check for "x:y,x:y" */
for (p = *varp; *p != NUL; p += 4)
{
if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
{
errmsg = e_invarg;
break;
}
if (p[3] == NUL)
break;
}
}
}
#ifdef FEAT_COMMENTS
/* 'comments' */
else if (gvarp == &p_com)
{
for (s = *varp; *s; )
{
while (*s && *s != ':')
{
if (vim_strchr((char_u *)COM_ALL, *s) == NULL
&& !VIM_ISDIGIT(*s) && *s != '-')
{
errmsg = illegal_char(errbuf, *s);
break;
}
++s;
}
if (*s++ == NUL)
errmsg = (char_u *)N_("E524: Missing colon");
else if (*s == ',' || *s == NUL)
errmsg = (char_u *)N_("E525: Zero length string");
if (errmsg != NULL)
break;
while (*s && *s != ',')
{
if (*s == '\\' && s[1] != NUL)
++s;
++s;
}
s = skip_to_option_part(s);
}
}
#endif
/* 'listchars' */
else if (varp == &p_lcs)
{
errmsg = set_chars_option(varp);
}
#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
/* 'fillchars' */
else if (varp == &p_fcs)
{
errmsg = set_chars_option(varp);
}
#endif
#ifdef FEAT_CMDWIN
/* 'cedit' */
else if (varp == &p_cedit)
{
errmsg = check_cedit();
}
#endif
/* 'verbosefile' */
else if (varp == &p_vfile)
{
verbose_stop();
if (*p_vfile != NUL && verbose_open() == FAIL)
errmsg = e_invarg;
}
#ifdef FEAT_VIMINFO
/* 'viminfo' */
else if (varp == &p_viminfo)
{
for (s = p_viminfo; *s;)
{
/* Check it's a valid character */
if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
{
errmsg = illegal_char(errbuf, *s);
break;
}
if (*s == 'n') /* name is always last one */
{
break;
}
else if (*s == 'r') /* skip until next ',' */
{
while (*++s && *s != ',')
;
}
else if (*s == '%')
{
/* optional number */
while (vim_isdigit(*++s))
;
}
else if (*s == '!' || *s == 'h' || *s == 'c')
++s; /* no extra chars */
else /* must have a number */
{
while (vim_isdigit(*++s))
;
if (!VIM_ISDIGIT(*(s - 1)))
{
if (errbuf != NULL)
{
sprintf((char *)errbuf,
_("E526: Missing number after <%s>"),
transchar_byte(*(s - 1)));
errmsg = errbuf;
}
else
errmsg = (char_u *)"";
break;
}
}
if (*s == ',')
++s;
else if (*s)
{
if (errbuf != NULL)
errmsg = (char_u *)N_("E527: Missing comma");
else
errmsg = (char_u *)"";
break;
}
}
if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
errmsg = (char_u *)N_("E528: Must specify a ' value");
}
#endif /* FEAT_VIMINFO */
/* terminal options */
else if (istermoption(&options[opt_idx]) && full_screen)
{
/* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
if (varp == &T_CCO)
{
int colors = atoi((char *)T_CCO);
/* Only reinitialize colors if t_Co value has really changed to
* avoid expensive reload of colorscheme if t_Co is set to the
* same value multiple times. */
if (colors != t_colors)
{
t_colors = colors;
if (t_colors <= 1)
{
if (new_value_alloced)
vim_free(T_CCO);
T_CCO = empty_option;
}
/* We now have a different color setup, initialize it again. */
init_highlight(TRUE, FALSE);
}
}
ttest(FALSE);
if (varp == &T_ME)
{
out_str(T_ME);
redraw_later(CLEAR);
#if defined(WIN3264) && !defined(FEAT_GUI_W32)
/* Since t_me has been set, this probably means that the user
* wants to use this as default colors. Need to reset default
* background/foreground colors. */
mch_set_normal_colors();
#endif
}
}
#ifdef FEAT_LINEBREAK
/* 'showbreak' */
else if (varp == &p_sbr)
{
for (s = p_sbr; *s; )
{
if (ptr2cells(s) != 1)
errmsg = (char_u *)N_("E595: contains unprintable or wide character");
mb_ptr_adv(s);
}
}
#endif
#ifdef FEAT_GUI
/* 'guifont' */
else if (varp == &p_guifont)
{
if (gui.in_use)
{
p = p_guifont;
# if defined(FEAT_GUI_GTK)
/*
* Put up a font dialog and let the user select a new value.
* If this is cancelled go back to the old value but don't
* give an error message.
*/
if (STRCMP(p, "*") == 0)
{
p = gui_mch_font_dialog(oldval);
if (new_value_alloced)
free_string_option(p_guifont);
p_guifont = (p != NULL) ? p : vim_strsave(oldval);
new_value_alloced = TRUE;
}
# endif
if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
{
# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
if (STRCMP(p_guifont, "*") == 0)
{
/* Dialog was cancelled: Keep the old value without giving
* an error message. */
if (new_value_alloced)
free_string_option(p_guifont);
p_guifont = vim_strsave(oldval);
new_value_alloced = TRUE;
}
else
# endif
errmsg = (char_u *)N_("E596: Invalid font(s)");
}
}
redraw_gui_only = TRUE;
}
# ifdef FEAT_XFONTSET
else if (varp == &p_guifontset)
{
if (STRCMP(p_guifontset, "*") == 0)
errmsg = (char_u *)N_("E597: can't select fontset");
else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
errmsg = (char_u *)N_("E598: Invalid fontset");
redraw_gui_only = TRUE;
}
# endif
# ifdef FEAT_MBYTE
else if (varp == &p_guifontwide)
{
if (STRCMP(p_guifontwide, "*") == 0)
errmsg = (char_u *)N_("E533: can't select wide font");
else if (gui_get_wide_font() == FAIL)
errmsg = (char_u *)N_("E534: Invalid wide font");
redraw_gui_only = TRUE;
}
# endif
#endif
#ifdef CURSOR_SHAPE
/* 'guicursor' */
else if (varp == &p_guicursor)
errmsg = parse_shape_opt(SHAPE_CURSOR);
#endif
#ifdef FEAT_MOUSESHAPE
/* 'mouseshape' */
else if (varp == &p_mouseshape)
{
errmsg = parse_shape_opt(SHAPE_MOUSE);
update_mouseshape(-1);
}
#endif
#ifdef FEAT_PRINTER
else if (varp == &p_popt)
errmsg = parse_printoptions();
# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
else if (varp == &p_pmfn)
errmsg = parse_printmbfont();
# endif
#endif
#ifdef FEAT_LANGMAP
/* 'langmap' */
else if (varp == &p_langmap)
langmap_set();
#endif
#ifdef FEAT_LINEBREAK
/* 'breakat' */
else if (varp == &p_breakat)
fill_breakat_flags();
#endif
#ifdef FEAT_TITLE
/* 'titlestring' and 'iconstring' */
else if (varp == &p_titlestring || varp == &p_iconstring)
{
# ifdef FEAT_STL_OPT
int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
/* NULL => statusline syntax */
if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
stl_syntax |= flagval;
else
stl_syntax &= ~flagval;
# endif
did_set_title(varp == &p_iconstring);
}
#endif
#ifdef FEAT_GUI
/* 'guioptions' */
else if (varp == &p_go)
{
gui_init_which_components(oldval);
redraw_gui_only = TRUE;
}
#endif
#if defined(FEAT_GUI_TABLINE)
/* 'guitablabel' */
else if (varp == &p_gtl)
{
redraw_tabline = TRUE;
redraw_gui_only = TRUE;
}
/* 'guitabtooltip' */
else if (varp == &p_gtt)
{
redraw_gui_only = TRUE;
}
#endif
#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
/* 'ttymouse' */
else if (varp == &p_ttym)
{
/* Switch the mouse off before changing the escape sequences used for
* that. */
mch_setmouse(FALSE);
if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
errmsg = e_invarg;
else
check_mouse_termcode();
if (termcap_active)
setmouse(); /* may switch it on again */
}
#endif
/* 'selection' */
else if (varp == &p_sel)
{
if (*p_sel == NUL
|| check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
errmsg = e_invarg;
}
/* 'selectmode' */
else if (varp == &p_slm)
{
if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
errmsg = e_invarg;
}
#ifdef FEAT_BROWSE
/* 'browsedir' */
else if (varp == &p_bsdir)
{
if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
&& !mch_isdir(p_bsdir))
errmsg = e_invarg;
}
#endif
/* 'keymodel' */
else if (varp == &p_km)
{
if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
errmsg = e_invarg;
else
{
km_stopsel = (vim_strchr(p_km, 'o') != NULL);
km_startsel = (vim_strchr(p_km, 'a') != NULL);
}
}
/* 'mousemodel' */
else if (varp == &p_mousem)
{
if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
errmsg = e_invarg;
#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
else if (*p_mousem != *oldval)
/* Changed from "extend" to "popup" or "popup_setpos" or vv: need
* to create or delete the popup menus. */
gui_motif_update_mousemodel(root_menu);
#endif
}
/* 'switchbuf' */
else if (varp == &p_swb)
{
if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
errmsg = e_invarg;
}
/* 'debug' */
else if (varp == &p_debug)
{
if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
errmsg = e_invarg;
}
/* 'display' */
else if (varp == &p_dy)
{
if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
errmsg = e_invarg;
else
(void)init_chartab();
}
#ifdef FEAT_WINDOWS
/* 'eadirection' */
else if (varp == &p_ead)
{
if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
errmsg = e_invarg;
}
#endif
#ifdef FEAT_CLIPBOARD
/* 'clipboard' */
else if (varp == &p_cb)
errmsg = check_clipboard_option();
#endif
#ifdef FEAT_SPELL
/* When 'spelllang' or 'spellfile' is set and there is a window for this
* buffer in which 'spell' is set load the wordlists. */
else if (varp == &(curwin->w_s->b_p_spl)
|| varp == &(curwin->w_s->b_p_spf))
{
errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
}
/* When 'spellcapcheck' is set compile the regexp program. */
else if (varp == &(curwin->w_s->b_p_spc))
{
errmsg = compile_cap_prog(curwin->w_s);
}
/* 'spellsuggest' */
else if (varp == &p_sps)
{
if (spell_check_sps() != OK)
errmsg = e_invarg;
}
/* 'mkspellmem' */
else if (varp == &p_msm)
{
if (spell_check_msm() != OK)
errmsg = e_invarg;
}
#endif
#ifdef FEAT_QUICKFIX
/* When 'bufhidden' is set, check for valid value. */
else if (gvarp == &p_bh)
{
if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
errmsg = e_invarg;
}
/* When 'buftype' is set, check for valid value. */
else if (gvarp == &p_bt)
{
if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
errmsg = e_invarg;
else
{
# ifdef FEAT_WINDOWS
if (curwin->w_status_height)
{
curwin->w_redr_status = TRUE;
redraw_later(VALID);
}
# endif
curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
# ifdef FEAT_TITLE
redraw_titles();
# endif
}
}
#endif
#ifdef FEAT_STL_OPT
/* 'statusline' or 'rulerformat' */
else if (gvarp == &p_stl || varp == &p_ruf)
{
int wid;
if (varp == &p_ruf) /* reset ru_wid first */
ru_wid = 0;
s = *varp;
if (varp == &p_ruf && *s == '%')
{
/* set ru_wid if 'ruf' starts with "%99(" */
if (*++s == '-') /* ignore a '-' */
s++;
wid = getdigits(&s);
if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
ru_wid = wid;
else
errmsg = check_stl_option(p_ruf);
}
/* check 'statusline' only if it doesn't start with "%!" */
else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
errmsg = check_stl_option(s);
if (varp == &p_ruf && errmsg == NULL)
comp_col();
}
#endif
#ifdef FEAT_INS_EXPAND
/* check if it is a valid value for 'complete' -- Acevedo */
else if (gvarp == &p_cpt)
{
for (s = *varp; *s;)
{
while (*s == ',' || *s == ' ')
s++;
if (!*s)
break;
if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
{
errmsg = illegal_char(errbuf, *s);
break;
}
if (*++s != NUL && *s != ',' && *s != ' ')
{
if (s[-1] == 'k' || s[-1] == 's')
{
/* skip optional filename after 'k' and 's' */
while (*s && *s != ',' && *s != ' ')
{
if (*s == '\\')
++s;
++s;
}
}
else
{
if (errbuf != NULL)
{
sprintf((char *)errbuf,
_("E535: Illegal character after <%c>"),
*--s);
errmsg = errbuf;
}
else
errmsg = (char_u *)"";
break;
}
}
}
}
/* 'completeopt' */
else if (varp == &p_cot)
{
if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
errmsg = e_invarg;
else
completeopt_was_set();
}
#endif /* FEAT_INS_EXPAND */
#ifdef FEAT_SIGNS
/* 'signcolumn' */
else if (varp == &curwin->w_p_scl)
{
if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
errmsg = e_invarg;
}
#endif
#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
else if (varp == &p_toolbar)
{
if (opt_strings_flags(p_toolbar, p_toolbar_values,
&toolbar_flags, TRUE) != OK)
errmsg = e_invarg;
else
{
out_flush();
gui_mch_show_toolbar((toolbar_flags &
(TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
}
}
#endif
#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
/* 'toolbariconsize': GTK+ 2 only */
else if (varp == &p_tbis)
{
if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
errmsg = e_invarg;
else
{
out_flush();
gui_mch_show_toolbar((toolbar_flags &
(TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
}
}
#endif
/* 'pastetoggle': translate key codes like in a mapping */
else if (varp == &p_pt)
{
if (*p_pt)
{
(void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
if (p != NULL)
{
if (new_value_alloced)
free_string_option(p_pt);
p_pt = p;
new_value_alloced = TRUE;
}
}
}
/* 'backspace' */
else if (varp == &p_bs)
{
if (VIM_ISDIGIT(*p_bs))
{
if (*p_bs > '2' || p_bs[1] != NUL)
errmsg = e_invarg;
}
else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
errmsg = e_invarg;
}
else if (varp == &p_bo)
{
if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
errmsg = e_invarg;
}
/* 'tagcase' */
else if (gvarp == &p_tc)
{
unsigned int *flags;
if (opt_flags & OPT_LOCAL)
{
p = curbuf->b_p_tc;
flags = &curbuf->b_tc_flags;
}
else
{
p = p_tc;
flags = &tc_flags;
}
if ((opt_flags & OPT_LOCAL) && *p == NUL)
/* make the local value empty: use the global value */
*flags = 0;
else if (*p == NUL
|| opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
errmsg = e_invarg;
}
#ifdef FEAT_MBYTE
/* 'casemap' */
else if (varp == &p_cmp)
{
if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
errmsg = e_invarg;
}
#endif
#ifdef FEAT_DIFF
/* 'diffopt' */
else if (varp == &p_dip)
{
if (diffopt_changed() == FAIL)
errmsg = e_invarg;
}
#endif
#ifdef FEAT_FOLDING
/* 'foldmethod' */
else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
{
if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
|| *curwin->w_p_fdm == NUL)
errmsg = e_invarg;
else
{
foldUpdateAll(curwin);
if (foldmethodIsDiff(curwin))
newFoldLevel();
}
}
# ifdef FEAT_EVAL
/* 'foldexpr' */
else if (varp == &curwin->w_p_fde)
{
if (foldmethodIsExpr(curwin))
foldUpdateAll(curwin);
}
# endif
/* 'foldmarker' */
else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
{
p = vim_strchr(*varp, ',');
if (p == NULL)
errmsg = (char_u *)N_("E536: comma required");
else if (p == *varp || p[1] == NUL)
errmsg = e_invarg;
else if (foldmethodIsMarker(curwin))
foldUpdateAll(curwin);
}
/* 'commentstring' */
else if (gvarp == &p_cms)
{
if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
}
/* 'foldopen' */
else if (varp == &p_fdo)
{
if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
errmsg = e_invarg;
}
/* 'foldclose' */
else if (varp == &p_fcl)
{
if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
errmsg = e_invarg;
}
/* 'foldignore' */
else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
{
if (foldmethodIsIndent(curwin))
foldUpdateAll(curwin);
}
#endif
#ifdef FEAT_VIRTUALEDIT
/* 'virtualedit' */
else if (varp == &p_ve)
{
if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
errmsg = e_invarg;
else if (STRCMP(p_ve, oldval) != 0)
{
/* Recompute cursor position in case the new 've' setting
* changes something. */
validate_virtcol();
coladvance(curwin->w_virtcol);
}
}
#endif
#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
else if (varp == &p_csqf)
{
if (p_csqf != NULL)
{
p = p_csqf;
while (*p != NUL)
{
if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
|| p[1] == NUL
|| vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
|| (p[2] != NUL && p[2] != ','))
{
errmsg = e_invarg;
break;
}
else if (p[2] == NUL)
break;
else
p += 3;
}
}
}
#endif
#ifdef FEAT_CINDENT
/* 'cinoptions' */
else if (gvarp == &p_cino)
{
/* TODO: recognize errors */
parse_cino(curbuf);
}
#endif
#if defined(FEAT_RENDER_OPTIONS)
else if (varp == &p_rop && gui.in_use)
{
if (!gui_mch_set_rendering_options(p_rop))
errmsg = e_invarg;
}
#endif
/* Options that are a list of flags. */
else
{
p = NULL;
if (varp == &p_ww)
p = (char_u *)WW_ALL;
if (varp == &p_shm)
p = (char_u *)SHM_ALL;
else if (varp == &(p_cpo))
p = (char_u *)CPO_ALL;
else if (varp == &(curbuf->b_p_fo))
p = (char_u *)FO_ALL;
#ifdef FEAT_CONCEAL
else if (varp == &curwin->w_p_cocu)
p = (char_u *)COCU_ALL;
#endif
else if (varp == &p_mouse)
{
#ifdef FEAT_MOUSE
p = (char_u *)MOUSE_ALL;
#else
if (*p_mouse != NUL)
errmsg = (char_u *)N_("E538: No mouse support");
#endif
}
#if defined(FEAT_GUI)
else if (varp == &p_go)
p = (char_u *)GO_ALL;
#endif
if (p != NULL)
{
for (s = *varp; *s; ++s)
if (vim_strchr(p, *s) == NULL)
{
errmsg = illegal_char(errbuf, *s);
break;
}
}
}
/*
* If error detected, restore the previous value.
*/
if (errmsg != NULL)
{
if (new_value_alloced)
free_string_option(*varp);
*varp = oldval;
/*
* When resetting some values, need to act on it.
*/
if (did_chartab)
(void)init_chartab();
if (varp == &p_hl)
(void)highlight_changed();
}
else
{
#ifdef FEAT_EVAL
/* Remember where the option was set. */
set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
#endif
/*
* Free string options that are in allocated memory.
* Use "free_oldval", because recursiveness may change the flags under
* our fingers (esp. init_highlight()).
*/
if (free_oldval)
free_string_option(oldval);
if (new_value_alloced)
options[opt_idx].flags |= P_ALLOCED;
else
options[opt_idx].flags &= ~P_ALLOCED;
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
&& ((int)options[opt_idx].indir & PV_BOTH))
{
/* global option with local value set to use global value; free
* the local value and make it empty */
p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
free_string_option(*(char_u **)p);
*(char_u **)p = empty_option;
}
/* May set global value for local option. */
else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
set_string_option_global(opt_idx, varp);
#ifdef FEAT_AUTOCMD
/*
* Trigger the autocommand only after setting the flags.
*/
# ifdef FEAT_SYN_HL
/* When 'syntax' is set, load the syntax of that name */
if (varp == &(curbuf->b_p_syn))
{
apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
curbuf->b_fname, TRUE, curbuf);
}
# endif
else if (varp == &(curbuf->b_p_ft))
{
/* 'filetype' is set, trigger the FileType autocommand */
did_filetype = TRUE;
apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
curbuf->b_fname, TRUE, curbuf);
}
#endif
#ifdef FEAT_SPELL
if (varp == &(curwin->w_s->b_p_spl))
{
char_u fname[200];
char_u *q = curwin->w_s->b_p_spl;
/* Skip the first name if it is "cjk". */
if (STRNCMP(q, "cjk,", 4) == 0)
q += 4;
/*
* Source the spell/LANG.vim in 'runtimepath'.
* They could set 'spellcapcheck' depending on the language.
* Use the first name in 'spelllang' up to '_region' or
* '.encoding'.
*/
for (p = q; *p != NUL; ++p)
if (vim_strchr((char_u *)"_.,", *p) != NULL)
break;
vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
source_runtime(fname, DIP_ALL);
}
#endif
}
#ifdef FEAT_MOUSE
if (varp == &p_mouse)
{
# ifdef FEAT_MOUSE_TTY
if (*p_mouse == NUL)
mch_setmouse(FALSE); /* switch mouse off */
else
# endif
setmouse(); /* in case 'mouse' changed */
}
#endif
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
curwin->w_set_curswant = TRUE;
#ifdef FEAT_GUI
/* check redraw when it's not a GUI option or the GUI is active. */
if (!redraw_gui_only || gui.in_use)
#endif
check_redraw(options[opt_idx].flags);
return errmsg;
} | 5906 | True | 1 |
CVE-2017-6349 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/3eb1637b1bba19519885dd6d377bd5596e91d22c', 'name': 'https://github.com/vim/vim/commit/3eb1637b1bba19519885dd6d377bd5596e91d22c', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://www.securityfocus.com/bid/96451', 'name': '96451', 'refsource': 'BID', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/201706-26', 'name': 'GLSA-201706-26', 'refsource': 'GENTOO', 'tags': []}, {'url': 'http://www.securitytracker.com/id/1037949', 'name': '1037949', 'refsource': 'SECTRACK', 'tags': []}, {'url': 'https://groups.google.com/forum/#!topic/vim_dev/QPZc0CY9j3Y', 'name': 'https://groups.google.com/forum/#!topic/vim_dev/QPZc0CY9j3Y', 'refsource': 'MISC', 'tags': []}, {'url': 'https://groups.google.com/forum/#!topic/vim_dev/LAgsTcdSfNA', 'name': 'https://groups.google.com/forum/#!topic/vim_dev/LAgsTcdSfNA', 'refsource': 'MISC', 'tags': []}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-190'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndIncluding': '8.0.0376', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'An integer overflow at a u_read_undo memory allocation site would occur for vim before patch 8.0.0377, if it does not properly validate values for tree length when reading a corrupted undo file, which may lead to resultant buffer overflows.'}] | 2018-08-13T21:47Z | 2017-02-27T07:59Z | Integer Overflow or Wraparound | The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
| https://cwe.mitre.org/data/definitions/190.html | 0 | Bram Moolenaar | 2017-02-26 18:11:36+01:00 | patch 8.0.0377: possible overflow when reading corrupted undo file
Problem: Possible overflow when reading corrupted undo file.
Solution: Check if allocated size is not too big. (King) | 3eb1637b1bba19519885dd6d377bd5596e91d22c | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | u_read_undo | u_read_undo( char_u * name , char_u * hash , char_u * orig_name) | ['name', 'hash', 'orig_name'] | u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
{
char_u *file_name;
FILE *fp;
long version, str_len;
char_u *line_ptr = NULL;
linenr_T line_lnum;
colnr_T line_colnr;
linenr_T line_count;
int num_head = 0;
long old_header_seq, new_header_seq, cur_header_seq;
long seq_last, seq_cur;
long last_save_nr = 0;
short old_idx = -1, new_idx = -1, cur_idx = -1;
long num_read_uhps = 0;
time_t seq_time;
int i, j;
int c;
u_header_T *uhp;
u_header_T **uhp_table = NULL;
char_u read_hash[UNDO_HASH_SIZE];
char_u magic_buf[UF_START_MAGIC_LEN];
#ifdef U_DEBUG
int *uhp_table_used;
#endif
#ifdef UNIX
stat_T st_orig;
stat_T st_undo;
#endif
bufinfo_T bi;
vim_memset(&bi, 0, sizeof(bi));
if (name == NULL)
{
file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE);
if (file_name == NULL)
return;
#ifdef UNIX
/* For safety we only read an undo file if the owner is equal to the
* owner of the text file or equal to the current user. */
if (mch_stat((char *)orig_name, &st_orig) >= 0
&& mch_stat((char *)file_name, &st_undo) >= 0
&& st_orig.st_uid != st_undo.st_uid
&& st_undo.st_uid != getuid())
{
if (p_verbose > 0)
{
verbose_enter();
smsg((char_u *)_("Not reading undo file, owner differs: %s"),
file_name);
verbose_leave();
}
return;
}
#endif
}
else
file_name = name;
if (p_verbose > 0)
{
verbose_enter();
smsg((char_u *)_("Reading undo file: %s"), file_name);
verbose_leave();
}
fp = mch_fopen((char *)file_name, "r");
if (fp == NULL)
{
if (name != NULL || p_verbose > 0)
EMSG2(_("E822: Cannot open undo file for reading: %s"), file_name);
goto error;
}
bi.bi_buf = curbuf;
bi.bi_fp = fp;
/*
* Read the undo file header.
*/
if (fread(magic_buf, UF_START_MAGIC_LEN, 1, fp) != 1
|| memcmp(magic_buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0)
{
EMSG2(_("E823: Not an undo file: %s"), file_name);
goto error;
}
version = get2c(fp);
if (version == UF_VERSION_CRYPT)
{
#ifdef FEAT_CRYPT
if (*curbuf->b_p_key == NUL)
{
EMSG2(_("E832: Non-encrypted file has encrypted undo file: %s"),
file_name);
goto error;
}
bi.bi_state = crypt_create_from_file(fp, curbuf->b_p_key);
if (bi.bi_state == NULL)
{
EMSG2(_("E826: Undo file decryption failed: %s"), file_name);
goto error;
}
if (crypt_whole_undofile(bi.bi_state->method_nr))
{
bi.bi_buffer = alloc(CRYPT_BUF_SIZE);
if (bi.bi_buffer == NULL)
{
crypt_free_state(bi.bi_state);
bi.bi_state = NULL;
goto error;
}
bi.bi_avail = 0;
bi.bi_used = 0;
}
#else
EMSG2(_("E827: Undo file is encrypted: %s"), file_name);
goto error;
#endif
}
else if (version != UF_VERSION)
{
EMSG2(_("E824: Incompatible undo file: %s"), file_name);
goto error;
}
if (undo_read(&bi, read_hash, (size_t)UNDO_HASH_SIZE) == FAIL)
{
corruption_error("hash", file_name);
goto error;
}
line_count = (linenr_T)undo_read_4c(&bi);
if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0
|| line_count != curbuf->b_ml.ml_line_count)
{
if (p_verbose > 0 || name != NULL)
{
if (name == NULL)
verbose_enter();
give_warning((char_u *)
_("File contents changed, cannot use undo info"), TRUE);
if (name == NULL)
verbose_leave();
}
goto error;
}
/* Read undo data for "U" command. */
str_len = undo_read_4c(&bi);
if (str_len < 0)
goto error;
if (str_len > 0)
line_ptr = read_string_decrypt(&bi, str_len);
line_lnum = (linenr_T)undo_read_4c(&bi);
line_colnr = (colnr_T)undo_read_4c(&bi);
if (line_lnum < 0 || line_colnr < 0)
{
corruption_error("line lnum/col", file_name);
goto error;
}
/* Begin general undo data */
old_header_seq = undo_read_4c(&bi);
new_header_seq = undo_read_4c(&bi);
cur_header_seq = undo_read_4c(&bi);
num_head = undo_read_4c(&bi);
seq_last = undo_read_4c(&bi);
seq_cur = undo_read_4c(&bi);
seq_time = undo_read_time(&bi);
/* Optional header fields. */
for (;;)
{
int len = undo_read_byte(&bi);
int what;
if (len == 0 || len == EOF)
break;
what = undo_read_byte(&bi);
switch (what)
{
case UF_LAST_SAVE_NR:
last_save_nr = undo_read_4c(&bi);
break;
default:
/* field not supported, skip */
while (--len >= 0)
(void)undo_read_byte(&bi);
}
}
/* uhp_table will store the freshly created undo headers we allocate
* until we insert them into curbuf. The table remains sorted by the
* sequence numbers of the headers.
* When there are no headers uhp_table is NULL. */
if (num_head > 0)
{
uhp_table = (u_header_T **)U_ALLOC_LINE(
num_head * sizeof(u_header_T *));
if (uhp_table == NULL)
goto error;
}
while ((c = undo_read_2c(&bi)) == UF_HEADER_MAGIC)
{
if (num_read_uhps >= num_head)
{
corruption_error("num_head too small", file_name);
goto error;
}
uhp = unserialize_uhp(&bi, file_name);
if (uhp == NULL)
goto error;
uhp_table[num_read_uhps++] = uhp;
}
if (num_read_uhps != num_head)
{
corruption_error("num_head", file_name);
goto error;
}
if (c != UF_HEADER_END_MAGIC)
{
corruption_error("end marker", file_name);
goto error;
}
#ifdef U_DEBUG
uhp_table_used = (int *)alloc_clear(
(unsigned)(sizeof(int) * num_head + 1));
# define SET_FLAG(j) ++uhp_table_used[j]
#else
# define SET_FLAG(j)
#endif
/* We have put all of the headers into a table. Now we iterate through the
* table and swizzle each sequence number we have stored in uh_*_seq into
* a pointer corresponding to the header with that sequence number. */
for (i = 0; i < num_head; i++)
{
uhp = uhp_table[i];
if (uhp == NULL)
continue;
for (j = 0; j < num_head; j++)
if (uhp_table[j] != NULL && i != j
&& uhp_table[i]->uh_seq == uhp_table[j]->uh_seq)
{
corruption_error("duplicate uh_seq", file_name);
goto error;
}
for (j = 0; j < num_head; j++)
if (uhp_table[j] != NULL
&& uhp_table[j]->uh_seq == uhp->uh_next.seq)
{
uhp->uh_next.ptr = uhp_table[j];
SET_FLAG(j);
break;
}
for (j = 0; j < num_head; j++)
if (uhp_table[j] != NULL
&& uhp_table[j]->uh_seq == uhp->uh_prev.seq)
{
uhp->uh_prev.ptr = uhp_table[j];
SET_FLAG(j);
break;
}
for (j = 0; j < num_head; j++)
if (uhp_table[j] != NULL
&& uhp_table[j]->uh_seq == uhp->uh_alt_next.seq)
{
uhp->uh_alt_next.ptr = uhp_table[j];
SET_FLAG(j);
break;
}
for (j = 0; j < num_head; j++)
if (uhp_table[j] != NULL
&& uhp_table[j]->uh_seq == uhp->uh_alt_prev.seq)
{
uhp->uh_alt_prev.ptr = uhp_table[j];
SET_FLAG(j);
break;
}
if (old_header_seq > 0 && old_idx < 0 && uhp->uh_seq == old_header_seq)
{
old_idx = i;
SET_FLAG(i);
}
if (new_header_seq > 0 && new_idx < 0 && uhp->uh_seq == new_header_seq)
{
new_idx = i;
SET_FLAG(i);
}
if (cur_header_seq > 0 && cur_idx < 0 && uhp->uh_seq == cur_header_seq)
{
cur_idx = i;
SET_FLAG(i);
}
}
/* Now that we have read the undo info successfully, free the current undo
* info and use the info from the file. */
u_blockfree(curbuf);
curbuf->b_u_oldhead = old_idx < 0 ? NULL : uhp_table[old_idx];
curbuf->b_u_newhead = new_idx < 0 ? NULL : uhp_table[new_idx];
curbuf->b_u_curhead = cur_idx < 0 ? NULL : uhp_table[cur_idx];
curbuf->b_u_line_ptr = line_ptr;
curbuf->b_u_line_lnum = line_lnum;
curbuf->b_u_line_colnr = line_colnr;
curbuf->b_u_numhead = num_head;
curbuf->b_u_seq_last = seq_last;
curbuf->b_u_seq_cur = seq_cur;
curbuf->b_u_time_cur = seq_time;
curbuf->b_u_save_nr_last = last_save_nr;
curbuf->b_u_save_nr_cur = last_save_nr;
curbuf->b_u_synced = TRUE;
vim_free(uhp_table);
#ifdef U_DEBUG
for (i = 0; i < num_head; ++i)
if (uhp_table_used[i] == 0)
EMSGN("uhp_table entry %ld not used, leaking memory", i);
vim_free(uhp_table_used);
u_check(TRUE);
#endif
if (name != NULL)
smsg((char_u *)_("Finished reading undo file %s"), file_name);
goto theend;
error:
vim_free(line_ptr);
if (uhp_table != NULL)
{
for (i = 0; i < num_read_uhps; i++)
if (uhp_table[i] != NULL)
u_free_uhp(uhp_table[i]);
vim_free(uhp_table);
}
theend:
#ifdef FEAT_CRYPT
if (bi.bi_state != NULL)
crypt_free_state(bi.bi_state);
vim_free(bi.bi_buffer);
#endif
if (fp != NULL)
fclose(fp);
if (file_name != name)
vim_free(file_name);
return;
} | 1688 | True | 1 |
CVE-2017-6350 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/vim/vim/commit/0c8485f0e4931463c0f7986e1ea84a7d79f10c75', 'name': 'https://github.com/vim/vim/commit/0c8485f0e4931463c0f7986e1ea84a7d79f10c75', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://www.securityfocus.com/bid/96448', 'name': '96448', 'refsource': 'BID', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/201706-26', 'name': 'GLSA-201706-26', 'refsource': 'GENTOO', 'tags': []}, {'url': 'http://www.securitytracker.com/id/1037949', 'name': '1037949', 'refsource': 'SECTRACK', 'tags': []}, {'url': 'https://groups.google.com/forum/#!topic/vim_dev/QPZc0CY9j3Y', 'name': 'https://groups.google.com/forum/#!topic/vim_dev/QPZc0CY9j3Y', 'refsource': 'MISC', 'tags': []}, {'url': 'https://groups.google.com/forum/#!topic/vim_dev/L_dOHOOiQ5Q', 'name': 'https://groups.google.com/forum/#!topic/vim_dev/L_dOHOOiQ5Q', 'refsource': 'MISC', 'tags': []}, {'url': 'https://usn.ubuntu.com/4309-1/', 'name': 'USN-4309-1', 'refsource': 'UBUNTU', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-190'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndIncluding': '8.0.0377', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'An integer overflow at an unserialize_uep memory allocation site would occur for vim before patch 8.0.0378, if it does not properly validate values for tree length when reading a corrupted undo file, which may lead to resultant buffer overflows.'}] | 2018-08-13T21:47Z | 2017-02-27T07:59Z | Integer Overflow or Wraparound | The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
| https://cwe.mitre.org/data/definitions/190.html | 0 | Bram Moolenaar | 2017-02-26 18:17:10+01:00 | patch 8.0.0378: possible overflow when reading corrupted undo file
Problem: Another possible overflow when reading corrupted undo file.
Solution: Check if allocated size is not too big. (King) | 0c8485f0e4931463c0f7986e1ea84a7d79f10c75 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | unserialize_uep | unserialize_uep( bufinfo_T * bi , int * error , char_u * file_name) | ['bi', 'error', 'file_name'] | unserialize_uep(bufinfo_T *bi, int *error, char_u *file_name)
{
int i;
u_entry_T *uep;
char_u **array;
char_u *line;
int line_len;
uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T));
if (uep == NULL)
return NULL;
vim_memset(uep, 0, sizeof(u_entry_T));
#ifdef U_DEBUG
uep->ue_magic = UE_MAGIC;
#endif
uep->ue_top = undo_read_4c(bi);
uep->ue_bot = undo_read_4c(bi);
uep->ue_lcount = undo_read_4c(bi);
uep->ue_size = undo_read_4c(bi);
if (uep->ue_size > 0)
{
array = (char_u **)U_ALLOC_LINE(sizeof(char_u *) * uep->ue_size);
if (array == NULL)
{
*error = TRUE;
return uep;
}
vim_memset(array, 0, sizeof(char_u *) * uep->ue_size);
}
else
array = NULL;
uep->ue_array = array;
for (i = 0; i < uep->ue_size; ++i)
{
line_len = undo_read_4c(bi);
if (line_len >= 0)
line = read_string_decrypt(bi, line_len);
else
{
line = NULL;
corruption_error("line length", file_name);
}
if (line == NULL)
{
*error = TRUE;
return uep;
}
array[i] = line;
}
return uep;
} | 263 | True | 1 |
CVE-2017-17087 | False | False | False | False | AV:L/AC:L/Au:N/C:P/I:N/A:N | LOCAL | LOW | NONE | PARTIAL | NONE | NONE | 2.1 | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N | LOCAL | LOW | LOW | NONE | UNCHANGED | HIGH | NONE | NONE | 5.5 | MEDIUM | 1.8 | 3.6 | nan | [{'url': 'https://groups.google.com/d/msg/vim_dev/sRT9BtjLWMk/BRtSXNU4BwAJ', 'name': 'https://groups.google.com/d/msg/vim_dev/sRT9BtjLWMk/BRtSXNU4BwAJ', 'refsource': 'MISC', 'tags': ['Issue Tracking', 'Mailing List', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/commit/5a73e0ca54c77e067c3b12ea6f35e3e8681e8cf8', 'name': 'https://github.com/vim/vim/commit/5a73e0ca54c77e067c3b12ea6f35e3e8681e8cf8', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://security.cucumberlinux.com/security/details.php?id=166', 'name': 'http://security.cucumberlinux.com/security/details.php?id=166', 'refsource': 'MISC', 'tags': ['Issue Tracking', 'Third Party Advisory']}, {'url': 'http://openwall.com/lists/oss-security/2017/11/27/2', 'name': 'http://openwall.com/lists/oss-security/2017/11/27/2', 'refsource': 'MISC', 'tags': ['Mailing List']}, {'url': 'https://lists.debian.org/debian-lts-announce/2019/08/msg00003.html', 'name': '[debian-lts-announce] 20190803 [SECURITY] [DLA 1871-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4582-1/', 'name': 'USN-4582-1', 'refsource': 'UBUNTU', 'tags': ['Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2022/01/msg00003.html', 'name': '[debian-lts-announce] 20220110 [SECURITY] [DLA 2876-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-668'}]}] | LOW | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndExcluding': '8.0.1263', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:esm:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': "fileio.c in Vim prior to 8.0.1263 sets the group ownership of a .swp file to the editor's primary group (which may be different from the group ownership of the original file), which allows local users to obtain sensitive information by leveraging an applicable group membership, as demonstrated by /etc/shadow owned by root:shadow mode 0640, but /etc/.shadow.swp owned by root:users mode 0640, a different vulnerability than CVE-2017-1000382."}] | 2022-02-20T05:58Z | 2017-12-01T08:29Z | Exposure of Resource to Wrong Sphere | The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource. |
Resources such as files and directories may be inadvertently exposed through mechanisms such as insecure permissions, or when a program accidentally operates on the wrong object. For example, a program may intend that private files can only be provided to a specific user. This effectively defines a control sphere that is intended to prevent attackers from accessing these private files. If the file permissions are insecure, then parties other than the user will be able to access those files.
A separate control sphere might effectively require that the user can only access the private files, but not any other files on the system. If the program does not ensure that the user is only requesting private files, then the user might be able to access other files on the system.
In either case, the end result is that a resource has been exposed to the wrong party.
| https://cwe.mitre.org/data/definitions/668.html | 0 | Bram Moolenaar | 2017-11-04 21:35:01+01:00 | patch 8.0.1263: others can read the swap file if a user is careless
Problem: Others can read the swap file if a user is careless with his
primary group.
Solution: If the group permission allows for reading but the world
permissions doesn't, make sure the group is right. | 5a73e0ca54c77e067c3b12ea6f35e3e8681e8cf8 | False | vim/vim | The official Vim repository | 2015-08-18 21:03:56 | 2022-08-27 16:53:22 | https://www.vim.org | vim | 28298.0 | 4345.0 | readfile | readfile( char_u * fname , char_u * sfname , linenr_T from , linenr_T lines_to_skip , linenr_T lines_to_read , exarg_T * eap , int flags) | ['fname', 'sfname', 'from', 'lines_to_skip', 'lines_to_read', 'eap', 'flags'] | readfile(
char_u *fname,
char_u *sfname,
linenr_T from,
linenr_T lines_to_skip,
linenr_T lines_to_read,
exarg_T *eap, /* can be NULL! */
int flags)
{
int fd = 0;
int newfile = (flags & READ_NEW);
int check_readonly;
int filtering = (flags & READ_FILTER);
int read_stdin = (flags & READ_STDIN);
int read_buffer = (flags & READ_BUFFER);
int read_fifo = (flags & READ_FIFO);
int set_options = newfile || read_buffer
|| (eap != NULL && eap->read_edit);
linenr_T read_buf_lnum = 1; /* next line to read from curbuf */
colnr_T read_buf_col = 0; /* next char to read from this line */
char_u c;
linenr_T lnum = from;
char_u *ptr = NULL; /* pointer into read buffer */
char_u *buffer = NULL; /* read buffer */
char_u *new_buffer = NULL; /* init to shut up gcc */
char_u *line_start = NULL; /* init to shut up gcc */
int wasempty; /* buffer was empty before reading */
colnr_T len;
long size = 0;
char_u *p;
off_T filesize = 0;
int skip_read = FALSE;
#ifdef FEAT_CRYPT
char_u *cryptkey = NULL;
int did_ask_for_key = FALSE;
#endif
#ifdef FEAT_PERSISTENT_UNDO
context_sha256_T sha_ctx;
int read_undo_file = FALSE;
#endif
int split = 0; /* number of split lines */
#define UNKNOWN 0x0fffffff /* file size is unknown */
linenr_T linecnt;
int error = FALSE; /* errors encountered */
int ff_error = EOL_UNKNOWN; /* file format with errors */
long linerest = 0; /* remaining chars in line */
#ifdef UNIX
int perm = 0;
int swap_mode = -1; /* protection bits for swap file */
#else
int perm;
#endif
int fileformat = 0; /* end-of-line format */
int keep_fileformat = FALSE;
stat_T st;
int file_readonly;
linenr_T skip_count = 0;
linenr_T read_count = 0;
int msg_save = msg_scroll;
linenr_T read_no_eol_lnum = 0; /* non-zero lnum when last line of
* last read was missing the eol */
int try_mac;
int try_dos;
int try_unix;
int file_rewind = FALSE;
#ifdef FEAT_MBYTE
int can_retry;
linenr_T conv_error = 0; /* line nr with conversion error */
linenr_T illegal_byte = 0; /* line nr with illegal byte */
int keep_dest_enc = FALSE; /* don't retry when char doesn't fit
in destination encoding */
int bad_char_behavior = BAD_REPLACE;
/* BAD_KEEP, BAD_DROP or character to
* replace with */
char_u *tmpname = NULL; /* name of 'charconvert' output file */
int fio_flags = 0;
char_u *fenc; /* fileencoding to use */
int fenc_alloced; /* fenc_next is in allocated memory */
char_u *fenc_next = NULL; /* next item in 'fencs' or NULL */
int advance_fenc = FALSE;
long real_size = 0;
# ifdef USE_ICONV
iconv_t iconv_fd = (iconv_t)-1; /* descriptor for iconv() or -1 */
# ifdef FEAT_EVAL
int did_iconv = FALSE; /* TRUE when iconv() failed and trying
'charconvert' next */
# endif
# endif
int converted = FALSE; /* TRUE if conversion done */
int notconverted = FALSE; /* TRUE if conversion wanted but it
wasn't possible */
char_u conv_rest[CONV_RESTLEN];
int conv_restlen = 0; /* nr of bytes in conv_rest[] */
#endif
#ifdef FEAT_AUTOCMD
buf_T *old_curbuf;
char_u *old_b_ffname;
char_u *old_b_fname;
int using_b_ffname;
int using_b_fname;
#endif
#ifdef FEAT_AUTOCMD
au_did_filetype = FALSE; /* reset before triggering any autocommands */
#endif
curbuf->b_no_eol_lnum = 0; /* in case it was set by the previous read */
/*
* If there is no file name yet, use the one for the read file.
* BF_NOTEDITED is set to reflect this.
* Don't do this for a read from a filter.
* Only do this when 'cpoptions' contains the 'f' flag.
*/
if (curbuf->b_ffname == NULL
&& !filtering
&& fname != NULL
&& vim_strchr(p_cpo, CPO_FNAMER) != NULL
&& !(flags & READ_DUMMY))
{
if (set_rw_fname(fname, sfname) == FAIL)
return FAIL;
}
#ifdef FEAT_AUTOCMD
/* Remember the initial values of curbuf, curbuf->b_ffname and
* curbuf->b_fname to detect whether they are altered as a result of
* executing nasty autocommands. Also check if "fname" and "sfname"
* point to one of these values. */
old_curbuf = curbuf;
old_b_ffname = curbuf->b_ffname;
old_b_fname = curbuf->b_fname;
using_b_ffname = (fname == curbuf->b_ffname)
|| (sfname == curbuf->b_ffname);
using_b_fname = (fname == curbuf->b_fname) || (sfname == curbuf->b_fname);
#endif
/* After reading a file the cursor line changes but we don't want to
* display the line. */
ex_no_reprint = TRUE;
/* don't display the file info for another buffer now */
need_fileinfo = FALSE;
/*
* For Unix: Use the short file name whenever possible.
* Avoids problems with networks and when directory names are changed.
* Don't do this for MS-DOS, a "cd" in a sub-shell may have moved us to
* another directory, which we don't detect.
*/
if (sfname == NULL)
sfname = fname;
#if defined(UNIX)
fname = sfname;
#endif
#ifdef FEAT_AUTOCMD
/*
* The BufReadCmd and FileReadCmd events intercept the reading process by
* executing the associated commands instead.
*/
if (!filtering && !read_stdin && !read_buffer)
{
pos_T pos;
pos = curbuf->b_op_start;
/* Set '[ mark to the line above where the lines go (line 1 if zero). */
curbuf->b_op_start.lnum = ((from == 0) ? 1 : from);
curbuf->b_op_start.col = 0;
if (newfile)
{
if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname,
FALSE, curbuf, eap))
#ifdef FEAT_EVAL
return aborting() ? FAIL : OK;
#else
return OK;
#endif
}
else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname,
FALSE, NULL, eap))
#ifdef FEAT_EVAL
return aborting() ? FAIL : OK;
#else
return OK;
#endif
curbuf->b_op_start = pos;
}
#endif
if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0)
msg_scroll = FALSE; /* overwrite previous file message */
else
msg_scroll = TRUE; /* don't overwrite previous file message */
/*
* If the name ends in a path separator, we can't open it. Check here,
* because reading the file may actually work, but then creating the swap
* file may destroy it! Reported on MS-DOS and Win 95.
* If the name is too long we might crash further on, quit here.
*/
if (fname != NULL && *fname != NUL)
{
p = fname + STRLEN(fname);
if (after_pathsep(fname, p) || STRLEN(fname) >= MAXPATHL)
{
filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0);
msg_end();
msg_scroll = msg_save;
return FAIL;
}
}
if (!read_stdin && !read_buffer && !read_fifo)
{
#ifdef UNIX
/*
* On Unix it is possible to read a directory, so we have to
* check for it before the mch_open().
*/
perm = mch_getperm(fname);
if (perm >= 0 && !S_ISREG(perm) /* not a regular file ... */
# ifdef S_ISFIFO
&& !S_ISFIFO(perm) /* ... or fifo */
# endif
# ifdef S_ISSOCK
&& !S_ISSOCK(perm) /* ... or socket */
# endif
# ifdef OPEN_CHR_FILES
&& !(S_ISCHR(perm) && is_dev_fd_file(fname))
/* ... or a character special file named /dev/fd/<n> */
# endif
)
{
int retval = FAIL;
if (S_ISDIR(perm))
{
filemess(curbuf, fname, (char_u *)_("is a directory"), 0);
retval = NOTDONE;
}
else
filemess(curbuf, fname, (char_u *)_("is not a file"), 0);
msg_end();
msg_scroll = msg_save;
return retval;
}
#endif
#if defined(MSWIN)
/*
* MS-Windows allows opening a device, but we will probably get stuck
* trying to read it.
*/
if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE)
{
filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option)"), 0);
msg_end();
msg_scroll = msg_save;
return FAIL;
}
#endif
}
/* Set default or forced 'fileformat' and 'binary'. */
set_file_options(set_options, eap);
/*
* When opening a new file we take the readonly flag from the file.
* Default is r/w, can be set to r/o below.
* Don't reset it when in readonly mode
* Only set/reset b_p_ro when BF_CHECK_RO is set.
*/
check_readonly = (newfile && (curbuf->b_flags & BF_CHECK_RO));
if (check_readonly && !readonlymode)
curbuf->b_p_ro = FALSE;
if (newfile && !read_stdin && !read_buffer && !read_fifo)
{
/* Remember time of file. */
if (mch_stat((char *)fname, &st) >= 0)
{
buf_store_time(curbuf, &st, fname);
curbuf->b_mtime_read = curbuf->b_mtime;
#ifdef UNIX
/*
* Use the protection bits of the original file for the swap file.
* This makes it possible for others to read the name of the
* edited file from the swapfile, but only if they can read the
* edited file.
* Remove the "write" and "execute" bits for group and others
* (they must not write the swapfile).
* Add the "read" and "write" bits for the user, otherwise we may
* not be able to write to the file ourselves.
* Setting the bits is done below, after creating the swap file.
*/
swap_mode = (st.st_mode & 0644) | 0600;
#endif
#ifdef FEAT_CW_EDITOR
/* Get the FSSpec on MacOS
* TODO: Update it properly when the buffer name changes
*/
(void)GetFSSpecFromPath(curbuf->b_ffname, &curbuf->b_FSSpec);
#endif
#ifdef VMS
curbuf->b_fab_rfm = st.st_fab_rfm;
curbuf->b_fab_rat = st.st_fab_rat;
curbuf->b_fab_mrs = st.st_fab_mrs;
#endif
}
else
{
curbuf->b_mtime = 0;
curbuf->b_mtime_read = 0;
curbuf->b_orig_size = 0;
curbuf->b_orig_mode = 0;
}
/* Reset the "new file" flag. It will be set again below when the
* file doesn't exist. */
curbuf->b_flags &= ~(BF_NEW | BF_NEW_W);
}
/*
* for UNIX: check readonly with perm and mch_access()
* for Amiga: check readonly by trying to open the file for writing
*/
file_readonly = FALSE;
if (read_stdin)
{
#if defined(MSWIN)
/* Force binary I/O on stdin to avoid CR-LF -> LF conversion. */
setmode(0, O_BINARY);
#endif
}
else if (!read_buffer)
{
#ifdef USE_MCH_ACCESS
if (
# ifdef UNIX
!(perm & 0222) ||
# endif
mch_access((char *)fname, W_OK))
file_readonly = TRUE;
fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
#else
if (!newfile
|| readonlymode
|| (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0)
{
file_readonly = TRUE;
/* try to open ro */
fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
}
#endif
}
if (fd < 0) /* cannot open at all */
{
#ifndef UNIX
int isdir_f;
#endif
msg_scroll = msg_save;
#ifndef UNIX
/*
* On Amiga we can't open a directory, check here.
*/
isdir_f = (mch_isdir(fname));
perm = mch_getperm(fname); /* check if the file exists */
if (isdir_f)
{
filemess(curbuf, sfname, (char_u *)_("is a directory"), 0);
curbuf->b_p_ro = TRUE; /* must use "w!" now */
}
else
#endif
if (newfile)
{
if (perm < 0
#ifdef ENOENT
&& errno == ENOENT
#endif
)
{
/*
* Set the 'new-file' flag, so that when the file has
* been created by someone else, a ":w" will complain.
*/
curbuf->b_flags |= BF_NEW;
/* Create a swap file now, so that other Vims are warned
* that we are editing this file. Don't do this for a
* "nofile" or "nowrite" buffer type. */
#ifdef FEAT_QUICKFIX
if (!bt_dontwrite(curbuf))
#endif
{
check_need_swap(newfile);
#ifdef FEAT_AUTOCMD
/* SwapExists autocommand may mess things up */
if (curbuf != old_curbuf
|| (using_b_ffname
&& (old_b_ffname != curbuf->b_ffname))
|| (using_b_fname
&& (old_b_fname != curbuf->b_fname)))
{
EMSG(_(e_auchangedbuf));
return FAIL;
}
#endif
}
if (dir_of_file_exists(fname))
filemess(curbuf, sfname, (char_u *)_("[New File]"), 0);
else
filemess(curbuf, sfname,
(char_u *)_("[New DIRECTORY]"), 0);
#ifdef FEAT_VIMINFO
/* Even though this is a new file, it might have been
* edited before and deleted. Get the old marks. */
check_marks_read();
#endif
#ifdef FEAT_MBYTE
/* Set forced 'fileencoding'. */
if (eap != NULL)
set_forced_fenc(eap);
#endif
#ifdef FEAT_AUTOCMD
apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname,
FALSE, curbuf, eap);
#endif
/* remember the current fileformat */
save_file_ff(curbuf);
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
if (aborting()) /* autocmds may abort script processing */
return FAIL;
#endif
return OK; /* a new file is not an error */
}
else
{
filemess(curbuf, sfname, (char_u *)(
# ifdef EFBIG
(errno == EFBIG) ? _("[File too big]") :
# endif
# ifdef EOVERFLOW
(errno == EOVERFLOW) ? _("[File too big]") :
# endif
_("[Permission Denied]")), 0);
curbuf->b_p_ro = TRUE; /* must use "w!" now */
}
}
return FAIL;
}
/*
* Only set the 'ro' flag for readonly files the first time they are
* loaded. Help files always get readonly mode
*/
if ((check_readonly && file_readonly) || curbuf->b_help)
curbuf->b_p_ro = TRUE;
if (set_options)
{
/* Don't change 'eol' if reading from buffer as it will already be
* correctly set when reading stdin. */
if (!read_buffer)
{
curbuf->b_p_eol = TRUE;
curbuf->b_start_eol = TRUE;
}
#ifdef FEAT_MBYTE
curbuf->b_p_bomb = FALSE;
curbuf->b_start_bomb = FALSE;
#endif
}
/* Create a swap file now, so that other Vims are warned that we are
* editing this file.
* Don't do this for a "nofile" or "nowrite" buffer type. */
#ifdef FEAT_QUICKFIX
if (!bt_dontwrite(curbuf))
#endif
{
check_need_swap(newfile);
#ifdef FEAT_AUTOCMD
if (!read_stdin && (curbuf != old_curbuf
|| (using_b_ffname && (old_b_ffname != curbuf->b_ffname))
|| (using_b_fname && (old_b_fname != curbuf->b_fname))))
{
EMSG(_(e_auchangedbuf));
if (!read_buffer)
close(fd);
return FAIL;
}
#endif
#ifdef UNIX
/* Set swap file protection bits after creating it. */
if (swap_mode > 0 && curbuf->b_ml.ml_mfp != NULL
&& curbuf->b_ml.ml_mfp->mf_fname != NULL)
(void)mch_setperm(curbuf->b_ml.ml_mfp->mf_fname, (long)swap_mode);
#endif
}
#if defined(HAS_SWAP_EXISTS_ACTION)
/* If "Quit" selected at ATTENTION dialog, don't load the file */
if (swap_exists_action == SEA_QUIT)
{
if (!read_buffer && !read_stdin)
close(fd);
return FAIL;
}
#endif
++no_wait_return; /* don't wait for return yet */
/*
* Set '[ mark to the line above where the lines go (line 1 if zero).
*/
curbuf->b_op_start.lnum = ((from == 0) ? 1 : from);
curbuf->b_op_start.col = 0;
try_mac = (vim_strchr(p_ffs, 'm') != NULL);
try_dos = (vim_strchr(p_ffs, 'd') != NULL);
try_unix = (vim_strchr(p_ffs, 'x') != NULL);
#ifdef FEAT_AUTOCMD
if (!read_buffer)
{
int m = msg_scroll;
int n = msg_scrolled;
/*
* The file must be closed again, the autocommands may want to change
* the file before reading it.
*/
if (!read_stdin)
close(fd); /* ignore errors */
/*
* The output from the autocommands should not overwrite anything and
* should not be overwritten: Set msg_scroll, restore its value if no
* output was done.
*/
msg_scroll = TRUE;
if (filtering)
apply_autocmds_exarg(EVENT_FILTERREADPRE, NULL, sfname,
FALSE, curbuf, eap);
else if (read_stdin)
apply_autocmds_exarg(EVENT_STDINREADPRE, NULL, sfname,
FALSE, curbuf, eap);
else if (newfile)
apply_autocmds_exarg(EVENT_BUFREADPRE, NULL, sfname,
FALSE, curbuf, eap);
else
apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname,
FALSE, NULL, eap);
/* autocommands may have changed it */
try_mac = (vim_strchr(p_ffs, 'm') != NULL);
try_dos = (vim_strchr(p_ffs, 'd') != NULL);
try_unix = (vim_strchr(p_ffs, 'x') != NULL);
if (msg_scrolled == n)
msg_scroll = m;
#ifdef FEAT_EVAL
if (aborting()) /* autocmds may abort script processing */
{
--no_wait_return;
msg_scroll = msg_save;
curbuf->b_p_ro = TRUE; /* must use "w!" now */
return FAIL;
}
#endif
/*
* Don't allow the autocommands to change the current buffer.
* Try to re-open the file.
*
* Don't allow the autocommands to change the buffer name either
* (cd for example) if it invalidates fname or sfname.
*/
if (!read_stdin && (curbuf != old_curbuf
|| (using_b_ffname && (old_b_ffname != curbuf->b_ffname))
|| (using_b_fname && (old_b_fname != curbuf->b_fname))
|| (fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) < 0))
{
--no_wait_return;
msg_scroll = msg_save;
if (fd < 0)
EMSG(_("E200: *ReadPre autocommands made the file unreadable"));
else
EMSG(_("E201: *ReadPre autocommands must not change current buffer"));
curbuf->b_p_ro = TRUE; /* must use "w!" now */
return FAIL;
}
}
#endif /* FEAT_AUTOCMD */
/* Autocommands may add lines to the file, need to check if it is empty */
wasempty = (curbuf->b_ml.ml_flags & ML_EMPTY);
if (!recoverymode && !filtering && !(flags & READ_DUMMY))
{
/*
* Show the user that we are busy reading the input. Sometimes this
* may take a while. When reading from stdin another program may
* still be running, don't move the cursor to the last line, unless
* always using the GUI.
*/
if (read_stdin)
{
#ifndef ALWAYS_USE_GUI
mch_msg(_("Vim: Reading from stdin...\n"));
#endif
#ifdef FEAT_GUI
/* Also write a message in the GUI window, if there is one. */
if (gui.in_use && !gui.dying && !gui.starting)
{
p = (char_u *)_("Reading from stdin...");
gui_write(p, (int)STRLEN(p));
}
#endif
}
else if (!read_buffer)
filemess(curbuf, sfname, (char_u *)"", 0);
}
msg_scroll = FALSE; /* overwrite the file message */
/*
* Set linecnt now, before the "retry" caused by a wrong guess for
* fileformat, and after the autocommands, which may change them.
*/
linecnt = curbuf->b_ml.ml_line_count;
#ifdef FEAT_MBYTE
/* "++bad=" argument. */
if (eap != NULL && eap->bad_char != 0)
{
bad_char_behavior = eap->bad_char;
if (set_options)
curbuf->b_bad_char = eap->bad_char;
}
else
curbuf->b_bad_char = 0;
/*
* Decide which 'encoding' to use or use first.
*/
if (eap != NULL && eap->force_enc != 0)
{
fenc = enc_canonize(eap->cmd + eap->force_enc);
fenc_alloced = TRUE;
keep_dest_enc = TRUE;
}
else if (curbuf->b_p_bin)
{
fenc = (char_u *)""; /* binary: don't convert */
fenc_alloced = FALSE;
}
else if (curbuf->b_help)
{
char_u firstline[80];
int fc;
/* Help files are either utf-8 or latin1. Try utf-8 first, if this
* fails it must be latin1.
* Always do this when 'encoding' is "utf-8". Otherwise only do
* this when needed to avoid [converted] remarks all the time.
* It is needed when the first line contains non-ASCII characters.
* That is only in *.??x files. */
fenc = (char_u *)"latin1";
c = enc_utf8;
if (!c && !read_stdin)
{
fc = fname[STRLEN(fname) - 1];
if (TOLOWER_ASC(fc) == 'x')
{
/* Read the first line (and a bit more). Immediately rewind to
* the start of the file. If the read() fails "len" is -1. */
len = read_eintr(fd, firstline, 80);
vim_lseek(fd, (off_T)0L, SEEK_SET);
for (p = firstline; p < firstline + len; ++p)
if (*p >= 0x80)
{
c = TRUE;
break;
}
}
}
if (c)
{
fenc_next = fenc;
fenc = (char_u *)"utf-8";
/* When the file is utf-8 but a character doesn't fit in
* 'encoding' don't retry. In help text editing utf-8 bytes
* doesn't make sense. */
if (!enc_utf8)
keep_dest_enc = TRUE;
}
fenc_alloced = FALSE;
}
else if (*p_fencs == NUL)
{
fenc = curbuf->b_p_fenc; /* use format from buffer */
fenc_alloced = FALSE;
}
else
{
fenc_next = p_fencs; /* try items in 'fileencodings' */
fenc = next_fenc(&fenc_next);
fenc_alloced = TRUE;
}
#endif
/*
* Jump back here to retry reading the file in different ways.
* Reasons to retry:
* - encoding conversion failed: try another one from "fenc_next"
* - BOM detected and fenc was set, need to setup conversion
* - "fileformat" check failed: try another
*
* Variables set for special retry actions:
* "file_rewind" Rewind the file to start reading it again.
* "advance_fenc" Advance "fenc" using "fenc_next".
* "skip_read" Re-use already read bytes (BOM detected).
* "did_iconv" iconv() conversion failed, try 'charconvert'.
* "keep_fileformat" Don't reset "fileformat".
*
* Other status indicators:
* "tmpname" When != NULL did conversion with 'charconvert'.
* Output file has to be deleted afterwards.
* "iconv_fd" When != -1 did conversion with iconv().
*/
retry:
if (file_rewind)
{
if (read_buffer)
{
read_buf_lnum = 1;
read_buf_col = 0;
}
else if (read_stdin || vim_lseek(fd, (off_T)0L, SEEK_SET) != 0)
{
/* Can't rewind the file, give up. */
error = TRUE;
goto failed;
}
/* Delete the previously read lines. */
while (lnum > from)
ml_delete(lnum--, FALSE);
file_rewind = FALSE;
#ifdef FEAT_MBYTE
if (set_options)
{
curbuf->b_p_bomb = FALSE;
curbuf->b_start_bomb = FALSE;
}
conv_error = 0;
#endif
}
/*
* When retrying with another "fenc" and the first time "fileformat"
* will be reset.
*/
if (keep_fileformat)
keep_fileformat = FALSE;
else
{
if (eap != NULL && eap->force_ff != 0)
{
fileformat = get_fileformat_force(curbuf, eap);
try_unix = try_dos = try_mac = FALSE;
}
else if (curbuf->b_p_bin)
fileformat = EOL_UNIX; /* binary: use Unix format */
else if (*p_ffs == NUL)
fileformat = get_fileformat(curbuf);/* use format from buffer */
else
fileformat = EOL_UNKNOWN; /* detect from file */
}
#ifdef FEAT_MBYTE
# ifdef USE_ICONV
if (iconv_fd != (iconv_t)-1)
{
/* aborted conversion with iconv(), close the descriptor */
iconv_close(iconv_fd);
iconv_fd = (iconv_t)-1;
}
# endif
if (advance_fenc)
{
/*
* Try the next entry in 'fileencodings'.
*/
advance_fenc = FALSE;
if (eap != NULL && eap->force_enc != 0)
{
/* Conversion given with "++cc=" wasn't possible, read
* without conversion. */
notconverted = TRUE;
conv_error = 0;
if (fenc_alloced)
vim_free(fenc);
fenc = (char_u *)"";
fenc_alloced = FALSE;
}
else
{
if (fenc_alloced)
vim_free(fenc);
if (fenc_next != NULL)
{
fenc = next_fenc(&fenc_next);
fenc_alloced = (fenc_next != NULL);
}
else
{
fenc = (char_u *)"";
fenc_alloced = FALSE;
}
}
if (tmpname != NULL)
{
mch_remove(tmpname); /* delete converted file */
vim_free(tmpname);
tmpname = NULL;
}
}
/*
* Conversion may be required when the encoding of the file is different
* from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4.
*/
fio_flags = 0;
converted = need_conversion(fenc);
if (converted)
{
/* "ucs-bom" means we need to check the first bytes of the file
* for a BOM. */
if (STRCMP(fenc, ENC_UCSBOM) == 0)
fio_flags = FIO_UCSBOM;
/*
* Check if UCS-2/4 or Latin1 to UTF-8 conversion needs to be
* done. This is handled below after read(). Prepare the
* fio_flags to avoid having to parse the string each time.
* Also check for Unicode to Latin1 conversion, because iconv()
* appears not to handle this correctly. This works just like
* conversion to UTF-8 except how the resulting character is put in
* the buffer.
*/
else if (enc_utf8 || STRCMP(p_enc, "latin1") == 0)
fio_flags = get_fio_flags(fenc);
# ifdef WIN3264
/*
* Conversion from an MS-Windows codepage to UTF-8 or another codepage
* is handled with MultiByteToWideChar().
*/
if (fio_flags == 0)
fio_flags = get_win_fio_flags(fenc);
# endif
# ifdef MACOS_CONVERT
/* Conversion from Apple MacRoman to latin1 or UTF-8 */
if (fio_flags == 0)
fio_flags = get_mac_fio_flags(fenc);
# endif
# ifdef USE_ICONV
/*
* Try using iconv() if we can't convert internally.
*/
if (fio_flags == 0
# ifdef FEAT_EVAL
&& !did_iconv
# endif
)
iconv_fd = (iconv_t)my_iconv_open(
enc_utf8 ? (char_u *)"utf-8" : p_enc, fenc);
# endif
# ifdef FEAT_EVAL
/*
* Use the 'charconvert' expression when conversion is required
* and we can't do it internally or with iconv().
*/
if (fio_flags == 0 && !read_stdin && !read_buffer && *p_ccv != NUL
&& !read_fifo
# ifdef USE_ICONV
&& iconv_fd == (iconv_t)-1
# endif
)
{
# ifdef USE_ICONV
did_iconv = FALSE;
# endif
/* Skip conversion when it's already done (retry for wrong
* "fileformat"). */
if (tmpname == NULL)
{
tmpname = readfile_charconvert(fname, fenc, &fd);
if (tmpname == NULL)
{
/* Conversion failed. Try another one. */
advance_fenc = TRUE;
if (fd < 0)
{
/* Re-opening the original file failed! */
EMSG(_("E202: Conversion made file unreadable!"));
error = TRUE;
goto failed;
}
goto retry;
}
}
}
else
# endif
{
if (fio_flags == 0
# ifdef USE_ICONV
&& iconv_fd == (iconv_t)-1
# endif
)
{
/* Conversion wanted but we can't.
* Try the next conversion in 'fileencodings' */
advance_fenc = TRUE;
goto retry;
}
}
}
/* Set "can_retry" when it's possible to rewind the file and try with
* another "fenc" value. It's FALSE when no other "fenc" to try, reading
* stdin or fixed at a specific encoding. */
can_retry = (*fenc != NUL && !read_stdin && !read_fifo && !keep_dest_enc);
#endif
if (!skip_read)
{
linerest = 0;
filesize = 0;
skip_count = lines_to_skip;
read_count = lines_to_read;
#ifdef FEAT_MBYTE
conv_restlen = 0;
#endif
#ifdef FEAT_PERSISTENT_UNDO
read_undo_file = (newfile && (flags & READ_KEEP_UNDO) == 0
&& curbuf->b_ffname != NULL
&& curbuf->b_p_udf
&& !filtering
&& !read_fifo
&& !read_stdin
&& !read_buffer);
if (read_undo_file)
sha256_start(&sha_ctx);
#endif
#ifdef FEAT_CRYPT
if (curbuf->b_cryptstate != NULL)
{
/* Need to free the state, but keep the key, don't want to ask for
* it again. */
crypt_free_state(curbuf->b_cryptstate);
curbuf->b_cryptstate = NULL;
}
#endif
}
while (!error && !got_int)
{
/*
* We allocate as much space for the file as we can get, plus
* space for the old line plus room for one terminating NUL.
* The amount is limited by the fact that read() only can read
* upto max_unsigned characters (and other things).
*/
#if VIM_SIZEOF_INT <= 2
if (linerest >= 0x7ff0)
{
++split;
*ptr = NL; /* split line by inserting a NL */
size = 1;
}
else
#endif
{
if (!skip_read)
{
#if VIM_SIZEOF_INT > 2
# if defined(SSIZE_MAX) && (SSIZE_MAX < 0x10000L)
size = SSIZE_MAX; /* use max I/O size, 52K */
# else
size = 0x10000L; /* use buffer >= 64K */
# endif
#else
size = 0x7ff0L - linerest; /* limit buffer to 32K */
#endif
for ( ; size >= 10; size = (long)((long_u)size >> 1))
{
if ((new_buffer = lalloc((long_u)(size + linerest + 1),
FALSE)) != NULL)
break;
}
if (new_buffer == NULL)
{
do_outofmem_msg((long_u)(size * 2 + linerest + 1));
error = TRUE;
break;
}
if (linerest) /* copy characters from the previous buffer */
mch_memmove(new_buffer, ptr - linerest, (size_t)linerest);
vim_free(buffer);
buffer = new_buffer;
ptr = buffer + linerest;
line_start = buffer;
#ifdef FEAT_MBYTE
/* May need room to translate into.
* For iconv() we don't really know the required space, use a
* factor ICONV_MULT.
* latin1 to utf-8: 1 byte becomes up to 2 bytes
* utf-16 to utf-8: 2 bytes become up to 3 bytes, 4 bytes
* become up to 4 bytes, size must be multiple of 2
* ucs-2 to utf-8: 2 bytes become up to 3 bytes, size must be
* multiple of 2
* ucs-4 to utf-8: 4 bytes become up to 6 bytes, size must be
* multiple of 4 */
real_size = (int)size;
# ifdef USE_ICONV
if (iconv_fd != (iconv_t)-1)
size = size / ICONV_MULT;
else
# endif
if (fio_flags & FIO_LATIN1)
size = size / 2;
else if (fio_flags & (FIO_UCS2 | FIO_UTF16))
size = (size * 2 / 3) & ~1;
else if (fio_flags & FIO_UCS4)
size = (size * 2 / 3) & ~3;
else if (fio_flags == FIO_UCSBOM)
size = size / ICONV_MULT; /* worst case */
# ifdef WIN3264
else if (fio_flags & FIO_CODEPAGE)
size = size / ICONV_MULT; /* also worst case */
# endif
# ifdef MACOS_CONVERT
else if (fio_flags & FIO_MACROMAN)
size = size / ICONV_MULT; /* also worst case */
# endif
#endif
#ifdef FEAT_MBYTE
if (conv_restlen > 0)
{
/* Insert unconverted bytes from previous line. */
mch_memmove(ptr, conv_rest, conv_restlen);
ptr += conv_restlen;
size -= conv_restlen;
}
#endif
if (read_buffer)
{
/*
* Read bytes from curbuf. Used for converting text read
* from stdin.
*/
if (read_buf_lnum > from)
size = 0;
else
{
int n, ni;
long tlen;
tlen = 0;
for (;;)
{
p = ml_get(read_buf_lnum) + read_buf_col;
n = (int)STRLEN(p);
if ((int)tlen + n + 1 > size)
{
/* Filled up to "size", append partial line.
* Change NL to NUL to reverse the effect done
* below. */
n = (int)(size - tlen);
for (ni = 0; ni < n; ++ni)
{
if (p[ni] == NL)
ptr[tlen++] = NUL;
else
ptr[tlen++] = p[ni];
}
read_buf_col += n;
break;
}
else
{
/* Append whole line and new-line. Change NL
* to NUL to reverse the effect done below. */
for (ni = 0; ni < n; ++ni)
{
if (p[ni] == NL)
ptr[tlen++] = NUL;
else
ptr[tlen++] = p[ni];
}
ptr[tlen++] = NL;
read_buf_col = 0;
if (++read_buf_lnum > from)
{
/* When the last line didn't have an
* end-of-line don't add it now either. */
if (!curbuf->b_p_eol)
--tlen;
size = tlen;
break;
}
}
}
}
}
else
{
/*
* Read bytes from the file.
*/
size = read_eintr(fd, ptr, size);
}
#ifdef FEAT_CRYPT
/*
* At start of file: Check for magic number of encryption.
*/
if (filesize == 0 && size > 0)
cryptkey = check_for_cryptkey(cryptkey, ptr, &size,
&filesize, newfile, sfname,
&did_ask_for_key);
/*
* Decrypt the read bytes. This is done before checking for
* EOF because the crypt layer may be buffering.
*/
if (cryptkey != NULL && curbuf->b_cryptstate != NULL
&& size > 0)
{
if (crypt_works_inplace(curbuf->b_cryptstate))
{
crypt_decode_inplace(curbuf->b_cryptstate, ptr, size);
}
else
{
char_u *newptr = NULL;
int decrypted_size;
decrypted_size = crypt_decode_alloc(
curbuf->b_cryptstate, ptr, size, &newptr);
/* If the crypt layer is buffering, not producing
* anything yet, need to read more. */
if (size > 0 && decrypted_size == 0)
continue;
if (linerest == 0)
{
/* Simple case: reuse returned buffer (may be
* NULL, checked later). */
new_buffer = newptr;
}
else
{
long_u new_size;
/* Need new buffer to add bytes carried over. */
new_size = (long_u)(decrypted_size + linerest + 1);
new_buffer = lalloc(new_size, FALSE);
if (new_buffer == NULL)
{
do_outofmem_msg(new_size);
error = TRUE;
break;
}
mch_memmove(new_buffer, buffer, linerest);
if (newptr != NULL)
mch_memmove(new_buffer + linerest, newptr,
decrypted_size);
}
if (new_buffer != NULL)
{
vim_free(buffer);
buffer = new_buffer;
new_buffer = NULL;
line_start = buffer;
ptr = buffer + linerest;
}
size = decrypted_size;
}
}
#endif
if (size <= 0)
{
if (size < 0) /* read error */
error = TRUE;
#ifdef FEAT_MBYTE
else if (conv_restlen > 0)
{
/*
* Reached end-of-file but some trailing bytes could
* not be converted. Truncated file?
*/
/* When we did a conversion report an error. */
if (fio_flags != 0
# ifdef USE_ICONV
|| iconv_fd != (iconv_t)-1
# endif
)
{
if (can_retry)
goto rewind_retry;
if (conv_error == 0)
conv_error = curbuf->b_ml.ml_line_count
- linecnt + 1;
}
/* Remember the first linenr with an illegal byte */
else if (illegal_byte == 0)
illegal_byte = curbuf->b_ml.ml_line_count
- linecnt + 1;
if (bad_char_behavior == BAD_DROP)
{
*(ptr - conv_restlen) = NUL;
conv_restlen = 0;
}
else
{
/* Replace the trailing bytes with the replacement
* character if we were converting; if we weren't,
* leave the UTF8 checking code to do it, as it
* works slightly differently. */
if (bad_char_behavior != BAD_KEEP && (fio_flags != 0
# ifdef USE_ICONV
|| iconv_fd != (iconv_t)-1
# endif
))
{
while (conv_restlen > 0)
{
*(--ptr) = bad_char_behavior;
--conv_restlen;
}
}
fio_flags = 0; /* don't convert this */
# ifdef USE_ICONV
if (iconv_fd != (iconv_t)-1)
{
iconv_close(iconv_fd);
iconv_fd = (iconv_t)-1;
}
# endif
}
}
#endif
}
}
skip_read = FALSE;
#ifdef FEAT_MBYTE
/*
* At start of file (or after crypt magic number): Check for BOM.
* Also check for a BOM for other Unicode encodings, but not after
* converting with 'charconvert' or when a BOM has already been
* found.
*/
if ((filesize == 0
# ifdef FEAT_CRYPT
|| (cryptkey != NULL
&& filesize == crypt_get_header_len(
crypt_get_method_nr(curbuf)))
# endif
)
&& (fio_flags == FIO_UCSBOM
|| (!curbuf->b_p_bomb
&& tmpname == NULL
&& (*fenc == 'u' || (*fenc == NUL && enc_utf8)))))
{
char_u *ccname;
int blen;
/* no BOM detection in a short file or in binary mode */
if (size < 2 || curbuf->b_p_bin)
ccname = NULL;
else
ccname = check_for_bom(ptr, size, &blen,
fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc));
if (ccname != NULL)
{
/* Remove BOM from the text */
filesize += blen;
size -= blen;
mch_memmove(ptr, ptr + blen, (size_t)size);
if (set_options)
{
curbuf->b_p_bomb = TRUE;
curbuf->b_start_bomb = TRUE;
}
}
if (fio_flags == FIO_UCSBOM)
{
if (ccname == NULL)
{
/* No BOM detected: retry with next encoding. */
advance_fenc = TRUE;
}
else
{
/* BOM detected: set "fenc" and jump back */
if (fenc_alloced)
vim_free(fenc);
fenc = ccname;
fenc_alloced = FALSE;
}
/* retry reading without getting new bytes or rewinding */
skip_read = TRUE;
goto retry;
}
}
/* Include not converted bytes. */
ptr -= conv_restlen;
size += conv_restlen;
conv_restlen = 0;
#endif
/*
* Break here for a read error or end-of-file.
*/
if (size <= 0)
break;
#ifdef FEAT_MBYTE
# ifdef USE_ICONV
if (iconv_fd != (iconv_t)-1)
{
/*
* Attempt conversion of the read bytes to 'encoding' using
* iconv().
*/
const char *fromp;
char *top;
size_t from_size;
size_t to_size;
fromp = (char *)ptr;
from_size = size;
ptr += size;
top = (char *)ptr;
to_size = real_size - size;
/*
* If there is conversion error or not enough room try using
* another conversion. Except for when there is no
* alternative (help files).
*/
while ((iconv(iconv_fd, (void *)&fromp, &from_size,
&top, &to_size)
== (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL)
|| from_size > CONV_RESTLEN)
{
if (can_retry)
goto rewind_retry;
if (conv_error == 0)
conv_error = readfile_linenr(linecnt,
ptr, (char_u *)top);
/* Deal with a bad byte and continue with the next. */
++fromp;
--from_size;
if (bad_char_behavior == BAD_KEEP)
{
*top++ = *(fromp - 1);
--to_size;
}
else if (bad_char_behavior != BAD_DROP)
{
*top++ = bad_char_behavior;
--to_size;
}
}
if (from_size > 0)
{
/* Some remaining characters, keep them for the next
* round. */
mch_memmove(conv_rest, (char_u *)fromp, from_size);
conv_restlen = (int)from_size;
}
/* move the linerest to before the converted characters */
line_start = ptr - linerest;
mch_memmove(line_start, buffer, (size_t)linerest);
size = (long)((char_u *)top - ptr);
}
# endif
# ifdef WIN3264
if (fio_flags & FIO_CODEPAGE)
{
char_u *src, *dst;
WCHAR ucs2buf[3];
int ucs2len;
int codepage = FIO_GET_CP(fio_flags);
int bytelen;
int found_bad;
char replstr[2];
/*
* Conversion from an MS-Windows codepage or UTF-8 to UTF-8 or
* a codepage, using standard MS-Windows functions. This
* requires two steps:
* 1. convert from 'fileencoding' to ucs-2
* 2. convert from ucs-2 to 'encoding'
*
* Because there may be illegal bytes AND an incomplete byte
* sequence at the end, we may have to do the conversion one
* character at a time to get it right.
*/
/* Replacement string for WideCharToMultiByte(). */
if (bad_char_behavior > 0)
replstr[0] = bad_char_behavior;
else
replstr[0] = '?';
replstr[1] = NUL;
/*
* Move the bytes to the end of the buffer, so that we have
* room to put the result at the start.
*/
src = ptr + real_size - size;
mch_memmove(src, ptr, size);
/*
* Do the conversion.
*/
dst = ptr;
size = size;
while (size > 0)
{
found_bad = FALSE;
# ifdef CP_UTF8 /* VC 4.1 doesn't define CP_UTF8 */
if (codepage == CP_UTF8)
{
/* Handle CP_UTF8 input ourselves to be able to handle
* trailing bytes properly.
* Get one UTF-8 character from src. */
bytelen = (int)utf_ptr2len_len(src, size);
if (bytelen > size)
{
/* Only got some bytes of a character. Normally
* it's put in "conv_rest", but if it's too long
* deal with it as if they were illegal bytes. */
if (bytelen <= CONV_RESTLEN)
break;
/* weird overlong byte sequence */
bytelen = size;
found_bad = TRUE;
}
else
{
int u8c = utf_ptr2char(src);
if (u8c > 0xffff || (*src >= 0x80 && bytelen == 1))
found_bad = TRUE;
ucs2buf[0] = u8c;
ucs2len = 1;
}
}
else
# endif
{
/* We don't know how long the byte sequence is, try
* from one to three bytes. */
for (bytelen = 1; bytelen <= size && bytelen <= 3;
++bytelen)
{
ucs2len = MultiByteToWideChar(codepage,
MB_ERR_INVALID_CHARS,
(LPCSTR)src, bytelen,
ucs2buf, 3);
if (ucs2len > 0)
break;
}
if (ucs2len == 0)
{
/* If we have only one byte then it's probably an
* incomplete byte sequence. Otherwise discard
* one byte as a bad character. */
if (size == 1)
break;
found_bad = TRUE;
bytelen = 1;
}
}
if (!found_bad)
{
int i;
/* Convert "ucs2buf[ucs2len]" to 'enc' in "dst". */
if (enc_utf8)
{
/* From UCS-2 to UTF-8. Cannot fail. */
for (i = 0; i < ucs2len; ++i)
dst += utf_char2bytes(ucs2buf[i], dst);
}
else
{
BOOL bad = FALSE;
int dstlen;
/* From UCS-2 to "enc_codepage". If the
* conversion uses the default character "?",
* the data doesn't fit in this encoding. */
dstlen = WideCharToMultiByte(enc_codepage, 0,
(LPCWSTR)ucs2buf, ucs2len,
(LPSTR)dst, (int)(src - dst),
replstr, &bad);
if (bad)
found_bad = TRUE;
else
dst += dstlen;
}
}
if (found_bad)
{
/* Deal with bytes we can't convert. */
if (can_retry)
goto rewind_retry;
if (conv_error == 0)
conv_error = readfile_linenr(linecnt, ptr, dst);
if (bad_char_behavior != BAD_DROP)
{
if (bad_char_behavior == BAD_KEEP)
{
mch_memmove(dst, src, bytelen);
dst += bytelen;
}
else
*dst++ = bad_char_behavior;
}
}
src += bytelen;
size -= bytelen;
}
if (size > 0)
{
/* An incomplete byte sequence remaining. */
mch_memmove(conv_rest, src, size);
conv_restlen = size;
}
/* The new size is equal to how much "dst" was advanced. */
size = (long)(dst - ptr);
}
else
# endif
# ifdef MACOS_CONVERT
if (fio_flags & FIO_MACROMAN)
{
/*
* Conversion from Apple MacRoman char encoding to UTF-8 or
* latin1. This is in os_mac_conv.c.
*/
if (macroman2enc(ptr, &size, real_size) == FAIL)
goto rewind_retry;
}
else
# endif
if (fio_flags != 0)
{
int u8c;
char_u *dest;
char_u *tail = NULL;
/*
* "enc_utf8" set: Convert Unicode or Latin1 to UTF-8.
* "enc_utf8" not set: Convert Unicode to Latin1.
* Go from end to start through the buffer, because the number
* of bytes may increase.
* "dest" points to after where the UTF-8 bytes go, "p" points
* to after the next character to convert.
*/
dest = ptr + real_size;
if (fio_flags == FIO_LATIN1 || fio_flags == FIO_UTF8)
{
p = ptr + size;
if (fio_flags == FIO_UTF8)
{
/* Check for a trailing incomplete UTF-8 sequence */
tail = ptr + size - 1;
while (tail > ptr && (*tail & 0xc0) == 0x80)
--tail;
if (tail + utf_byte2len(*tail) <= ptr + size)
tail = NULL;
else
p = tail;
}
}
else if (fio_flags & (FIO_UCS2 | FIO_UTF16))
{
/* Check for a trailing byte */
p = ptr + (size & ~1);
if (size & 1)
tail = p;
if ((fio_flags & FIO_UTF16) && p > ptr)
{
/* Check for a trailing leading word */
if (fio_flags & FIO_ENDIAN_L)
{
u8c = (*--p << 8);
u8c += *--p;
}
else
{
u8c = *--p;
u8c += (*--p << 8);
}
if (u8c >= 0xd800 && u8c <= 0xdbff)
tail = p;
else
p += 2;
}
}
else /* FIO_UCS4 */
{
/* Check for trailing 1, 2 or 3 bytes */
p = ptr + (size & ~3);
if (size & 3)
tail = p;
}
/* If there is a trailing incomplete sequence move it to
* conv_rest[]. */
if (tail != NULL)
{
conv_restlen = (int)((ptr + size) - tail);
mch_memmove(conv_rest, (char_u *)tail, conv_restlen);
size -= conv_restlen;
}
while (p > ptr)
{
if (fio_flags & FIO_LATIN1)
u8c = *--p;
else if (fio_flags & (FIO_UCS2 | FIO_UTF16))
{
if (fio_flags & FIO_ENDIAN_L)
{
u8c = (*--p << 8);
u8c += *--p;
}
else
{
u8c = *--p;
u8c += (*--p << 8);
}
if ((fio_flags & FIO_UTF16)
&& u8c >= 0xdc00 && u8c <= 0xdfff)
{
int u16c;
if (p == ptr)
{
/* Missing leading word. */
if (can_retry)
goto rewind_retry;
if (conv_error == 0)
conv_error = readfile_linenr(linecnt,
ptr, p);
if (bad_char_behavior == BAD_DROP)
continue;
if (bad_char_behavior != BAD_KEEP)
u8c = bad_char_behavior;
}
/* found second word of double-word, get the first
* word and compute the resulting character */
if (fio_flags & FIO_ENDIAN_L)
{
u16c = (*--p << 8);
u16c += *--p;
}
else
{
u16c = *--p;
u16c += (*--p << 8);
}
u8c = 0x10000 + ((u16c & 0x3ff) << 10)
+ (u8c & 0x3ff);
/* Check if the word is indeed a leading word. */
if (u16c < 0xd800 || u16c > 0xdbff)
{
if (can_retry)
goto rewind_retry;
if (conv_error == 0)
conv_error = readfile_linenr(linecnt,
ptr, p);
if (bad_char_behavior == BAD_DROP)
continue;
if (bad_char_behavior != BAD_KEEP)
u8c = bad_char_behavior;
}
}
}
else if (fio_flags & FIO_UCS4)
{
if (fio_flags & FIO_ENDIAN_L)
{
u8c = (unsigned)*--p << 24;
u8c += (unsigned)*--p << 16;
u8c += (unsigned)*--p << 8;
u8c += *--p;
}
else /* big endian */
{
u8c = *--p;
u8c += (unsigned)*--p << 8;
u8c += (unsigned)*--p << 16;
u8c += (unsigned)*--p << 24;
}
}
else /* UTF-8 */
{
if (*--p < 0x80)
u8c = *p;
else
{
len = utf_head_off(ptr, p);
p -= len;
u8c = utf_ptr2char(p);
if (len == 0)
{
/* Not a valid UTF-8 character, retry with
* another fenc when possible, otherwise just
* report the error. */
if (can_retry)
goto rewind_retry;
if (conv_error == 0)
conv_error = readfile_linenr(linecnt,
ptr, p);
if (bad_char_behavior == BAD_DROP)
continue;
if (bad_char_behavior != BAD_KEEP)
u8c = bad_char_behavior;
}
}
}
if (enc_utf8) /* produce UTF-8 */
{
dest -= utf_char2len(u8c);
(void)utf_char2bytes(u8c, dest);
}
else /* produce Latin1 */
{
--dest;
if (u8c >= 0x100)
{
/* character doesn't fit in latin1, retry with
* another fenc when possible, otherwise just
* report the error. */
if (can_retry)
goto rewind_retry;
if (conv_error == 0)
conv_error = readfile_linenr(linecnt, ptr, p);
if (bad_char_behavior == BAD_DROP)
++dest;
else if (bad_char_behavior == BAD_KEEP)
*dest = u8c;
else if (eap != NULL && eap->bad_char != 0)
*dest = bad_char_behavior;
else
*dest = 0xBF;
}
else
*dest = u8c;
}
}
/* move the linerest to before the converted characters */
line_start = dest - linerest;
mch_memmove(line_start, buffer, (size_t)linerest);
size = (long)((ptr + real_size) - dest);
ptr = dest;
}
else if (enc_utf8 && !curbuf->b_p_bin)
{
int incomplete_tail = FALSE;
/* Reading UTF-8: Check if the bytes are valid UTF-8. */
for (p = ptr; ; ++p)
{
int todo = (int)((ptr + size) - p);
int l;
if (todo <= 0)
break;
if (*p >= 0x80)
{
/* A length of 1 means it's an illegal byte. Accept
* an incomplete character at the end though, the next
* read() will get the next bytes, we'll check it
* then. */
l = utf_ptr2len_len(p, todo);
if (l > todo && !incomplete_tail)
{
/* Avoid retrying with a different encoding when
* a truncated file is more likely, or attempting
* to read the rest of an incomplete sequence when
* we have already done so. */
if (p > ptr || filesize > 0)
incomplete_tail = TRUE;
/* Incomplete byte sequence, move it to conv_rest[]
* and try to read the rest of it, unless we've
* already done so. */
if (p > ptr)
{
conv_restlen = todo;
mch_memmove(conv_rest, p, conv_restlen);
size -= conv_restlen;
break;
}
}
if (l == 1 || l > todo)
{
/* Illegal byte. If we can try another encoding
* do that, unless at EOF where a truncated
* file is more likely than a conversion error. */
if (can_retry && !incomplete_tail)
break;
# ifdef USE_ICONV
/* When we did a conversion report an error. */
if (iconv_fd != (iconv_t)-1 && conv_error == 0)
conv_error = readfile_linenr(linecnt, ptr, p);
# endif
/* Remember the first linenr with an illegal byte */
if (conv_error == 0 && illegal_byte == 0)
illegal_byte = readfile_linenr(linecnt, ptr, p);
/* Drop, keep or replace the bad byte. */
if (bad_char_behavior == BAD_DROP)
{
mch_memmove(p, p + 1, todo - 1);
--p;
--size;
}
else if (bad_char_behavior != BAD_KEEP)
*p = bad_char_behavior;
}
else
p += l - 1;
}
}
if (p < ptr + size && !incomplete_tail)
{
/* Detected a UTF-8 error. */
rewind_retry:
/* Retry reading with another conversion. */
# if defined(FEAT_EVAL) && defined(USE_ICONV)
if (*p_ccv != NUL && iconv_fd != (iconv_t)-1)
/* iconv() failed, try 'charconvert' */
did_iconv = TRUE;
else
# endif
/* use next item from 'fileencodings' */
advance_fenc = TRUE;
file_rewind = TRUE;
goto retry;
}
}
#endif
/* count the number of characters (after conversion!) */
filesize += size;
/*
* when reading the first part of a file: guess EOL type
*/
if (fileformat == EOL_UNKNOWN)
{
/* First try finding a NL, for Dos and Unix */
if (try_dos || try_unix)
{
/* Reset the carriage return counter. */
if (try_mac)
try_mac = 1;
for (p = ptr; p < ptr + size; ++p)
{
if (*p == NL)
{
if (!try_unix
|| (try_dos && p > ptr && p[-1] == CAR))
fileformat = EOL_DOS;
else
fileformat = EOL_UNIX;
break;
}
else if (*p == CAR && try_mac)
try_mac++;
}
/* Don't give in to EOL_UNIX if EOL_MAC is more likely */
if (fileformat == EOL_UNIX && try_mac)
{
/* Need to reset the counters when retrying fenc. */
try_mac = 1;
try_unix = 1;
for (; p >= ptr && *p != CAR; p--)
;
if (p >= ptr)
{
for (p = ptr; p < ptr + size; ++p)
{
if (*p == NL)
try_unix++;
else if (*p == CAR)
try_mac++;
}
if (try_mac > try_unix)
fileformat = EOL_MAC;
}
}
else if (fileformat == EOL_UNKNOWN && try_mac == 1)
/* Looking for CR but found no end-of-line markers at
* all: use the default format. */
fileformat = default_fileformat();
}
/* No NL found: may use Mac format */
if (fileformat == EOL_UNKNOWN && try_mac)
fileformat = EOL_MAC;
/* Still nothing found? Use first format in 'ffs' */
if (fileformat == EOL_UNKNOWN)
fileformat = default_fileformat();
/* if editing a new file: may set p_tx and p_ff */
if (set_options)
set_fileformat(fileformat, OPT_LOCAL);
}
}
/*
* This loop is executed once for every character read.
* Keep it fast!
*/
if (fileformat == EOL_MAC)
{
--ptr;
while (++ptr, --size >= 0)
{
/* catch most common case first */
if ((c = *ptr) != NUL && c != CAR && c != NL)
continue;
if (c == NUL)
*ptr = NL; /* NULs are replaced by newlines! */
else if (c == NL)
*ptr = CAR; /* NLs are replaced by CRs! */
else
{
if (skip_count == 0)
{
*ptr = NUL; /* end of line */
len = (colnr_T) (ptr - line_start + 1);
if (ml_append(lnum, line_start, len, newfile) == FAIL)
{
error = TRUE;
break;
}
#ifdef FEAT_PERSISTENT_UNDO
if (read_undo_file)
sha256_update(&sha_ctx, line_start, len);
#endif
++lnum;
if (--read_count == 0)
{
error = TRUE; /* break loop */
line_start = ptr; /* nothing left to write */
break;
}
}
else
--skip_count;
line_start = ptr + 1;
}
}
}
else
{
--ptr;
while (++ptr, --size >= 0)
{
if ((c = *ptr) != NUL && c != NL) /* catch most common case */
continue;
if (c == NUL)
*ptr = NL; /* NULs are replaced by newlines! */
else
{
if (skip_count == 0)
{
*ptr = NUL; /* end of line */
len = (colnr_T)(ptr - line_start + 1);
if (fileformat == EOL_DOS)
{
if (ptr > line_start && ptr[-1] == CAR)
{
/* remove CR before NL */
ptr[-1] = NUL;
--len;
}
/*
* Reading in Dos format, but no CR-LF found!
* When 'fileformats' includes "unix", delete all
* the lines read so far and start all over again.
* Otherwise give an error message later.
*/
else if (ff_error != EOL_DOS)
{
if ( try_unix
&& !read_stdin
&& (read_buffer
|| vim_lseek(fd, (off_T)0L, SEEK_SET)
== 0))
{
fileformat = EOL_UNIX;
if (set_options)
set_fileformat(EOL_UNIX, OPT_LOCAL);
file_rewind = TRUE;
keep_fileformat = TRUE;
goto retry;
}
ff_error = EOL_DOS;
}
}
if (ml_append(lnum, line_start, len, newfile) == FAIL)
{
error = TRUE;
break;
}
#ifdef FEAT_PERSISTENT_UNDO
if (read_undo_file)
sha256_update(&sha_ctx, line_start, len);
#endif
++lnum;
if (--read_count == 0)
{
error = TRUE; /* break loop */
line_start = ptr; /* nothing left to write */
break;
}
}
else
--skip_count;
line_start = ptr + 1;
}
}
}
linerest = (long)(ptr - line_start);
ui_breakcheck();
}
failed:
/* not an error, max. number of lines reached */
if (error && read_count == 0)
error = FALSE;
/*
* If we get EOF in the middle of a line, note the fact and
* complete the line ourselves.
* In Dos format ignore a trailing CTRL-Z, unless 'binary' set.
*/
if (!error
&& !got_int
&& linerest != 0
&& !(!curbuf->b_p_bin
&& fileformat == EOL_DOS
&& *line_start == Ctrl_Z
&& ptr == line_start + 1))
{
/* remember for when writing */
if (set_options)
curbuf->b_p_eol = FALSE;
*ptr = NUL;
len = (colnr_T)(ptr - line_start + 1);
if (ml_append(lnum, line_start, len, newfile) == FAIL)
error = TRUE;
else
{
#ifdef FEAT_PERSISTENT_UNDO
if (read_undo_file)
sha256_update(&sha_ctx, line_start, len);
#endif
read_no_eol_lnum = ++lnum;
}
}
if (set_options)
save_file_ff(curbuf); /* remember the current file format */
#ifdef FEAT_CRYPT
if (curbuf->b_cryptstate != NULL)
{
crypt_free_state(curbuf->b_cryptstate);
curbuf->b_cryptstate = NULL;
}
if (cryptkey != NULL && cryptkey != curbuf->b_p_key)
crypt_free_key(cryptkey);
/* Don't set cryptkey to NULL, it's used below as a flag that
* encryption was used. */
#endif
#ifdef FEAT_MBYTE
/* If editing a new file: set 'fenc' for the current buffer.
* Also for ":read ++edit file". */
if (set_options)
set_string_option_direct((char_u *)"fenc", -1, fenc,
OPT_FREE|OPT_LOCAL, 0);
if (fenc_alloced)
vim_free(fenc);
# ifdef USE_ICONV
if (iconv_fd != (iconv_t)-1)
{
iconv_close(iconv_fd);
iconv_fd = (iconv_t)-1;
}
# endif
#endif
if (!read_buffer && !read_stdin)
close(fd); /* errors are ignored */
#ifdef HAVE_FD_CLOEXEC
else
{
int fdflags = fcntl(fd, F_GETFD);
if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0)
(void)fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
}
#endif
vim_free(buffer);
#ifdef HAVE_DUP
if (read_stdin)
{
/* Use stderr for stdin, makes shell commands work. */
close(0);
ignored = dup(2);
}
#endif
#ifdef FEAT_MBYTE
if (tmpname != NULL)
{
mch_remove(tmpname); /* delete converted file */
vim_free(tmpname);
}
#endif
--no_wait_return; /* may wait for return now */
/*
* In recovery mode everything but autocommands is skipped.
*/
if (!recoverymode)
{
/* need to delete the last line, which comes from the empty buffer */
if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY))
{
#ifdef FEAT_NETBEANS_INTG
netbeansFireChanges = 0;
#endif
ml_delete(curbuf->b_ml.ml_line_count, FALSE);
#ifdef FEAT_NETBEANS_INTG
netbeansFireChanges = 1;
#endif
--linecnt;
}
linecnt = curbuf->b_ml.ml_line_count - linecnt;
if (filesize == 0)
linecnt = 0;
if (newfile || read_buffer)
{
redraw_curbuf_later(NOT_VALID);
#ifdef FEAT_DIFF
/* After reading the text into the buffer the diff info needs to
* be updated. */
diff_invalidate(curbuf);
#endif
#ifdef FEAT_FOLDING
/* All folds in the window are invalid now. Mark them for update
* before triggering autocommands. */
foldUpdateAll(curwin);
#endif
}
else if (linecnt) /* appended at least one line */
appended_lines_mark(from, linecnt);
#ifndef ALWAYS_USE_GUI
/*
* If we were reading from the same terminal as where messages go,
* the screen will have been messed up.
* Switch on raw mode now and clear the screen.
*/
if (read_stdin)
{
settmode(TMODE_RAW); /* set to raw mode */
starttermcap();
screenclear();
}
#endif
if (got_int)
{
if (!(flags & READ_DUMMY))
{
filemess(curbuf, sfname, (char_u *)_(e_interr), 0);
if (newfile)
curbuf->b_p_ro = TRUE; /* must use "w!" now */
}
msg_scroll = msg_save;
#ifdef FEAT_VIMINFO
check_marks_read();
#endif
return OK; /* an interrupt isn't really an error */
}
if (!filtering && !(flags & READ_DUMMY))
{
msg_add_fname(curbuf, sfname); /* fname in IObuff with quotes */
c = FALSE;
#ifdef UNIX
# ifdef S_ISFIFO
if (S_ISFIFO(perm)) /* fifo or socket */
{
STRCAT(IObuff, _("[fifo/socket]"));
c = TRUE;
}
# else
# ifdef S_IFIFO
if ((perm & S_IFMT) == S_IFIFO) /* fifo */
{
STRCAT(IObuff, _("[fifo]"));
c = TRUE;
}
# endif
# ifdef S_IFSOCK
if ((perm & S_IFMT) == S_IFSOCK) /* or socket */
{
STRCAT(IObuff, _("[socket]"));
c = TRUE;
}
# endif
# endif
# ifdef OPEN_CHR_FILES
if (S_ISCHR(perm)) /* or character special */
{
STRCAT(IObuff, _("[character special]"));
c = TRUE;
}
# endif
#endif
if (curbuf->b_p_ro)
{
STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]"));
c = TRUE;
}
if (read_no_eol_lnum)
{
msg_add_eol();
c = TRUE;
}
if (ff_error == EOL_DOS)
{
STRCAT(IObuff, _("[CR missing]"));
c = TRUE;
}
if (split)
{
STRCAT(IObuff, _("[long lines split]"));
c = TRUE;
}
#ifdef FEAT_MBYTE
if (notconverted)
{
STRCAT(IObuff, _("[NOT converted]"));
c = TRUE;
}
else if (converted)
{
STRCAT(IObuff, _("[converted]"));
c = TRUE;
}
#endif
#ifdef FEAT_CRYPT
if (cryptkey != NULL)
{
crypt_append_msg(curbuf);
c = TRUE;
}
#endif
#ifdef FEAT_MBYTE
if (conv_error != 0)
{
sprintf((char *)IObuff + STRLEN(IObuff),
_("[CONVERSION ERROR in line %ld]"), (long)conv_error);
c = TRUE;
}
else if (illegal_byte > 0)
{
sprintf((char *)IObuff + STRLEN(IObuff),
_("[ILLEGAL BYTE in line %ld]"), (long)illegal_byte);
c = TRUE;
}
else
#endif
if (error)
{
STRCAT(IObuff, _("[READ ERRORS]"));
c = TRUE;
}
if (msg_add_fileformat(fileformat))
c = TRUE;
#ifdef FEAT_CRYPT
if (cryptkey != NULL)
msg_add_lines(c, (long)linecnt, filesize
- crypt_get_header_len(crypt_get_method_nr(curbuf)));
else
#endif
msg_add_lines(c, (long)linecnt, filesize);
vim_free(keep_msg);
keep_msg = NULL;
msg_scrolled_ign = TRUE;
#ifdef ALWAYS_USE_GUI
/* Don't show the message when reading stdin, it would end up in a
* message box (which might be shown when exiting!) */
if (read_stdin || read_buffer)
p = msg_may_trunc(FALSE, IObuff);
else
#endif
p = msg_trunc_attr(IObuff, FALSE, 0);
if (read_stdin || read_buffer || restart_edit != 0
|| (msg_scrolled != 0 && !need_wait_return))
/* Need to repeat the message after redrawing when:
* - When reading from stdin (the screen will be cleared next).
* - When restart_edit is set (otherwise there will be a delay
* before redrawing).
* - When the screen was scrolled but there is no wait-return
* prompt. */
set_keep_msg(p, 0);
msg_scrolled_ign = FALSE;
}
/* with errors writing the file requires ":w!" */
if (newfile && (error
#ifdef FEAT_MBYTE
|| conv_error != 0
|| (illegal_byte > 0 && bad_char_behavior != BAD_KEEP)
#endif
))
curbuf->b_p_ro = TRUE;
u_clearline(); /* cannot use "U" command after adding lines */
/*
* In Ex mode: cursor at last new line.
* Otherwise: cursor at first new line.
*/
if (exmode_active)
curwin->w_cursor.lnum = from + linecnt;
else
curwin->w_cursor.lnum = from + 1;
check_cursor_lnum();
beginline(BL_WHITE | BL_FIX); /* on first non-blank */
/*
* Set '[ and '] marks to the newly read lines.
*/
curbuf->b_op_start.lnum = from + 1;
curbuf->b_op_start.col = 0;
curbuf->b_op_end.lnum = from + linecnt;
curbuf->b_op_end.col = 0;
#ifdef WIN32
/*
* Work around a weird problem: When a file has two links (only
* possible on NTFS) and we write through one link, then stat() it
* through the other link, the timestamp information may be wrong.
* It's correct again after reading the file, thus reset the timestamp
* here.
*/
if (newfile && !read_stdin && !read_buffer
&& mch_stat((char *)fname, &st) >= 0)
{
buf_store_time(curbuf, &st, fname);
curbuf->b_mtime_read = curbuf->b_mtime;
}
#endif
}
msg_scroll = msg_save;
#ifdef FEAT_VIMINFO
/*
* Get the marks before executing autocommands, so they can be used there.
*/
check_marks_read();
#endif
/*
* We remember if the last line of the read didn't have
* an eol even when 'binary' is off, to support turning 'fixeol' off,
* or writing the read again with 'binary' on. The latter is required
* for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
*/
curbuf->b_no_eol_lnum = read_no_eol_lnum;
/* When reloading a buffer put the cursor at the first line that is
* different. */
if (flags & READ_KEEP_UNDO)
u_find_first_changed();
#ifdef FEAT_PERSISTENT_UNDO
/*
* When opening a new file locate undo info and read it.
*/
if (read_undo_file)
{
char_u hash[UNDO_HASH_SIZE];
sha256_finish(&sha_ctx, hash);
u_read_undo(NULL, hash, fname);
}
#endif
#ifdef FEAT_AUTOCMD
if (!read_stdin && !read_fifo && (!read_buffer || sfname != NULL))
{
int m = msg_scroll;
int n = msg_scrolled;
/* Save the fileformat now, otherwise the buffer will be considered
* modified if the format/encoding was automatically detected. */
if (set_options)
save_file_ff(curbuf);
/*
* The output from the autocommands should not overwrite anything and
* should not be overwritten: Set msg_scroll, restore its value if no
* output was done.
*/
msg_scroll = TRUE;
if (filtering)
apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname,
FALSE, curbuf, eap);
else if (newfile || (read_buffer && sfname != NULL))
{
apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname,
FALSE, curbuf, eap);
if (!au_did_filetype && *curbuf->b_p_ft != NUL)
/*
* EVENT_FILETYPE was not triggered but the buffer already has a
* filetype. Trigger EVENT_FILETYPE using the existing filetype.
*/
apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
TRUE, curbuf);
}
else
apply_autocmds_exarg(EVENT_FILEREADPOST, sfname, sfname,
FALSE, NULL, eap);
if (msg_scrolled == n)
msg_scroll = m;
# ifdef FEAT_EVAL
if (aborting()) /* autocmds may abort script processing */
return FAIL;
# endif
}
#endif
if (recoverymode && error)
return FAIL;
return OK;
} | 8173 | True | 1 |
CVE-2016-1248 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.0/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'http://openwall.com/lists/oss-security/2016/11/22/20', 'name': 'http://openwall.com/lists/oss-security/2016/11/22/20', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://github.com/vim/vim/releases/tag/v8.0.0056', 'name': 'https://github.com/vim/vim/releases/tag/v8.0.0056', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'https://github.com/vim/vim/commit/d0b5138ba4bccff8a744c99836041ef6322ed39a', 'name': 'https://github.com/vim/vim/commit/d0b5138ba4bccff8a744c99836041ef6322ed39a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'https://lists.debian.org/debian-security-announce/2016/msg00305.html', 'name': 'https://lists.debian.org/debian-security-announce/2016/msg00305.html', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'https://github.com/neovim/neovim/commit/4fad66fbe637818b6b3d6bc5d21923ba72795040', 'name': 'https://github.com/neovim/neovim/commit/4fad66fbe637818b6b3d6bc5d21923ba72795040', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Vendor Advisory']}, {'url': 'https://anonscm.debian.org/cgit/pkg-vim/vim.git/tree/debian/changelog', 'name': 'https://anonscm.debian.org/cgit/pkg-vim/vim.git/tree/debian/changelog', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2016/11/msg00025.html', 'name': '[debian-lts-announce] 20161122 [SECURITY] [DLA 718-1] vim security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.securityfocus.com/bid/94478', 'name': '94478', 'refsource': 'BID', 'tags': []}, {'url': 'http://www.ubuntu.com/usn/USN-3139-1', 'name': 'USN-3139-1', 'refsource': 'UBUNTU', 'tags': []}, {'url': 'http://www.debian.org/security/2016/dsa-3722', 'name': 'DSA-3722', 'refsource': 'DEBIAN', 'tags': []}, {'url': 'http://rhn.redhat.com/errata/RHSA-2016-2972.html', 'name': 'RHSA-2016:2972', 'refsource': 'REDHAT', 'tags': []}, {'url': 'https://security.gentoo.org/glsa/201701-29', 'name': 'GLSA-201701-29', 'refsource': 'GENTOO', 'tags': []}, {'url': 'http://www.securitytracker.com/id/1037338', 'name': '1037338', 'refsource': 'SECTRACK', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-20'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:vim:vim:*:*:*:*:*:*:*:*', 'versionEndIncluding': '8.0.0055', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': "vim before patch 8.0.0056 does not properly validate values for the 'filetype', 'syntax' and 'keymap' options, which may result in the execution of arbitrary code if a file with a specially crafted modeline is opened."}] | 2017-07-28T01:29Z | 2016-11-23T15:59Z | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. |
Input validation is a frequently-used technique
for checking potentially dangerous inputs in order to
ensure that the inputs are safe for processing within the
code, or when communicating with other components. When
software does not validate input properly, an attacker is
able to craft the input in a form that is not expected by
the rest of the application. This will lead to parts of the
system receiving unintended input, which may result in
altered control flow, arbitrary control of a resource, or
arbitrary code execution.
Input validation is not the only technique for
processing input, however. Other techniques attempt to
transform potentially-dangerous input into something safe, such
as filtering (CWE-790) - which attempts to remove dangerous
inputs - or encoding/escaping (CWE-116), which attempts to
ensure that the input is not misinterpreted when it is included
in output to another component. Other techniques exist as well
(see CWE-138 for more examples.)
Input validation can be applied to:
raw data - strings, numbers, parameters, file contents, etc.
metadata - information about the raw data, such as headers or size
Data can be simple or structured. Structured data
can be composed of many nested layers, composed of
combinations of metadata and raw data, with other simple or
structured data.
Many properties of raw data or metadata may need
to be validated upon entry into the code, such
as:
specified quantities such as size, length, frequency, price, rate, number of operations, time, etc.
implied or derived quantities, such as the actual size of a file instead of a specified size
indexes, offsets, or positions into more complex data structures
symbolic keys or other elements into hash tables, associative arrays, etc.
well-formedness, i.e. syntactic correctness - compliance with expected syntax
lexical token correctness - compliance with rules for what is treated as a token
specified or derived type - the actual type of the input (or what the input appears to be)
consistency - between individual data elements, between raw data and metadata, between references, etc.
conformance to domain-specific rules, e.g. business logic
equivalence - ensuring that equivalent inputs are treated the same
authenticity, ownership, or other attestations about the input, e.g. a cryptographic signature to prove the source of the data
Implied or derived properties of data must often
be calculated or inferred by the code itself. Errors in
deriving properties may be considered a contributing factor
to improper input validation.
Note that "input validation" has very different
meanings to different people, or within different
classification schemes. Caution must be used when
referencing this CWE entry or mapping to it. For example,
some weaknesses might involve inadvertently giving control
to an attacker over an input when they should not be able
to provide an input at all, but sometimes this is referred
to as input validation.
Finally, it is important to emphasize that the
distinctions between input validation and output escaping
are often blurred, and developers must be careful to
understand the difference, including how input validation
is not always sufficient to prevent vulnerabilities,
especially when less stringent data types must be
supported, such as free-form text. Consider a SQL injection
scenario in which a person's last name is inserted into a
query. The name "O'Reilly" would likely pass the validation
step since it is a common last name in the English
language. However, this valid name cannot be directly
inserted into the database because it contains the "'"
apostrophe character, which would need to be escaped or
otherwise transformed. In this case, removing the
apostrophe might reduce the risk of SQL injection, but it
would produce incorrect behavior because the wrong name
would be recorded.
| https://cwe.mitre.org/data/definitions/20.html | 0 | James McCoy | 2016-11-20 08:42:38-07:00 | vim-patch:8.0.0056
Problem: When setting 'filetype' there is no check for a valid name.
Solution: Only allow valid characters in 'filetype', 'syntax' and 'keymap'.
https://github.com/vim/vim/commit/d0b5138ba4bccff8a744c99836041ef6322ed39a | 4fad66fbe637818b6b3d6bc5d21923ba72795040 | False | neovim/neovim | Vim-fork focused on extensibility and usability | 2014-01-31 13:39:22 | 2022-08-27 18:58:56 | https://neovim.io | neovim | 57131.0 | 4015.0 | did_set_string_option | did_set_string_option( int opt_idx , char_u ** varp , int new_value_alloced , char_u * oldval , char_u * errbuf , int opt_flags) | ['opt_idx', 'varp', 'new_value_alloced', 'oldval', 'errbuf', 'opt_flags'] | did_set_string_option (
int opt_idx, /* index in options[] table */
char_u **varp, /* pointer to the option variable */
int new_value_alloced, /* new value was allocated */
char_u *oldval, /* previous value of the option */
char_u *errbuf, /* buffer for errors, or NULL */
int opt_flags /* OPT_LOCAL and/or OPT_GLOBAL */
)
{
char_u *errmsg = NULL;
char_u *s, *p;
int did_chartab = FALSE;
char_u **gvarp;
bool free_oldval = (options[opt_idx].flags & P_ALLOCED);
/* Get the global option to compare with, otherwise we would have to check
* two values for all local options. */
gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
/* Disallow changing some options from secure mode */
if ((secure || sandbox != 0)
&& (options[opt_idx].flags & P_SECURE)) {
errmsg = e_secure;
}
/* Check for a "normal" file name in some options. Disallow a path
* separator (slash and/or backslash), wildcards and characters that are
* often illegal in a file name. */
else if ((options[opt_idx].flags & P_NFNAME)
&& vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL) {
errmsg = e_invarg;
}
/* 'backupcopy' */
else if (gvarp == &p_bkc) {
char_u *bkc = p_bkc;
unsigned int *flags = &bkc_flags;
if (opt_flags & OPT_LOCAL) {
bkc = curbuf->b_p_bkc;
flags = &curbuf->b_bkc_flags;
}
if ((opt_flags & OPT_LOCAL) && *bkc == NUL) {
// make the local value empty: use the global value
*flags = 0;
} else {
if (opt_strings_flags(bkc, p_bkc_values, flags, true) != OK) {
errmsg = e_invarg;
}
if (((*flags & BKC_AUTO) != 0)
+ ((*flags & BKC_YES) != 0)
+ ((*flags & BKC_NO) != 0) != 1) {
// Must have exactly one of "auto", "yes" and "no".
(void)opt_strings_flags(oldval, p_bkc_values, flags, true);
errmsg = e_invarg;
}
}
}
/* 'backupext' and 'patchmode' */
else if (varp == &p_bex || varp == &p_pm) {
if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
*p_pm == '.' ? p_pm + 1 : p_pm) == 0)
errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
}
/* 'breakindentopt' */
else if (varp == &curwin->w_p_briopt) {
if (briopt_check(curwin) == FAIL)
errmsg = e_invarg;
} else if (varp == &p_isi
|| varp == &(curbuf->b_p_isk)
|| varp == &p_isp
|| varp == &p_isf) {
// 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
// If the new option is invalid, use old value. 'lisp' option: refill
// g_chartab[] for '-' char
if (init_chartab() == FAIL) {
did_chartab = TRUE; /* need to restore it below */
errmsg = e_invarg; /* error in value */
}
}
/* 'helpfile' */
else if (varp == &p_hf) {
/* May compute new values for $VIM and $VIMRUNTIME */
if (didset_vim) {
vim_setenv("VIM", "");
didset_vim = FALSE;
}
if (didset_vimruntime) {
vim_setenv("VIMRUNTIME", "");
didset_vimruntime = FALSE;
}
}
/* 'colorcolumn' */
else if (varp == &curwin->w_p_cc)
errmsg = check_colorcolumn(curwin);
/* 'helplang' */
else if (varp == &p_hlg) {
/* Check for "", "ab", "ab,cd", etc. */
for (s = p_hlg; *s != NUL; s += 3) {
if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) {
errmsg = e_invarg;
break;
}
if (s[2] == NUL)
break;
}
}
/* 'highlight' */
else if (varp == &p_hl) {
if (highlight_changed() == FAIL)
errmsg = e_invarg; /* invalid flags */
}
/* 'nrformats' */
else if (gvarp == &p_nf) {
if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
errmsg = e_invarg;
} else if (varp == &p_ssop) { // 'sessionoptions'
if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, true) != OK)
errmsg = e_invarg;
if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) {
/* Don't allow both "sesdir" and "curdir". */
(void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, true);
errmsg = e_invarg;
}
} else if (varp == &p_vop) { // 'viewoptions'
if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, true) != OK)
errmsg = e_invarg;
}
/* 'scrollopt' */
else if (varp == &p_sbo) {
if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
errmsg = e_invarg;
} else if (varp == &p_ambw || (int *)varp == &p_emoji) {
// 'ambiwidth'
if (check_opt_strings(p_ambw, p_ambw_values, false) != OK) {
errmsg = e_invarg;
} else if (set_chars_option(&p_lcs) != NULL) {
errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
} else if (set_chars_option(&p_fcs) != NULL) {
errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
}
}
/* 'background' */
else if (varp == &p_bg) {
if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK) {
int dark = (*p_bg == 'd');
init_highlight(FALSE, FALSE);
if (dark != (*p_bg == 'd')
&& get_var_value((char_u *)"g:colors_name") != NULL) {
/* The color scheme must have set 'background' back to another
* value, that's not what we want here. Disable the color
* scheme and set the colors again. */
do_unlet((char_u *)"g:colors_name", TRUE);
free_string_option(p_bg);
p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
check_string_option(&p_bg);
init_highlight(FALSE, FALSE);
}
} else
errmsg = e_invarg;
}
/* 'wildmode' */
else if (varp == &p_wim) {
if (check_opt_wim() == FAIL)
errmsg = e_invarg;
}
/* 'wildoptions' */
else if (varp == &p_wop) {
if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
errmsg = e_invarg;
}
/* 'winaltkeys' */
else if (varp == &p_wak) {
if (*p_wak == NUL
|| check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
errmsg = e_invarg;
}
/* 'eventignore' */
else if (varp == &p_ei) {
if (check_ei() == FAIL)
errmsg = e_invarg;
/* 'encoding' and 'fileencoding' */
} else if (varp == &p_enc || gvarp == &p_fenc) {
if (gvarp == &p_fenc) {
if (!MODIFIABLE(curbuf) && opt_flags != OPT_GLOBAL) {
errmsg = e_modifiable;
} else if (vim_strchr(*varp, ',') != NULL) {
// No comma allowed in 'fileencoding'; catches confusing it
// with 'fileencodings'.
errmsg = e_invarg;
} else {
// May show a "+" in the title now.
redraw_titles();
// Add 'fileencoding' to the swap file.
ml_setflags(curbuf);
}
}
if (errmsg == NULL) {
/* canonize the value, so that STRCMP() can be used on it */
p = enc_canonize(*varp);
xfree(*varp);
*varp = p;
if (varp == &p_enc) {
// only encoding=utf-8 allowed
if (STRCMP(p_enc, "utf-8") != 0) {
errmsg = e_invarg;
}
}
}
} else if (varp == &p_penc) {
/* Canonize printencoding if VIM standard one */
p = enc_canonize(p_penc);
xfree(p_penc);
p_penc = p;
} else if (varp == &curbuf->b_p_keymap) {
/* load or unload key mapping tables */
errmsg = keymap_init();
if (errmsg == NULL) {
if (*curbuf->b_p_keymap != NUL) {
/* Installed a new keymap, switch on using it. */
curbuf->b_p_iminsert = B_IMODE_LMAP;
if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
curbuf->b_p_imsearch = B_IMODE_LMAP;
} else {
/* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
if (curbuf->b_p_iminsert == B_IMODE_LMAP)
curbuf->b_p_iminsert = B_IMODE_NONE;
if (curbuf->b_p_imsearch == B_IMODE_LMAP)
curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
}
if ((opt_flags & OPT_LOCAL) == 0) {
set_iminsert_global();
set_imsearch_global();
}
status_redraw_curbuf();
}
}
/* 'fileformat' */
else if (gvarp == &p_ff) {
if (!MODIFIABLE(curbuf) && !(opt_flags & OPT_GLOBAL))
errmsg = e_modifiable;
else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
errmsg = e_invarg;
else {
redraw_titles();
/* update flag in swap file */
ml_setflags(curbuf);
/* Redraw needed when switching to/from "mac": a CR in the text
* will be displayed differently. */
if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
redraw_curbuf_later(NOT_VALID);
}
}
/* 'fileformats' */
else if (varp == &p_ffs) {
if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) {
errmsg = e_invarg;
}
}
/* 'matchpairs' */
else if (gvarp == &p_mps) {
if (has_mbyte) {
for (p = *varp; *p != NUL; ++p) {
int x2 = -1;
int x3 = -1;
if (*p != NUL)
p += mb_ptr2len(p);
if (*p != NUL)
x2 = *p++;
if (*p != NUL) {
x3 = mb_ptr2char(p);
p += mb_ptr2len(p);
}
if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) {
errmsg = e_invarg;
break;
}
if (*p == NUL)
break;
}
} else {
/* Check for "x:y,x:y" */
for (p = *varp; *p != NUL; p += 4) {
if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) {
errmsg = e_invarg;
break;
}
if (p[3] == NUL)
break;
}
}
}
/* 'comments' */
else if (gvarp == &p_com) {
for (s = *varp; *s; ) {
while (*s && *s != ':') {
if (vim_strchr((char_u *)COM_ALL, *s) == NULL
&& !ascii_isdigit(*s) && *s != '-') {
errmsg = illegal_char(errbuf, *s);
break;
}
++s;
}
if (*s++ == NUL)
errmsg = (char_u *)N_("E524: Missing colon");
else if (*s == ',' || *s == NUL)
errmsg = (char_u *)N_("E525: Zero length string");
if (errmsg != NULL)
break;
while (*s && *s != ',') {
if (*s == '\\' && s[1] != NUL)
++s;
++s;
}
s = skip_to_option_part(s);
}
}
/* 'listchars' */
else if (varp == &p_lcs) {
errmsg = set_chars_option(varp);
}
/* 'fillchars' */
else if (varp == &p_fcs) {
errmsg = set_chars_option(varp);
}
/* 'cedit' */
else if (varp == &p_cedit) {
errmsg = check_cedit();
}
/* 'verbosefile' */
else if (varp == &p_vfile) {
verbose_stop();
if (*p_vfile != NUL && verbose_open() == FAIL)
errmsg = e_invarg;
/* 'shada' */
} else if (varp == &p_shada) {
// TODO(ZyX-I): Remove this code in the future, alongside with &viminfo
// option.
opt_idx = ((options[opt_idx].fullname[0] == 'v')
? (shada_idx == -1
? ((shada_idx = findoption((char_u *) "shada")))
: shada_idx)
: opt_idx);
for (s = p_shada; *s; ) {
/* Check it's a valid character */
if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL) {
errmsg = illegal_char(errbuf, *s);
break;
}
if (*s == 'n') { /* name is always last one */
break;
} else if (*s == 'r') { /* skip until next ',' */
while (*++s && *s != ',')
;
} else if (*s == '%') {
/* optional number */
while (ascii_isdigit(*++s))
;
} else if (*s == '!' || *s == 'h' || *s == 'c')
++s; /* no extra chars */
else { /* must have a number */
while (ascii_isdigit(*++s))
;
if (!ascii_isdigit(*(s - 1))) {
if (errbuf != NULL) {
sprintf((char *)errbuf,
_("E526: Missing number after <%s>"),
transchar_byte(*(s - 1)));
errmsg = errbuf;
} else
errmsg = (char_u *)"";
break;
}
}
if (*s == ',')
++s;
else if (*s) {
if (errbuf != NULL)
errmsg = (char_u *)N_("E527: Missing comma");
else
errmsg = (char_u *)"";
break;
}
}
if (*p_shada && errmsg == NULL && get_shada_parameter('\'') < 0)
errmsg = (char_u *)N_("E528: Must specify a ' value");
}
/* 'showbreak' */
else if (varp == &p_sbr) {
for (s = p_sbr; *s; ) {
if (ptr2cells(s) != 1)
errmsg = (char_u *)N_("E595: contains unprintable or wide character");
mb_ptr_adv(s);
}
}
/* 'guicursor' */
else if (varp == &p_guicursor)
errmsg = parse_shape_opt(SHAPE_CURSOR);
else if (varp == &p_popt)
errmsg = parse_printoptions();
else if (varp == &p_pmfn)
errmsg = parse_printmbfont();
/* 'langmap' */
else if (varp == &p_langmap)
langmap_set();
/* 'breakat' */
else if (varp == &p_breakat)
fill_breakat_flags();
/* 'titlestring' and 'iconstring' */
else if (varp == &p_titlestring || varp == &p_iconstring) {
int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
/* NULL => statusline syntax */
if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
stl_syntax |= flagval;
else
stl_syntax &= ~flagval;
did_set_title(varp == &p_iconstring);
}
/* 'selection' */
else if (varp == &p_sel) {
if (*p_sel == NUL
|| check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
errmsg = e_invarg;
}
/* 'selectmode' */
else if (varp == &p_slm) {
if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
errmsg = e_invarg;
}
/* 'keymodel' */
else if (varp == &p_km) {
if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
errmsg = e_invarg;
else {
km_stopsel = (vim_strchr(p_km, 'o') != NULL);
km_startsel = (vim_strchr(p_km, 'a') != NULL);
}
}
/* 'mousemodel' */
else if (varp == &p_mousem) {
if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
errmsg = e_invarg;
} else if (varp == &p_swb) { // 'switchbuf'
if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, true) != OK)
errmsg = e_invarg;
}
/* 'debug' */
else if (varp == &p_debug) {
if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
errmsg = e_invarg;
} else if (varp == &p_dy) { // 'display'
if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, true) != OK)
errmsg = e_invarg;
else
(void)init_chartab();
}
/* 'eadirection' */
else if (varp == &p_ead) {
if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
errmsg = e_invarg;
} else if (varp == &p_cb) { // 'clipboard'
if (opt_strings_flags(p_cb, p_cb_values, &cb_flags, true) != OK) {
errmsg = e_invarg;
}
} else if (varp == &(curwin->w_s->b_p_spl) // 'spell'
|| varp == &(curwin->w_s->b_p_spf)) {
// When 'spelllang' or 'spellfile' is set and there is a window for this
// buffer in which 'spell' is set load the wordlists.
errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
}
/* When 'spellcapcheck' is set compile the regexp program. */
else if (varp == &(curwin->w_s->b_p_spc)) {
errmsg = compile_cap_prog(curwin->w_s);
}
/* 'spellsuggest' */
else if (varp == &p_sps) {
if (spell_check_sps() != OK)
errmsg = e_invarg;
}
/* 'mkspellmem' */
else if (varp == &p_msm) {
if (spell_check_msm() != OK)
errmsg = e_invarg;
}
/* When 'bufhidden' is set, check for valid value. */
else if (gvarp == &p_bh) {
if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
errmsg = e_invarg;
}
/* When 'buftype' is set, check for valid value. */
else if (gvarp == &p_bt) {
if ((curbuf->terminal && curbuf->b_p_bt[0] != 't')
|| (!curbuf->terminal && curbuf->b_p_bt[0] == 't')
|| check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK) {
errmsg = e_invarg;
} else {
if (curwin->w_status_height) {
curwin->w_redr_status = TRUE;
redraw_later(VALID);
}
curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
redraw_titles();
}
}
/* 'statusline' or 'rulerformat' */
else if (gvarp == &p_stl || varp == &p_ruf) {
int wid;
if (varp == &p_ruf) /* reset ru_wid first */
ru_wid = 0;
s = *varp;
if (varp == &p_ruf && *s == '%') {
/* set ru_wid if 'ruf' starts with "%99(" */
if (*++s == '-') /* ignore a '-' */
s++;
wid = getdigits_int(&s);
if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
ru_wid = wid;
else
errmsg = check_stl_option(p_ruf);
}
/* check 'statusline' only if it doesn't start with "%!" */
else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
errmsg = check_stl_option(s);
if (varp == &p_ruf && errmsg == NULL)
comp_col();
}
/* check if it is a valid value for 'complete' -- Acevedo */
else if (gvarp == &p_cpt) {
for (s = *varp; *s; ) {
while (*s == ',' || *s == ' ')
s++;
if (!*s)
break;
if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL) {
errmsg = illegal_char(errbuf, *s);
break;
}
if (*++s != NUL && *s != ',' && *s != ' ') {
if (s[-1] == 'k' || s[-1] == 's') {
/* skip optional filename after 'k' and 's' */
while (*s && *s != ',' && *s != ' ') {
if (*s == '\\')
++s;
++s;
}
} else {
if (errbuf != NULL) {
sprintf((char *)errbuf,
_("E535: Illegal character after <%c>"),
*--s);
errmsg = errbuf;
} else
errmsg = (char_u *)"";
break;
}
}
}
}
/* 'completeopt' */
else if (varp == &p_cot) {
if (check_opt_strings(p_cot, p_cot_values, true) != OK) {
errmsg = e_invarg;
} else {
completeopt_was_set();
}
}
/* 'pastetoggle': translate key codes like in a mapping */
else if (varp == &p_pt) {
if (*p_pt) {
(void)replace_termcodes(p_pt, STRLEN(p_pt), &p, true, true, false,
CPO_TO_CPO_FLAGS);
if (p != NULL) {
if (new_value_alloced)
free_string_option(p_pt);
p_pt = p;
new_value_alloced = TRUE;
}
}
}
/* 'backspace' */
else if (varp == &p_bs) {
if (ascii_isdigit(*p_bs)) {
if (*p_bs >'2' || p_bs[1] != NUL)
errmsg = e_invarg;
} else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
errmsg = e_invarg;
} else if (varp == &p_bo) {
if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, true) != OK) {
errmsg = e_invarg;
}
} else if (gvarp == &p_tc) { // 'tagcase'
unsigned int *flags;
if (opt_flags & OPT_LOCAL) {
p = curbuf->b_p_tc;
flags = &curbuf->b_tc_flags;
} else {
p = p_tc;
flags = &tc_flags;
}
if ((opt_flags & OPT_LOCAL) && *p == NUL) {
// make the local value empty: use the global value
*flags = 0;
} else if (*p == NUL
|| opt_strings_flags(p, p_tc_values, flags, false) != OK) {
errmsg = e_invarg;
}
} else if (varp == &p_cmp) { // 'casemap'
if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, true) != OK)
errmsg = e_invarg;
}
/* 'diffopt' */
else if (varp == &p_dip) {
if (diffopt_changed() == FAIL)
errmsg = e_invarg;
}
/* 'foldmethod' */
else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) {
if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
|| *curwin->w_p_fdm == NUL)
errmsg = e_invarg;
else {
foldUpdateAll(curwin);
if (foldmethodIsDiff(curwin))
newFoldLevel();
}
}
/* 'foldexpr' */
else if (varp == &curwin->w_p_fde) {
if (foldmethodIsExpr(curwin))
foldUpdateAll(curwin);
}
/* 'foldmarker' */
else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) {
p = vim_strchr(*varp, ',');
if (p == NULL)
errmsg = (char_u *)N_("E536: comma required");
else if (p == *varp || p[1] == NUL)
errmsg = e_invarg;
else if (foldmethodIsMarker(curwin))
foldUpdateAll(curwin);
}
/* 'commentstring' */
else if (gvarp == &p_cms) {
if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
errmsg = (char_u *)N_(
"E537: 'commentstring' must be empty or contain %s");
} else if (varp == &p_fdo) { // 'foldopen'
if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, true) != OK)
errmsg = e_invarg;
}
/* 'foldclose' */
else if (varp == &p_fcl) {
if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
errmsg = e_invarg;
}
/* 'foldignore' */
else if (gvarp == &curwin->w_allbuf_opt.wo_fdi) {
if (foldmethodIsIndent(curwin))
foldUpdateAll(curwin);
} else if (varp == &p_ve) { // 'virtualedit'
if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, true) != OK)
errmsg = e_invarg;
else if (STRCMP(p_ve, oldval) != 0) {
/* Recompute cursor position in case the new 've' setting
* changes something. */
validate_virtcol();
coladvance(curwin->w_virtcol);
}
} else if (varp == &p_csqf) {
if (p_csqf != NULL) {
p = p_csqf;
while (*p != NUL) {
if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
|| p[1] == NUL
|| vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
|| (p[2] != NUL && p[2] != ',')) {
errmsg = e_invarg;
break;
} else if (p[2] == NUL)
break;
else
p += 3;
}
}
}
/* 'cinoptions' */
else if (gvarp == &p_cino) {
/* TODO: recognize errors */
parse_cino(curbuf);
// inccommand
} else if (varp == &p_icm) {
if (check_opt_strings(p_icm, p_icm_values, false) != OK) {
errmsg = e_invarg;
}
// Options that are a list of flags.
} else {
p = NULL;
if (varp == &p_ww)
p = (char_u *)WW_ALL;
if (varp == &p_shm)
p = (char_u *)SHM_ALL;
else if (varp == &(p_cpo))
p = (char_u *)CPO_VI;
else if (varp == &(curbuf->b_p_fo))
p = (char_u *)FO_ALL;
else if (varp == &curwin->w_p_cocu)
p = (char_u *)COCU_ALL;
else if (varp == &p_mouse) {
p = (char_u *)MOUSE_ALL;
}
if (p != NULL) {
for (s = *varp; *s; ++s)
if (vim_strchr(p, *s) == NULL) {
errmsg = illegal_char(errbuf, *s);
break;
}
}
}
/*
* If error detected, restore the previous value.
*/
if (errmsg != NULL) {
if (new_value_alloced)
free_string_option(*varp);
*varp = oldval;
/*
* When resetting some values, need to act on it.
*/
if (did_chartab)
(void)init_chartab();
if (varp == &p_hl)
(void)highlight_changed();
} else {
/* Remember where the option was set. */
set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
/*
* Free string options that are in allocated memory.
* Use "free_oldval", because recursiveness may change the flags under
* our fingers (esp. init_highlight()).
*/
if (free_oldval)
free_string_option(oldval);
if (new_value_alloced)
options[opt_idx].flags |= P_ALLOCED;
else
options[opt_idx].flags &= ~P_ALLOCED;
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
&& ((int)options[opt_idx].indir & PV_BOTH)) {
/* global option with local value set to use global value; free
* the local value and make it empty */
p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
free_string_option(*(char_u **)p);
*(char_u **)p = empty_option;
}
/* May set global value for local option. */
else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
set_string_option_global(opt_idx, varp);
/*
* Trigger the autocommand only after setting the flags.
*/
/* When 'syntax' is set, load the syntax of that name */
if (varp == &(curbuf->b_p_syn)) {
apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
curbuf->b_fname, TRUE, curbuf);
} else if (varp == &(curbuf->b_p_ft)) {
/* 'filetype' is set, trigger the FileType autocommand */
did_filetype = TRUE;
apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
curbuf->b_fname, TRUE, curbuf);
}
if (varp == &(curwin->w_s->b_p_spl)) {
char_u fname[200];
char_u *q = curwin->w_s->b_p_spl;
/* Skip the first name if it is "cjk". */
if (STRNCMP(q, "cjk,", 4) == 0)
q += 4;
/*
* Source the spell/LANG.vim in 'runtimepath'.
* They could set 'spellcapcheck' depending on the language.
* Use the first name in 'spelllang' up to '_region' or
* '.encoding'.
*/
for (p = q; *p != NUL; ++p)
if (vim_strchr((char_u *)"_.,", *p) != NULL)
break;
vim_snprintf((char *)fname, sizeof(fname), "spell/%.*s.vim",
(int)(p - q), q);
source_runtime(fname, DIP_ALL);
}
}
if (varp == &p_mouse) {
if (*p_mouse == NUL) {
ui_mouse_off();
} else {
setmouse(); // in case 'mouse' changed
}
}
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
curwin->w_set_curswant = TRUE;
check_redraw(options[opt_idx].flags);
return errmsg;
} | 4646 | True | 1 |
CVE-2020-13881 | False | False | False | False | AV:N/AC:M/Au:N/C:P/I:N/A:N | NETWORK | MEDIUM | NONE | PARTIAL | NONE | NONE | 4.3 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | NONE | NONE | 7.5 | HIGH | 3.9 | 3.6 | False | [{'url': 'https://github.com/kravietz/pam_tacplus/issues/149', 'name': 'https://github.com/kravietz/pam_tacplus/issues/149', 'refsource': 'MISC', 'tags': ['Issue Tracking', 'Third Party Advisory']}, {'url': 'https://github.com/kravietz/pam_tacplus/commit/4a9852c31c2fd0c0e72fbb689a586aabcfb11cb0', 'name': 'https://github.com/kravietz/pam_tacplus/commit/4a9852c31c2fd0c0e72fbb689a586aabcfb11cb0', 'refsource': 'MISC', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://www.openwall.com/lists/oss-security/2020/06/08/1', 'name': '[oss-security] 20200608 CVE-2020-13881: pam_tacplus 1.3.8 through 1.5.1, the TACACS+ shared secret gets logged via syslog if configured with debug parameter', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Patch', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2020/06/msg00007.html', 'name': '[debian-lts-announce] 20200608 [SECURITY] [DLA 2239-1] libpam-tacplus security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'https://www.arista.com/en/support/advisories-notices/security-advisories/11705-security-advisory-50', 'name': 'https://www.arista.com/en/support/advisories-notices/security-advisories/11705-security-advisory-50', 'refsource': 'MISC', 'tags': ['Third Party Advisory']}, {'url': 'https://usn.ubuntu.com/4521-1/', 'name': 'USN-4521-1', 'refsource': 'UBUNTU', 'tags': ['Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2021/08/msg00006.html', 'name': '[debian-lts-announce] 20210804 [SECURITY] [DLA 2730-1] libpam-tacplus security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-532'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:pam_tacplus_project:pam_tacplus:*:*:*:*:*:*:*:*', 'versionStartIncluding': '1.3.8', 'versionEndIncluding': '1.5.1', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:20.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:esm:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:arista:cloudvision_portal:*:*:*:*:*:*:*:*', 'versionEndExcluding': '2020.1.2', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'In support.c in pam_tacplus 1.3.8 through 1.5.1, the TACACS+ shared secret gets logged via syslog if the DEBUG loglevel and journald are used.'}] | 2022-04-05T15:04Z | 2020-06-06T19:15Z | Insertion of Sensitive Information into Log File | Information written to log files can be of a sensitive nature and give valuable guidance to an attacker or expose sensitive user information. |
While logging all information may be helpful during development stages, it is important that logging levels be set appropriately before a product ships so that sensitive user data and system information are not accidentally exposed to potential attackers.
Different log files may be produced and stored for:
Server log files (e.g. server.log). This can give information on whatever application left the file. Usually this can give full path names and system information, and sometimes usernames and passwords.
log files that are used for debugging
| https://cwe.mitre.org/data/definitions/532.html | 0 | Daniel Gollub | 2020-06-02 19:21:56+02:00 | pam: don't leak TACACS+ secret to journald
If journald for syslog is used, the journal is going to store everything,
even DEBUG loglevel messages. Pre-journald logging of system-wide DEBUG
loglevel could be avoided and is not affected in all cases.
With journald presence it's probably safe to no longer log sensitive
details at DEBUG level.
Fix #149
Signed-off-by: Daniel Gollub <[email protected]> | 4a9852c31c2fd0c0e72fbb689a586aabcfb11cb0 | False | kravietz/pam_tacplus | TACACS+ protocol client library and PAM module in C. This PAM module support authentication, authorization (account management) and accounting (session management)performed using TACACS+ protocol designed by Cisco. | 2012-12-17 21:22:35 | 2022-05-10 20:37:04 | kravietz | 109.0 | 85.0 | _pam_parse | _pam_parse( int argc , const char ** argv) | ['argc', 'argv'] | int _pam_parse(int argc, const char **argv) {
int ctrl = 0;
const char *current_secret = NULL;
/* otherwise the list will grow with each call */
memset(tac_srv, 0, sizeof(tacplus_server_t) * TAC_PLUS_MAXSERVERS);
memset(&tac_srv_addr, 0, sizeof(struct addrinfo) * TAC_PLUS_MAXSERVERS);
memset(&tac_sock_addr, 0, sizeof(struct sockaddr) * TAC_PLUS_MAXSERVERS);
memset(&tac_sock6_addr, 0, sizeof(struct sockaddr_in6) * TAC_PLUS_MAXSERVERS);
tac_srv_no = 0;
tac_service[0] = 0;
tac_protocol[0] = 0;
tac_prompt[0] = 0;
tac_login[0] = 0;
for (ctrl = 0; argc-- > 0; ++argv) {
if (!strcmp(*argv, "debug")) { /* all */
ctrl |= PAM_TAC_DEBUG;
} else if (!strcmp(*argv, "use_first_pass")) {
ctrl |= PAM_TAC_USE_FIRST_PASS;
} else if (!strcmp(*argv, "try_first_pass")) {
ctrl |= PAM_TAC_TRY_FIRST_PASS;
} else if (!strncmp(*argv, "service=", 8)) { /* author & acct */
xstrcpy(tac_service, *argv + 8, sizeof(tac_service));
} else if (!strncmp(*argv, "protocol=", 9)) { /* author & acct */
xstrcpy(tac_protocol, *argv + 9, sizeof(tac_protocol));
} else if (!strncmp(*argv, "prompt=", 7)) { /* authentication */
xstrcpy(tac_prompt, *argv + 7, sizeof(tac_prompt));
/* Replace _ with space */
unsigned long chr;
for (chr = 0; chr < strlen(tac_prompt); chr++) {
if (tac_prompt[chr] == '_') {
tac_prompt[chr] = ' ';
}
}
} else if (!strncmp(*argv, "login=", 6)) {
xstrcpy(tac_login, *argv + 6, sizeof(tac_login));
} else if (!strcmp(*argv, "acct_all")) {
ctrl |= PAM_TAC_ACCT;
} else if (!strncmp(*argv, "server=", 7)) { /* authen & acct */
if (tac_srv_no < TAC_PLUS_MAXSERVERS) {
struct addrinfo hints, *servers, *server;
int rv;
char *close_bracket, *server_name, *port, server_buf[256];
memset(&hints, 0, sizeof hints);
memset(&server_buf, 0, sizeof(server_buf));
hints.ai_family = AF_UNSPEC; /* use IPv4 or IPv6, whichever */
hints.ai_socktype = SOCK_STREAM;
if (strlen(*argv + 7) >= sizeof(server_buf)) {
_pam_log(LOG_ERR, "server address too long, sorry");
continue;
}
strcpy(server_buf, *argv + 7);
if (*server_buf == '[' &&
(close_bracket = strchr(server_buf, ']')) != NULL) { /* Check for URI syntax */
server_name = server_buf + 1;
_pam_log (LOG_ERR,
"reading server address as: %s ",
server_name);
port = strchr(close_bracket, ':');
*close_bracket = '\0';
} else { /* Fall back to traditional syntax */
server_name = server_buf;
port = strchr(server_buf, ':');
}
if (port != NULL) {
*port = '\0';
port++;
}
_pam_log (LOG_DEBUG,
"sending server address to getaddrinfo as: %s ",
server_name);
if ((rv = getaddrinfo(server_name, (port == NULL) ? "49" : port, &hints, &servers)) == 0) {
for (server = servers;
server != NULL && tac_srv_no < TAC_PLUS_MAXSERVERS; server = server->ai_next) {
set_tac_srv_addr(tac_srv_no, server);
set_tac_srv_key(tac_srv_no, current_secret);
tac_srv_no++;
}
_pam_log(LOG_DEBUG, "%s: server index %d ", __FUNCTION__, tac_srv_no);
freeaddrinfo (servers);
} else {
_pam_log(LOG_ERR,
"skip invalid server: %s (getaddrinfo: %s)",
server_name, gai_strerror(rv));
}
} else {
_pam_log(LOG_ERR, "maximum number of servers (%d) exceeded, skipping",
TAC_PLUS_MAXSERVERS);
}
} else if (!strncmp(*argv, "secret=", 7)) {
current_secret = *argv + 7; /* points right into argv (which is const) */
// this is possible because server structure is initialized only on the server= occurence
if (tac_srv_no == 0) {
_pam_log(LOG_ERR, "secret set but no servers configured yet");
} else {
// set secret for the last server configured
set_tac_srv_key(tac_srv_no - 1, current_secret);
}
} else if (!strncmp(*argv, "timeout=", 8)) {
#ifdef HAVE_STRTOL
tac_timeout = strtol(*argv + 8, NULL, 10);
#else
tac_timeout = atoi(*argv + 8);
#endif
if (tac_timeout == LONG_MAX) {
_pam_log(LOG_ERR, "timeout parameter cannot be parsed as integer: %s", *argv);
tac_timeout = 0;
} else {
tac_readtimeout_enable = 1;
}
} else {
_pam_log(LOG_WARNING, "unrecognized option: %s", *argv);
}
}
if (ctrl & PAM_TAC_DEBUG) {
unsigned long n;
_pam_log(LOG_DEBUG, "%d servers defined", tac_srv_no);
for (n = 0; n < tac_srv_no; n++) {
_pam_log(LOG_DEBUG, "server[%lu] { addr=%s, key='%s' }", n, tac_ntop(tac_srv[n].addr->ai_addr),
tac_srv[n].key);
}
_pam_log(LOG_DEBUG, "tac_service='%s'", tac_service);
_pam_log(LOG_DEBUG, "tac_protocol='%s'", tac_protocol);
_pam_log(LOG_DEBUG, "tac_prompt='%s'", tac_prompt);
_pam_log(LOG_DEBUG, "tac_login='%s'", tac_login);
}
return ctrl;
} /* _pam_parse */ | 935 | True | 1 |
|
CVE-2016-2347 | False | False | False | True | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.0/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H | LOCAL | LOW | NONE | REQUIRED | UNCHANGED | HIGH | HIGH | HIGH | 7.8 | HIGH | 1.8 | 5.9 | nan | [{'url': 'https://github.com/fragglet/lhasa/releases/tag/v0.3.1', 'name': 'https://github.com/fragglet/lhasa/releases/tag/v0.3.1', 'refsource': 'CONFIRM', 'tags': ['Issue Tracking', 'Patch', 'Third Party Advisory']}, {'url': 'https://github.com/fragglet/lhasa/commit/6fcdb8f1f538b9d63e63a5fa199c5514a15d4564', 'name': 'https://github.com/fragglet/lhasa/commit/6fcdb8f1f538b9d63e63a5fa199c5514a15d4564', 'refsource': 'CONFIRM', 'tags': ['Issue Tracking', 'Patch', 'Third Party Advisory']}, {'url': 'http://www.talosintelligence.com/reports/TALOS-2016-0095/', 'name': 'http://www.talosintelligence.com/reports/TALOS-2016-0095/', 'refsource': 'MISC', 'tags': ['Exploit', 'Technical Description', 'Third Party Advisory']}, {'url': 'http://www.debian.org/security/2016/dsa-3540', 'name': 'DSA-3540', 'refsource': 'DEBIAN', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-04/msg00039.html', 'name': 'openSUSE-SU-2016:1029', 'refsource': 'SUSE', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-04/msg00038.html', 'name': 'openSUSE-SU-2016:1027', 'refsource': 'SUSE', 'tags': ['Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-190'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:42.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:opensuse:13.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:7.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:lhasa_project:lhasa:*:*:*:*:*:*:*:*', 'versionEndIncluding': '0.3.0', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'Integer underflow in the decode_level3_header function in lib/lha_file_header.c in Lhasa before 0.3.1 allows remote attackers to execute arbitrary code via a crafted archive.'}] | 2018-10-30T16:27Z | 2017-04-21T20:59Z | Integer Overflow or Wraparound | The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control. | An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.
| https://cwe.mitre.org/data/definitions/190.html | 0 | Simon Howard | 2016-03-17 00:40:19-04:00 | Fix integer underflow vulnerability in L3 decode.
Marcin 'Icewall' Noga of Cisco TALOS discovered that the level 3 header
decoding routines were vulnerable to an integer underflow, if the 32-bit
header length was less than the base level 3 header length. This could
lead to an exploitable heap corruption condition.
Thanks go to Marcin Noga and Regina Wilson of Cisco TALOS for reporting
this vulnerability. | 6fcdb8f1f538b9d63e63a5fa199c5514a15d4564 | False | fragglet/lhasa | Free Software LHA implementation | 2011-04-28 20:31:32 | 2022-08-10 18:11:30 | http://fragglet.github.io/lhasa/ | fragglet | 68.0 | 10.0 | decode_level3_header | decode_level3_header( LHAFileHeader ** header , LHAInputStream * stream) | ['header', 'stream'] | static int decode_level3_header(LHAFileHeader **header, LHAInputStream *stream)
{
unsigned int header_len;
// The first field at the start of a level 3 header is supposed to
// indicate word size, with the idea being that the header format
// can be extended beyond 32-bit words in the future. In practise,
// nothing supports anything other than 32-bit (4 bytes), and neither
// do we.
if (lha_decode_uint16(&RAW_DATA(header, 0)) != 4) {
return 0;
}
// Read the full header.
if (!extend_raw_data(header, stream,
LEVEL_3_HEADER_LEN - RAW_DATA_LEN(header))) {
return 0;
}
// Read the header length field (including extended headers), and
// extend to this full length. Because this is a 32-bit value,
// we must place a sensible limit on the amount of data that will
// be read, to avoid possibly allocating gigabytes of memory.
header_len = lha_decode_uint32(&RAW_DATA(header, 24));
if (header_len > LEVEL_3_MAX_HEADER_LEN) {
return 0;
}
if (!extend_raw_data(header, stream,
header_len - RAW_DATA_LEN(header))) {
return 0;
}
// Compression method:
memcpy((*header)->compress_method, &RAW_DATA(header, 2), 5);
(*header)->compress_method[5] = '\0';
// File lengths:
(*header)->compressed_length = lha_decode_uint32(&RAW_DATA(header, 7));
(*header)->length = lha_decode_uint32(&RAW_DATA(header, 11));
// Unix-style timestamp.
(*header)->timestamp = lha_decode_uint32(&RAW_DATA(header, 15));
// CRC.
(*header)->crc = lha_decode_uint16(&RAW_DATA(header, 21));
// OS type:
(*header)->os_type = RAW_DATA(header, 23);
if (!decode_extended_headers(header, 28)) {
return 0;
}
return 1;
} | 240 | True | 1 |
CVE-2016-3698 | False | False | False | False | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | HIGH | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 8.1 | HIGH | 2.2 | 5.9 | nan | [{'url': 'https://github.com/jpirko/libndp/commit/2af9a55b38b55abbf05fd116ec097d4029115839', 'name': 'https://github.com/jpirko/libndp/commit/2af9a55b38b55abbf05fd116ec097d4029115839', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://rhn.redhat.com/errata/RHSA-2016-1086.html', 'name': 'RHSA-2016:1086', 'refsource': 'REDHAT', 'tags': []}, {'url': 'http://www.openwall.com/lists/oss-security/2016/05/17/9', 'name': '[oss-security] 20160517 RHSA-2016:1086 libndp: denial of service due to insufficient validation of source of NDP messages', 'refsource': 'MLIST', 'tags': []}, {'url': 'http://www.debian.org/security/2016/dsa-3581', 'name': 'DSA-3581', 'refsource': 'DEBIAN', 'tags': []}, {'url': 'https://github.com/jpirko/libndp/commit/a4892df306e0532487f1634ba6d4c6d4bb381c7f', 'name': 'https://github.com/jpirko/libndp/commit/a4892df306e0532487f1634ba6d4c6d4bb381c7f', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'http://www.ubuntu.com/usn/USN-2980-1', 'name': 'USN-2980-1', 'refsource': 'UBUNTU', 'tags': []}, {'url': 'http://www.oracle.com/technetwork/topics/security/linuxbulletinapr2016-2952096.html', 'name': 'http://www.oracle.com/technetwork/topics/security/linuxbulletinapr2016-2952096.html', 'refsource': 'CONFIRM', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-284'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_desktop:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server_aus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_workstation:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_hpc_node:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server_eus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_hpc_node_eus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:libndp:libndp:*:*:*:*:*:*:*:*', 'versionEndIncluding': '1.5', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:15.10:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libndp before 1.6, as used in NetworkManager, does not properly validate the origin of Neighbor Discovery Protocol (NDP) messages, which allows remote attackers to conduct man-in-the-middle attacks or cause a denial of service (network connectivity disruption) by advertising a node as a router from a non-local network.'}] | 2016-10-04T02:08Z | 2016-06-13T19:59Z | Improper Access Control | The software does not restrict or incorrectly restricts access to a resource from an unauthorized actor. |
Access control involves the use of several protection mechanisms such as:
Authentication (proving the identity of an actor)
Authorization (ensuring that a given actor can access a resource), and
Accountability (tracking of activities that were performed)
When any mechanism is not applied or otherwise fails, attackers can compromise the security of the software by gaining privileges, reading sensitive information, executing commands, evading detection, etc.
There are two distinct behaviors that can introduce access control weaknesses:
Specification: incorrect privileges, permissions, ownership, etc. are explicitly specified for either the user or the resource (for example, setting a password file to be world-writable, or giving administrator capabilities to a guest user). This action could be performed by the program or the administrator.
Enforcement: the mechanism contains errors that prevent it from properly enforcing the specified access control requirements (e.g., allowing the user to specify their own privileges, or allowing a syntactically-incorrect ACL to produce insecure settings). This problem occurs within the program itself, in that it does not actually enforce the intended security policy that the administrator specifies.
| https://cwe.mitre.org/data/definitions/284.html | 0 | Lubomir Rintel | 2016-05-17 12:17:53+02:00 | libndp: validate the IPv6 hop limit
None of the NDP messages should ever come from a non-local network; as
stated in RFC4861's 6.1.1 (RS), 6.1.2 (RA), 7.1.1 (NS), 7.1.2 (NA),
and 8.1. (redirect):
- The IP Hop Limit field has a value of 255, i.e., the packet
could not possibly have been forwarded by a router.
This fixes CVE-2016-3698.
Reported by: Julien BERNARD <[email protected]>
Signed-off-by: Lubomir Rintel <[email protected]>
Signed-off-by: Jiri Pirko <[email protected]> | a4892df306e0532487f1634ba6d4c6d4bb381c7f | False | jpirko/libndp | Neighbor Discovery library | 2013-03-15 14:34:13 | 2022-03-28 08:17:14 | jpirko | 33.0 | 18.0 | myrecvfrom6 | myrecvfrom6( int sockfd , void * buf , size_t * buflen , int flags , struct in6_addr * addr , uint32_t * ifindex) | ['sockfd', 'buf', 'buflen', 'flags', 'addr', 'ifindex'] | static int myrecvfrom6(int sockfd, void *buf, size_t *buflen, int flags,
struct in6_addr *addr, uint32_t *ifindex)
{
struct sockaddr_in6 sin6;
unsigned char cbuf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
struct iovec iovec;
struct msghdr msghdr;
struct cmsghdr *cmsghdr;
ssize_t len;
iovec.iov_len = *buflen;
iovec.iov_base = buf;
memset(&msghdr, 0, sizeof(msghdr));
msghdr.msg_name = &sin6;
msghdr.msg_namelen = sizeof(sin6);
msghdr.msg_iov = &iovec;
msghdr.msg_iovlen = 1;
msghdr.msg_control = cbuf;
msghdr.msg_controllen = sizeof(cbuf);
len = recvmsg(sockfd, &msghdr, flags);
if (len == -1)
return -errno;
*buflen = len;
/* Set ifindex to scope_id now. But since scope_id gets not
* set by kernel for linklocal addresses, use pktinfo to obtain that
* value right after.
*/
*ifindex = sin6.sin6_scope_id;
for (cmsghdr = CMSG_FIRSTHDR(&msghdr); cmsghdr;
cmsghdr = CMSG_NXTHDR(&msghdr, cmsghdr)) {
if (cmsghdr->cmsg_level == IPPROTO_IPV6 &&
cmsghdr->cmsg_type == IPV6_PKTINFO &&
cmsghdr->cmsg_len == CMSG_LEN(sizeof(struct in6_pktinfo))) {
struct in6_pktinfo *pktinfo;
pktinfo = (struct in6_pktinfo *) CMSG_DATA(cmsghdr);
*ifindex = pktinfo->ipi6_ifindex;
}
}
*addr = sin6.sin6_addr;
return 0;
} | 253 | True | 1 |
|
CVE-2016-3698 | False | False | False | False | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | HIGH | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 8.1 | HIGH | 2.2 | 5.9 | nan | [{'url': 'https://github.com/jpirko/libndp/commit/2af9a55b38b55abbf05fd116ec097d4029115839', 'name': 'https://github.com/jpirko/libndp/commit/2af9a55b38b55abbf05fd116ec097d4029115839', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://rhn.redhat.com/errata/RHSA-2016-1086.html', 'name': 'RHSA-2016:1086', 'refsource': 'REDHAT', 'tags': []}, {'url': 'http://www.openwall.com/lists/oss-security/2016/05/17/9', 'name': '[oss-security] 20160517 RHSA-2016:1086 libndp: denial of service due to insufficient validation of source of NDP messages', 'refsource': 'MLIST', 'tags': []}, {'url': 'http://www.debian.org/security/2016/dsa-3581', 'name': 'DSA-3581', 'refsource': 'DEBIAN', 'tags': []}, {'url': 'https://github.com/jpirko/libndp/commit/a4892df306e0532487f1634ba6d4c6d4bb381c7f', 'name': 'https://github.com/jpirko/libndp/commit/a4892df306e0532487f1634ba6d4c6d4bb381c7f', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'http://www.ubuntu.com/usn/USN-2980-1', 'name': 'USN-2980-1', 'refsource': 'UBUNTU', 'tags': []}, {'url': 'http://www.oracle.com/technetwork/topics/security/linuxbulletinapr2016-2952096.html', 'name': 'http://www.oracle.com/technetwork/topics/security/linuxbulletinapr2016-2952096.html', 'refsource': 'CONFIRM', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-284'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_desktop:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server_aus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_workstation:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_hpc_node:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server_eus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_hpc_node_eus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:libndp:libndp:*:*:*:*:*:*:*:*', 'versionEndIncluding': '1.5', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:15.10:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libndp before 1.6, as used in NetworkManager, does not properly validate the origin of Neighbor Discovery Protocol (NDP) messages, which allows remote attackers to conduct man-in-the-middle attacks or cause a denial of service (network connectivity disruption) by advertising a node as a router from a non-local network.'}] | 2016-10-04T02:08Z | 2016-06-13T19:59Z | Improper Access Control | The software does not restrict or incorrectly restricts access to a resource from an unauthorized actor. |
Access control involves the use of several protection mechanisms such as:
Authentication (proving the identity of an actor)
Authorization (ensuring that a given actor can access a resource), and
Accountability (tracking of activities that were performed)
When any mechanism is not applied or otherwise fails, attackers can compromise the security of the software by gaining privileges, reading sensitive information, executing commands, evading detection, etc.
There are two distinct behaviors that can introduce access control weaknesses:
Specification: incorrect privileges, permissions, ownership, etc. are explicitly specified for either the user or the resource (for example, setting a password file to be world-writable, or giving administrator capabilities to a guest user). This action could be performed by the program or the administrator.
Enforcement: the mechanism contains errors that prevent it from properly enforcing the specified access control requirements (e.g., allowing the user to specify their own privileges, or allowing a syntactically-incorrect ACL to produce insecure settings). This problem occurs within the program itself, in that it does not actually enforce the intended security policy that the administrator specifies.
| https://cwe.mitre.org/data/definitions/284.html | 0 | Lubomir Rintel | 2016-05-17 12:17:53+02:00 | libndp: validate the IPv6 hop limit
None of the NDP messages should ever come from a non-local network; as
stated in RFC4861's 6.1.1 (RS), 6.1.2 (RA), 7.1.1 (NS), 7.1.2 (NA),
and 8.1. (redirect):
- The IP Hop Limit field has a value of 255, i.e., the packet
could not possibly have been forwarded by a router.
This fixes CVE-2016-3698.
Reported by: Julien BERNARD <[email protected]>
Signed-off-by: Lubomir Rintel <[email protected]>
Signed-off-by: Jiri Pirko <[email protected]> | a4892df306e0532487f1634ba6d4c6d4bb381c7f | False | jpirko/libndp | Neighbor Discovery library | 2013-03-15 14:34:13 | 2022-03-28 08:17:14 | jpirko | 33.0 | 18.0 | ndp_sock_recv | ndp_sock_recv( struct ndp * ndp) | ['ndp'] | static int ndp_sock_recv(struct ndp *ndp)
{
struct ndp_msg *msg;
enum ndp_msg_type msg_type;
size_t len;
int err;
msg = ndp_msg_alloc();
if (!msg)
return -ENOMEM;
len = ndp_msg_payload_maxlen(msg);
err = myrecvfrom6(ndp->sock, msg->buf, &len, 0,
&msg->addrto, &msg->ifindex);
if (err) {
err(ndp, "Failed to receive message");
goto free_msg;
}
dbg(ndp, "rcvd from: %s, ifindex: %u",
str_in6_addr(&msg->addrto), msg->ifindex);
if (len < sizeof(*msg->icmp6_hdr)) {
warn(ndp, "rcvd icmp6 packet too short (%luB)", len);
err = 0;
goto free_msg;
}
err = ndp_msg_type_by_raw_type(&msg_type, msg->icmp6_hdr->icmp6_type);
if (err) {
err = 0;
goto free_msg;
}
ndp_msg_init(msg, msg_type);
ndp_msg_payload_len_set(msg, len);
if (!ndp_msg_check_valid(msg)) {
warn(ndp, "rcvd invalid ND message");
err = 0;
goto free_msg;
}
dbg(ndp, "rcvd %s, len: %zuB",
ndp_msg_type_info(msg_type)->strabbr, len);
if (!ndp_msg_check_opts(msg)) {
err = 0;
goto free_msg;
}
err = ndp_call_handlers(ndp, msg);;
free_msg:
ndp_msg_destroy(msg);
return err;
} | 257 | True | 1 |
|
CVE-2016-3698 | False | False | False | False | AV:N/AC:M/Au:N/C:P/I:P/A:P | NETWORK | MEDIUM | NONE | PARTIAL | PARTIAL | PARTIAL | 6.8 | CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | HIGH | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 8.1 | HIGH | 2.2 | 5.9 | nan | [{'url': 'https://github.com/jpirko/libndp/commit/2af9a55b38b55abbf05fd116ec097d4029115839', 'name': 'https://github.com/jpirko/libndp/commit/2af9a55b38b55abbf05fd116ec097d4029115839', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'https://rhn.redhat.com/errata/RHSA-2016-1086.html', 'name': 'RHSA-2016:1086', 'refsource': 'REDHAT', 'tags': []}, {'url': 'http://www.openwall.com/lists/oss-security/2016/05/17/9', 'name': '[oss-security] 20160517 RHSA-2016:1086 libndp: denial of service due to insufficient validation of source of NDP messages', 'refsource': 'MLIST', 'tags': []}, {'url': 'http://www.debian.org/security/2016/dsa-3581', 'name': 'DSA-3581', 'refsource': 'DEBIAN', 'tags': []}, {'url': 'https://github.com/jpirko/libndp/commit/a4892df306e0532487f1634ba6d4c6d4bb381c7f', 'name': 'https://github.com/jpirko/libndp/commit/a4892df306e0532487f1634ba6d4c6d4bb381c7f', 'refsource': 'CONFIRM', 'tags': []}, {'url': 'http://www.ubuntu.com/usn/USN-2980-1', 'name': 'USN-2980-1', 'refsource': 'UBUNTU', 'tags': []}, {'url': 'http://www.oracle.com/technetwork/topics/security/linuxbulletinapr2016-2952096.html', 'name': 'http://www.oracle.com/technetwork/topics/security/linuxbulletinapr2016-2952096.html', 'refsource': 'CONFIRM', 'tags': []}] | [{'description': [{'lang': 'en', 'value': 'CWE-284'}]}] | MEDIUM | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_desktop:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server_aus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_workstation:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_hpc_node:7.0:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_server_eus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:redhat:enterprise_linux_hpc_node_eus:7.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:libndp:libndp:*:*:*:*:*:*:*:*', 'versionEndIncluding': '1.5', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:lts:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:canonical:ubuntu_linux:15.10:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'libndp before 1.6, as used in NetworkManager, does not properly validate the origin of Neighbor Discovery Protocol (NDP) messages, which allows remote attackers to conduct man-in-the-middle attacks or cause a denial of service (network connectivity disruption) by advertising a node as a router from a non-local network.'}] | 2016-10-04T02:08Z | 2016-06-13T19:59Z | Improper Access Control | The software does not restrict or incorrectly restricts access to a resource from an unauthorized actor. |
Access control involves the use of several protection mechanisms such as:
Authentication (proving the identity of an actor)
Authorization (ensuring that a given actor can access a resource), and
Accountability (tracking of activities that were performed)
When any mechanism is not applied or otherwise fails, attackers can compromise the security of the software by gaining privileges, reading sensitive information, executing commands, evading detection, etc.
There are two distinct behaviors that can introduce access control weaknesses:
Specification: incorrect privileges, permissions, ownership, etc. are explicitly specified for either the user or the resource (for example, setting a password file to be world-writable, or giving administrator capabilities to a guest user). This action could be performed by the program or the administrator.
Enforcement: the mechanism contains errors that prevent it from properly enforcing the specified access control requirements (e.g., allowing the user to specify their own privileges, or allowing a syntactically-incorrect ACL to produce insecure settings). This problem occurs within the program itself, in that it does not actually enforce the intended security policy that the administrator specifies.
| https://cwe.mitre.org/data/definitions/284.html | 0 | Lubomir Rintel | 2016-05-17 12:17:54+02:00 | libndb: reject redirect and router advertisements from non-link-local
RFC4861 suggests that these messages should only originate from
link-local addresses in 6.1.2 (RA) and 8.1. (redirect):
Mitigates CVE-2016-3698.
Signed-off-by: Lubomir Rintel <[email protected]>
Signed-off-by: Jiri Pirko <[email protected]> | 2af9a55b38b55abbf05fd116ec097d4029115839 | False | jpirko/libndp | Neighbor Discovery library | 2013-03-15 14:34:13 | 2022-03-28 08:17:14 | jpirko | 33.0 | 18.0 | ndp_msg_check_valid | ndp_msg_check_valid( struct ndp_msg * msg) | ['msg'] | static bool ndp_msg_check_valid(struct ndp_msg *msg)
{
size_t len = ndp_msg_payload_len(msg);
enum ndp_msg_type msg_type = ndp_msg_type(msg);
if (len < ndp_msg_type_info(msg_type)->raw_struct_size)
return false;
return true;
} | 43 | True | 1 |
|
CVE-2016-4303 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'name': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00090.html', 'name': 'openSUSE-SU-2016:2121', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'name': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'name': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'refsource': 'CONFIRM', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'name': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00082.html', 'name': 'openSUSE-SU-2016:2113', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'name': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2020/01/msg00023.html', 'name': '[debian-lts-announce] 20200127 [SECURITY] [DLA 2080-1] iperf3 security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-120'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.1', 'versionEndExcluding': '3.1.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.0', 'versionEndExcluding': '3.0.12', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:novell:suse_package_hub_for_suse_linux_enterprise:12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:42.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:opensuse:13.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'The parse_string function in cjson.c in the cJSON library mishandles UTF8/16 strings, which allows remote attackers to cause a denial of service (crash) or execute arbitrary code via a non-hex character in a JSON string, which triggers a heap-based buffer overflow.'}] | 2022-06-30T15:13Z | 2016-09-26T14:59Z | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
| https://cwe.mitre.org/data/definitions/120.html | 0 | Bruce A. Mah | 2016-06-03 09:23:59-07:00 | Fix a buffer overflow / heap corruption issue that could occur if a
malformed JSON string was passed on the control channel. This issue,
present in the cJSON library, was already fixed upstream, so was
addressed here in iperf3 by importing a newer version of cJSON (plus
local ESnet modifications).
Discovered and reported by Dave McDaniel, Cisco Talos.
Based on a patch by @dopheide-esnet, with input from @DaveGamble.
Cross-references: TALOS-CAN-0164, ESNET-SECADV-2016-0001,
CVE-2016-4303
(cherry picked from commit ed94082be27d971a5e1b08b666e2c217cf470a40)
Signed-off-by: Bruce A. Mah <[email protected]> | 91f2fa59e8ed80dfbf400add0164ee0e508e412a | False | esnet/iperf | iperf3: A TCP, UDP, and SCTP network bandwidth measurement tool | 2014-02-25 18:42:52 | 2022-08-26 21:20:45 | esnet | 4609.0 | 1044.0 | cJSON_AddItemReferenceToArray | cJSON_AddItemReferenceToArray( cJSON * array , cJSON * item) | ['array', 'item'] | void cJSON_AddItemReferenceToArray( cJSON *array, cJSON *item )
{
cJSON_AddItemToArray( array, create_reference( item ) );
} | 22 | True | 1 |
|
CVE-2016-4303 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'name': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00090.html', 'name': 'openSUSE-SU-2016:2121', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'name': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'name': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'refsource': 'CONFIRM', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'name': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00082.html', 'name': 'openSUSE-SU-2016:2113', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'name': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2020/01/msg00023.html', 'name': '[debian-lts-announce] 20200127 [SECURITY] [DLA 2080-1] iperf3 security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-120'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.1', 'versionEndExcluding': '3.1.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.0', 'versionEndExcluding': '3.0.12', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:novell:suse_package_hub_for_suse_linux_enterprise:12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:42.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:opensuse:13.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'The parse_string function in cjson.c in the cJSON library mishandles UTF8/16 strings, which allows remote attackers to cause a denial of service (crash) or execute arbitrary code via a non-hex character in a JSON string, which triggers a heap-based buffer overflow.'}] | 2022-06-30T15:13Z | 2016-09-26T14:59Z | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
| https://cwe.mitre.org/data/definitions/120.html | 0 | Bruce A. Mah | 2016-06-03 09:23:59-07:00 | Fix a buffer overflow / heap corruption issue that could occur if a
malformed JSON string was passed on the control channel. This issue,
present in the cJSON library, was already fixed upstream, so was
addressed here in iperf3 by importing a newer version of cJSON (plus
local ESnet modifications).
Discovered and reported by Dave McDaniel, Cisco Talos.
Based on a patch by @dopheide-esnet, with input from @DaveGamble.
Cross-references: TALOS-CAN-0164, ESNET-SECADV-2016-0001,
CVE-2016-4303
(cherry picked from commit ed94082be27d971a5e1b08b666e2c217cf470a40)
Signed-off-by: Bruce A. Mah <[email protected]> | 91f2fa59e8ed80dfbf400add0164ee0e508e412a | False | esnet/iperf | iperf3: A TCP, UDP, and SCTP network bandwidth measurement tool | 2014-02-25 18:42:52 | 2022-08-26 21:20:45 | esnet | 4609.0 | 1044.0 | cJSON_AddItemReferenceToObject | cJSON_AddItemReferenceToObject( cJSON * object , const char * string , cJSON * item) | ['object', 'string', 'item'] | void cJSON_AddItemReferenceToObject( cJSON *object, const char *string, cJSON *item )
{
cJSON_AddItemToObject( object, string, create_reference( item ) );
} | 29 | True | 1 |
|
CVE-2016-4303 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'name': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00090.html', 'name': 'openSUSE-SU-2016:2121', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'name': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'name': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'refsource': 'CONFIRM', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'name': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00082.html', 'name': 'openSUSE-SU-2016:2113', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'name': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2020/01/msg00023.html', 'name': '[debian-lts-announce] 20200127 [SECURITY] [DLA 2080-1] iperf3 security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-120'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.1', 'versionEndExcluding': '3.1.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.0', 'versionEndExcluding': '3.0.12', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:novell:suse_package_hub_for_suse_linux_enterprise:12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:42.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:opensuse:13.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'The parse_string function in cjson.c in the cJSON library mishandles UTF8/16 strings, which allows remote attackers to cause a denial of service (crash) or execute arbitrary code via a non-hex character in a JSON string, which triggers a heap-based buffer overflow.'}] | 2022-06-30T15:13Z | 2016-09-26T14:59Z | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
| https://cwe.mitre.org/data/definitions/120.html | 0 | Bruce A. Mah | 2016-06-03 09:23:59-07:00 | Fix a buffer overflow / heap corruption issue that could occur if a
malformed JSON string was passed on the control channel. This issue,
present in the cJSON library, was already fixed upstream, so was
addressed here in iperf3 by importing a newer version of cJSON (plus
local ESnet modifications).
Discovered and reported by Dave McDaniel, Cisco Talos.
Based on a patch by @dopheide-esnet, with input from @DaveGamble.
Cross-references: TALOS-CAN-0164, ESNET-SECADV-2016-0001,
CVE-2016-4303
(cherry picked from commit ed94082be27d971a5e1b08b666e2c217cf470a40)
Signed-off-by: Bruce A. Mah <[email protected]> | 91f2fa59e8ed80dfbf400add0164ee0e508e412a | False | esnet/iperf | iperf3: A TCP, UDP, and SCTP network bandwidth measurement tool | 2014-02-25 18:42:52 | 2022-08-26 21:20:45 | esnet | 4609.0 | 1044.0 | cJSON_AddItemToArray | cJSON_AddItemToArray( cJSON * array , cJSON * item) | ['array', 'item'] | void cJSON_AddItemToArray( cJSON *array, cJSON *item )
{
cJSON *c = array->child;
if ( ! item )
return;
if ( ! c ) {
array->child = item;
} else {
while ( c && c->next )
c = c->next;
suffix_object( c, item );
}
} | 64 | True | 1 |
|
CVE-2016-4303 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'name': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00090.html', 'name': 'openSUSE-SU-2016:2121', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'name': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'name': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'refsource': 'CONFIRM', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'name': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00082.html', 'name': 'openSUSE-SU-2016:2113', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'name': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2020/01/msg00023.html', 'name': '[debian-lts-announce] 20200127 [SECURITY] [DLA 2080-1] iperf3 security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-120'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.1', 'versionEndExcluding': '3.1.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.0', 'versionEndExcluding': '3.0.12', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:novell:suse_package_hub_for_suse_linux_enterprise:12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:42.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:opensuse:13.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'The parse_string function in cjson.c in the cJSON library mishandles UTF8/16 strings, which allows remote attackers to cause a denial of service (crash) or execute arbitrary code via a non-hex character in a JSON string, which triggers a heap-based buffer overflow.'}] | 2022-06-30T15:13Z | 2016-09-26T14:59Z | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
| https://cwe.mitre.org/data/definitions/120.html | 0 | Bruce A. Mah | 2016-06-03 09:23:59-07:00 | Fix a buffer overflow / heap corruption issue that could occur if a
malformed JSON string was passed on the control channel. This issue,
present in the cJSON library, was already fixed upstream, so was
addressed here in iperf3 by importing a newer version of cJSON (plus
local ESnet modifications).
Discovered and reported by Dave McDaniel, Cisco Talos.
Based on a patch by @dopheide-esnet, with input from @DaveGamble.
Cross-references: TALOS-CAN-0164, ESNET-SECADV-2016-0001,
CVE-2016-4303
(cherry picked from commit ed94082be27d971a5e1b08b666e2c217cf470a40)
Signed-off-by: Bruce A. Mah <[email protected]> | 91f2fa59e8ed80dfbf400add0164ee0e508e412a | False | esnet/iperf | iperf3: A TCP, UDP, and SCTP network bandwidth measurement tool | 2014-02-25 18:42:52 | 2022-08-26 21:20:45 | esnet | 4609.0 | 1044.0 | cJSON_AddItemToObject | cJSON_AddItemToObject( cJSON * object , const char * string , cJSON * item) | ['object', 'string', 'item'] | void cJSON_AddItemToObject( cJSON *object, const char *string, cJSON *item )
{
if ( ! item )
return;
if ( item->string )
cJSON_free( item->string );
item->string = cJSON_strdup( string );
cJSON_AddItemToArray( object, item );
} | 53 | True | 1 |
|
CVE-2016-4303 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'name': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00090.html', 'name': 'openSUSE-SU-2016:2121', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'name': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'name': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'refsource': 'CONFIRM', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'name': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00082.html', 'name': 'openSUSE-SU-2016:2113', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'name': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2020/01/msg00023.html', 'name': '[debian-lts-announce] 20200127 [SECURITY] [DLA 2080-1] iperf3 security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-120'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.1', 'versionEndExcluding': '3.1.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.0', 'versionEndExcluding': '3.0.12', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:novell:suse_package_hub_for_suse_linux_enterprise:12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:42.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:opensuse:13.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'The parse_string function in cjson.c in the cJSON library mishandles UTF8/16 strings, which allows remote attackers to cause a denial of service (crash) or execute arbitrary code via a non-hex character in a JSON string, which triggers a heap-based buffer overflow.'}] | 2022-06-30T15:13Z | 2016-09-26T14:59Z | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
| https://cwe.mitre.org/data/definitions/120.html | 0 | Bruce A. Mah | 2016-06-03 09:23:59-07:00 | Fix a buffer overflow / heap corruption issue that could occur if a
malformed JSON string was passed on the control channel. This issue,
present in the cJSON library, was already fixed upstream, so was
addressed here in iperf3 by importing a newer version of cJSON (plus
local ESnet modifications).
Discovered and reported by Dave McDaniel, Cisco Talos.
Based on a patch by @dopheide-esnet, with input from @DaveGamble.
Cross-references: TALOS-CAN-0164, ESNET-SECADV-2016-0001,
CVE-2016-4303
(cherry picked from commit ed94082be27d971a5e1b08b666e2c217cf470a40)
Signed-off-by: Bruce A. Mah <[email protected]> | 91f2fa59e8ed80dfbf400add0164ee0e508e412a | False | esnet/iperf | iperf3: A TCP, UDP, and SCTP network bandwidth measurement tool | 2014-02-25 18:42:52 | 2022-08-26 21:20:45 | esnet | 4609.0 | 1044.0 | cJSON_CreateArray | cJSON_CreateArray( void) | ['void'] | cJSON *cJSON_CreateArray( void )
{
cJSON *item = cJSON_New_Item();
if ( item )
item->type = cJSON_Array;
return item;
} | 27 | True | 1 |
|
CVE-2016-4303 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'name': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00090.html', 'name': 'openSUSE-SU-2016:2121', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'name': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'name': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'refsource': 'CONFIRM', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'name': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00082.html', 'name': 'openSUSE-SU-2016:2113', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'name': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2020/01/msg00023.html', 'name': '[debian-lts-announce] 20200127 [SECURITY] [DLA 2080-1] iperf3 security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-120'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.1', 'versionEndExcluding': '3.1.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.0', 'versionEndExcluding': '3.0.12', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:novell:suse_package_hub_for_suse_linux_enterprise:12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:42.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:opensuse:13.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'The parse_string function in cjson.c in the cJSON library mishandles UTF8/16 strings, which allows remote attackers to cause a denial of service (crash) or execute arbitrary code via a non-hex character in a JSON string, which triggers a heap-based buffer overflow.'}] | 2022-06-30T15:13Z | 2016-09-26T14:59Z | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
| https://cwe.mitre.org/data/definitions/120.html | 0 | Bruce A. Mah | 2016-06-03 09:23:59-07:00 | Fix a buffer overflow / heap corruption issue that could occur if a
malformed JSON string was passed on the control channel. This issue,
present in the cJSON library, was already fixed upstream, so was
addressed here in iperf3 by importing a newer version of cJSON (plus
local ESnet modifications).
Discovered and reported by Dave McDaniel, Cisco Talos.
Based on a patch by @dopheide-esnet, with input from @DaveGamble.
Cross-references: TALOS-CAN-0164, ESNET-SECADV-2016-0001,
CVE-2016-4303
(cherry picked from commit ed94082be27d971a5e1b08b666e2c217cf470a40)
Signed-off-by: Bruce A. Mah <[email protected]> | 91f2fa59e8ed80dfbf400add0164ee0e508e412a | False | esnet/iperf | iperf3: A TCP, UDP, and SCTP network bandwidth measurement tool | 2014-02-25 18:42:52 | 2022-08-26 21:20:45 | esnet | 4609.0 | 1044.0 | cJSON_CreateBool | cJSON_CreateBool( int b) | ['b'] | cJSON *cJSON_CreateBool( int b )
{
cJSON *item = cJSON_New_Item();
if ( item )
item->type = b ? cJSON_True : cJSON_False;
return item;
} | 32 | True | 1 |
|
CVE-2016-4303 | False | False | False | False | AV:N/AC:L/Au:N/C:P/I:P/A:P | NETWORK | LOW | NONE | PARTIAL | PARTIAL | PARTIAL | 7.5 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | NETWORK | LOW | NONE | NONE | UNCHANGED | HIGH | HIGH | HIGH | 9.8 | CRITICAL | 3.9 | 5.9 | nan | [{'url': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'name': 'https://github.com/esnet/iperf/commit/91f2fa59e8ed80dfbf400add0164ee0e508e412a', 'refsource': 'CONFIRM', 'tags': ['Patch', 'Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00090.html', 'name': 'openSUSE-SU-2016:2121', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'name': 'http://www.talosintelligence.com/reports/TALOS-2016-0164/', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'name': 'http://software.es.net/iperf/news.html#security-issue-iperf-3-1-3-iperf-3-0-12-released', 'refsource': 'CONFIRM', 'tags': ['Release Notes', 'Third Party Advisory']}, {'url': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'name': 'https://raw.githubusercontent.com/esnet/security/master/cve-2016-4303/esnet-secadv-2016-0001.txt.asc', 'refsource': 'CONFIRM', 'tags': ['Third Party Advisory']}, {'url': 'http://lists.opensuse.org/opensuse-updates/2016-08/msg00082.html', 'name': 'openSUSE-SU-2016:2113', 'refsource': 'SUSE', 'tags': ['Mailing List', 'Third Party Advisory']}, {'url': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'name': 'http://blog.talosintel.com/2016/06/esnet-vulnerability.html', 'refsource': 'MISC', 'tags': ['Exploit', 'Third Party Advisory']}, {'url': 'https://lists.debian.org/debian-lts-announce/2020/01/msg00023.html', 'name': '[debian-lts-announce] 20200127 [SECURITY] [DLA 2080-1] iperf3 security update', 'refsource': 'MLIST', 'tags': ['Mailing List', 'Third Party Advisory']}] | [{'description': [{'lang': 'en', 'value': 'CWE-120'}]}] | HIGH | [{'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.1', 'versionEndExcluding': '3.1.3', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:iperf3_project:iperf3:*:*:*:*:*:*:*:*', 'versionStartIncluding': '3.0', 'versionEndExcluding': '3.0.12', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:a:novell:suse_package_hub_for_suse_linux_enterprise:12:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:leap:42.1:*:*:*:*:*:*:*', 'cpe_name': []}, {'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:opensuse:opensuse:13.2:*:*:*:*:*:*:*', 'cpe_name': []}]}, {'operator': 'OR', 'children': [], 'cpe_match': [{'vulnerable': True, 'cpe23Uri': 'cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*', 'cpe_name': []}]}] | [{'lang': 'en', 'value': 'The parse_string function in cjson.c in the cJSON library mishandles UTF8/16 strings, which allows remote attackers to cause a denial of service (crash) or execute arbitrary code via a non-hex character in a JSON string, which triggers a heap-based buffer overflow.'}] | 2022-06-30T15:13Z | 2016-09-26T14:59Z | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow. | A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
| https://cwe.mitre.org/data/definitions/120.html | 0 | Bruce A. Mah | 2016-06-03 09:23:59-07:00 | Fix a buffer overflow / heap corruption issue that could occur if a
malformed JSON string was passed on the control channel. This issue,
present in the cJSON library, was already fixed upstream, so was
addressed here in iperf3 by importing a newer version of cJSON (plus
local ESnet modifications).
Discovered and reported by Dave McDaniel, Cisco Talos.
Based on a patch by @dopheide-esnet, with input from @DaveGamble.
Cross-references: TALOS-CAN-0164, ESNET-SECADV-2016-0001,
CVE-2016-4303
(cherry picked from commit ed94082be27d971a5e1b08b666e2c217cf470a40)
Signed-off-by: Bruce A. Mah <[email protected]> | 91f2fa59e8ed80dfbf400add0164ee0e508e412a | False | esnet/iperf | iperf3: A TCP, UDP, and SCTP network bandwidth measurement tool | 2014-02-25 18:42:52 | 2022-08-26 21:20:45 | esnet | 4609.0 | 1044.0 | cJSON_CreateFalse | cJSON_CreateFalse( void) | ['void'] | cJSON *cJSON_CreateFalse( void )
{
cJSON *item = cJSON_New_Item();
if ( item )
item->type = cJSON_False;
return item;
} | 27 | True | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.