Skip to content

Commit

Permalink
Fix chdir() may crash
Browse files Browse the repository at this point in the history
This crashes.

```vim
let pwd = chdir('non-existing-dir')
call chdir(pwd)
```
  • Loading branch information
k-takata committed Jan 30, 2020
1 parent 92be6e3 commit 63b3972
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6572,6 +6572,8 @@ changedir_func(
int dir_differs;
int retval = FALSE;

if (new_dir == NULL)
return FALSE;
if (allbuf_locked())
return FALSE;

Expand Down
2 changes: 2 additions & 0 deletions src/testdir/test_cd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func Test_chdir_func()
call assert_fails("call chdir('dir-abcd')", 'E472:')
silent! let d = chdir("dir_abcd")
call assert_equal("", d)
" Should not crash
call chdir(d)

only | tabonly
call chdir(topdir)
Expand Down

0 comments on commit 63b3972

Please sign in to comment.