• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision80e663e91e1ba1a734a2c39ce987c79b2678f8d2 (tree)
Zeit2020-04-07 04:15:37
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.0521: crash when reading a blob fails

Commit: https://github.com/vim/vim/commit/15352dc6ec43fd50cc3be4f4fd1ad74d5619da20
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 6 21:12:42 2020 +0200

patch 8.2.0521: crash when reading a blob fails
Problem: Crash when reading a blob fails.
Solution: Avoid keeping a pointer to a freed blob object. (Dominique Pelle,
closes #5890) Adjust error messages.

Ändern Zusammenfassung

Diff

diff -r 35310c0dd026 -r 80e663e91e1b src/filepath.c
--- a/src/filepath.c Sun Apr 05 23:15:36 2020 +0200
+++ b/src/filepath.c Mon Apr 06 21:15:37 2020 +0200
@@ -1452,20 +1452,18 @@
14521452 maxline = (long)tv_get_number(&argvars[2]);
14531453 }
14541454
1455- if (blob)
1456- {
1457- if (rettv_blob_alloc(rettv) == FAIL)
1458- return;
1459- }
1460- else
1461- {
1462- if (rettv_list_alloc(rettv) == FAIL)
1463- return;
1464- }
1455+ if ((blob ? rettv_blob_alloc(rettv) : rettv_list_alloc(rettv)) == FAIL)
1456+ return;
14651457
14661458 // Always open the file in binary mode, library functions have a mind of
14671459 // their own about CR-LF conversion.
14681460 fname = tv_get_string(&argvars[0]);
1461+
1462+ if (mch_isdir(fname))
1463+ {
1464+ semsg(_(e_isadir2), fname);
1465+ return;
1466+ }
14691467 if (*fname == NUL || (fd = mch_fopen((char *)fname, READBIN)) == NULL)
14701468 {
14711469 semsg(_(e_notopen), *fname == NUL ? (char_u *)_("<empty>") : fname);
@@ -1476,8 +1474,10 @@
14761474 {
14771475 if (read_blob(fd, rettv->vval.v_blob) == FAIL)
14781476 {
1479- emsg("cannot read file");
1477+ semsg(_(e_notread), fname);
1478+ // An empty blob is returned on error.
14801479 blob_free(rettv->vval.v_blob);
1480+ rettv->vval.v_blob = NULL;
14811481 }
14821482 fclose(fd);
14831483 return;
diff -r 35310c0dd026 -r 80e663e91e1b src/testdir/test_blob.vim
--- a/src/testdir/test_blob.vim Sun Apr 05 23:15:36 2020 +0200
+++ b/src/testdir/test_blob.vim Mon Apr 06 21:15:37 2020 +0200
@@ -257,6 +257,9 @@
257257 let br = readfile('Xblob', 'B')
258258 call assert_equal(b, br)
259259 call delete('Xblob')
260+
261+ " This was crashing when calling readfile() with a directory.
262+ call assert_fails("call readfile('.', 'B')", 'E17: "." is a directory')
260263 endfunc
261264
262265 " filter() item in blob
diff -r 35310c0dd026 -r 80e663e91e1b src/version.c
--- a/src/version.c Sun Apr 05 23:15:36 2020 +0200
+++ b/src/version.c Mon Apr 06 21:15:37 2020 +0200
@@ -739,6 +739,8 @@
739739 static int included_patches[] =
740740 { /* Add new patch number below this line */
741741 /**/
742+ 521,
743+/**/
742744 520,
743745 /**/
744746 519,
Show on old repository browser