To: vim-dev@vim.org Subject: Patch 5.6.089 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.6.089 Problem: On non-Unix systems it's possible to overwrite a read-only file without using "!". Solution: Check if the file permissions allow overwriting before moving the file to become the backup file. Files: src/fileio.c *** ../vim-5.6.88/src/fileio.c Mon Apr 3 09:35:20 2000 --- src/fileio.c Mon Jun 5 17:33:39 2000 *************** *** 40,45 **** --- 40,49 ---- # define CRYPT_MAGIC_LEN 12 #endif + #if defined(UNIX) || defined(DJGPP) || defined(__EMX__) || defined(VMS) || defined(RISCOS) + # define USE_MCH_ACCESS + #endif + #ifdef AUTOCMD struct aco_save { *************** *** 311,317 **** fd = 0; else { ! #if defined(UNIX) || defined(DJGPP) || defined(__EMX__) || defined(VMS) || defined(RISCOS) if ( # ifdef UNIX !(perm & 0222) || --- 321,327 ---- fd = 0; else { ! #ifdef USE_MCH_ACCESS if ( # ifdef UNIX !(perm & 0222) || *************** *** 1599,1604 **** --- 1609,1626 ---- errmsg = (char_u *)"is a directory"; goto fail; } + else if (!forceit && ( + # ifdef USE_MCH_ACCESS + mch_access((char *)fname, W_OK) + # else + (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0 + ? TRUE : (close(fd), FALSE) + # endif + )) + { + errmsg = (char_u *)"is read-only (use ! to override)"; + goto fail; + } else if (overwriting) { struct stat st; *** ../vim-5.6.88/src/version.c Mon Jun 5 15:11:45 2000 --- src/version.c Mon Jun 5 18:22:23 2000 *************** *** 420,421 **** --- 420,423 ---- { /* Add new patch number below this line */ + /**/ + 89, /**/ -- CART DRIVER: Bring out your dead! LARGE MAN: Here's one! CART DRIVER: Ninepence. BODY: I'm not dead! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /-/-- Bram Moolenaar --- Bram@moolenaar.net --- http://www.moolenaar.net --\-\ \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/