Patch 8.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.
Files:      src/filepath.c, src/testdir/test_blob.vim


*** ../vim-8.2.0520/src/filepath.c      2020-04-02 18:50:42.419773128 +0200
--- src/filepath.c      2020-04-06 21:09:22.253999058 +0200
***************
*** 1452,1471 ****
            maxline = (long)tv_get_number(&argvars[2]);
      }
  
!     if (blob)
!     {
!       if (rettv_blob_alloc(rettv) == FAIL)
!           return;
!     }
!     else
!     {
!       if (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 (*fname == NUL || (fd = mch_fopen((char *)fname, READBIN)) == NULL)
      {
        semsg(_(e_notopen), *fname == NUL ? (char_u *)_("<empty>") : fname);
--- 1452,1469 ----
            maxline = (long)tv_get_number(&argvars[2]);
      }
  
!     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,1483 ****
      {
        if (read_blob(fd, rettv->vval.v_blob) == FAIL)
        {
!           emsg("cannot read file");
            blob_free(rettv->vval.v_blob);
        }
        fclose(fd);
        return;
--- 1474,1483 ----
      {
        if (read_blob(fd, rettv->vval.v_blob) == FAIL)
        {
!           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;
*** ../vim-8.2.0520/src/testdir/test_blob.vim   2020-03-25 22:23:41.894363634 
+0100
--- src/testdir/test_blob.vim   2020-04-06 21:11:26.897573834 +0200
***************
*** 257,262 ****
--- 257,265 ----
    let br = readfile('Xblob', 'B')
    call assert_equal(b, br)
    call delete('Xblob')
+ 
+   " This was crashing when calling readfile() with a directory.
+   call assert_fails("call readfile('.', 'B')", 'E17: "." is a directory')
  endfunc
  
  " filter() item in blob
*** ../vim-8.2.0520/src/version.c       2020-04-05 23:04:53.664241873 +0200
--- src/version.c       2020-04-06 21:03:02.783297552 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     521,
  /**/

-- 
Kisses may last for as much as, but no more than, five minutes.
                [real standing law in Iowa, United States of America]

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202004061913.036JD942031971%40masaka.moolenaar.net.

Raspunde prin e-mail lui