Permalink
Browse files

patch 8.0.1671: crash when passing non-dict argument as env to job_st…

…art()

Problem:    Crash when passing non-dict argument as env to job_start().
Solution:   Check for valid argument. (Ozaki Kiichi, closes #2765)
  • Loading branch information...
brammool committed Apr 7, 2018
1 parent b6ed74f commit 22efba47deb7e504142487fdc1617ec638cf0683
Showing with 16 additions and 5 deletions.
  1. +7 −1 src/channel.c
  2. +7 −4 src/testdir/test_channel.vim
  3. +2 −0 src/version.c
@@ -4797,9 +4797,15 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
{
if (!(supported2 & JO2_ENV))
break;
if (item->v_type != VAR_DICT)
{
EMSG2(_(e_invargval), "env");
return FAIL;
}
opt->jo_set2 |= JO2_ENV;
opt->jo_env = item->vval.v_dict;
++item->vval.v_dict->dv_refcount;
if (opt->jo_env != NULL)
++opt->jo_env->dv_refcount;
}
else if (STRCMP(hi->hi_key, "cwd") == 0)
{
@@ -1720,10 +1720,12 @@ func Test_env()
let g:envstr = ''
if has('win32')
call job_start(['cmd', '/c', 'echo %FOO%'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'env':{'FOO': 'bar'}})
let cmd = ['cmd', '/c', 'echo %FOO%']
else
call job_start([&shell, &shellcmdflag, 'echo $FOO'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'env':{'FOO': 'bar'}})
let cmd = [&shell, &shellcmdflag, 'echo $FOO']
endif
call assert_fails('call job_start(cmd, {"env": 1})', 'E475:')
call job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'env': {'FOO': 'bar'}})
call WaitFor('"" != g:envstr')
call assert_equal("bar", g:envstr)
unlet g:envstr
@@ -1737,11 +1739,12 @@ func Test_cwd()
let g:envstr = ''
if has('win32')
let expect = $TEMP
let job = job_start(['cmd', '/c', 'echo %CD%'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'cwd': expect})
let cmd = ['cmd', '/c', 'echo %CD%']
else
let expect = $HOME
let job = job_start(['pwd'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'cwd': expect})
let cmd = ['pwd']
endif
let job = job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'cwd': expect})
try
call WaitFor('"" != g:envstr')
let expect = substitute(expect, '[/\\]$', '', '')
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1671,
/**/
1670,
/**/

0 comments on commit 22efba4

Please sign in to comment.