diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-04-06 21:12:42 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-04-06 21:12:42 +0200 |
commit | 15352dc6ec43fd50cc3be4f4fd1ad74d5619da20 (patch) | |
tree | ead8831f915f42ef288759af0ae8a2bdda4bc5a9 /src/filepath.c | |
parent | 6c307dcd554a1ce14c4279a3c2ede29f972bdb23 (diff) | |
download | vim-git-15352dc6ec43fd50cc3be4f4fd1ad74d5619da20.tar.gz |
patch 8.2.0521: crash when reading a blob failsv8.2.0521
Problem: Crash when reading a blob fails.
Solution: Avoid keeping a pointer to a freed blob object. (Dominique Pelle,
closes #5890) Adjust error messages.
Diffstat (limited to 'src/filepath.c')
-rw-r--r-- | src/filepath.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/filepath.c b/src/filepath.c index 37455a256..15372af8e 100644 --- a/src/filepath.c +++ b/src/filepath.c @@ -1452,20 +1452,18 @@ f_readfile(typval_T *argvars, typval_T *rettv) maxline = (long)tv_get_number(&argvars[2]); } - if (blob) - { - if (rettv_blob_alloc(rettv) == FAIL) - return; - } - else - { - if (rettv_list_alloc(rettv) == FAIL) - return; - } + if ((blob ? rettv_blob_alloc(rettv) : rettv_list_alloc(rettv)) == FAIL) + return; // Always open the file in binary mode, library functions have a mind of // their own about CR-LF conversion. fname = tv_get_string(&argvars[0]); + + if (mch_isdir(fname)) + { + semsg(_(e_isadir2), fname); + return; + } if (*fname == NUL || (fd = mch_fopen((char *)fname, READBIN)) == NULL) { semsg(_(e_notopen), *fname == NUL ? (char_u *)_("<empty>") : fname); @@ -1476,8 +1474,10 @@ f_readfile(typval_T *argvars, typval_T *rettv) { if (read_blob(fd, rettv->vval.v_blob) == FAIL) { - emsg("cannot read file"); + semsg(_(e_notread), fname); + // An empty blob is returned on error. blob_free(rettv->vval.v_blob); + rettv->vval.v_blob = NULL; } fclose(fd); return; |