To: vim-dev@vim.org Subject: Patch 5.7.028 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.7.028 Problem: Creating a backup or swap file could fail in rare situations. Solution: Use O_EXCL for open(). Files: src/fileio.c, src/memfile.c *** ../vim-5.7.27/src/fileio.c Thu Mar 29 21:39:51 2001 --- src/fileio.c Fri Mar 30 12:11:30 2001 *************** *** 1532,1538 **** { /* remove old backup, if present */ mch_remove(backup); ! bfd = mch_open((char *)backup, O_WRONLY|O_CREAT|O_EXTRA, 0666); if (bfd < 0) { vim_free(backup); --- 1532,1539 ---- { /* remove old backup, if present */ mch_remove(backup); ! bfd = mch_open((char *)backup, O_WRONLY|O_CREAT|O_EXCL|O_EXTRA, ! 0666); if (bfd < 0) { vim_free(backup); *************** *** 2147,2153 **** int empty_fd; if (org == NULL ! || (empty_fd = mch_open(org, O_CREAT | O_EXTRA, 0666)) < 0) EMSG("patchmode: can't touch empty original file"); else close(empty_fd); --- 2148,2155 ---- int empty_fd; if (org == NULL ! || (empty_fd = mch_open(org, O_CREAT | O_EXTRA | O_EXCL, ! 0666)) < 0) EMSG("patchmode: can't touch empty original file"); else close(empty_fd); *************** *** 2820,2826 **** fd_in = mch_open((char *)from, O_RDONLY|O_EXTRA, 0); if (fd_in == -1) return -1; ! fd_out = mch_open((char *)to, O_CREAT|O_TRUNC|O_WRONLY|O_EXTRA, 0666); if (fd_out == -1) { close(fd_in); --- 2822,2828 ---- fd_in = mch_open((char *)from, O_RDONLY|O_EXTRA, 0); if (fd_in == -1) return -1; ! fd_out = mch_open((char *)to, O_CREAT|O_EXCL|O_WRONLY|O_EXTRA, 0666); if (fd_out == -1) { close(fd_in); *** ../vim-5.7.27/src/memfile.c Tue Jan 11 16:19:43 2000 --- src/memfile.c Tue Apr 3 11:47:46 2001 *************** *** 1213,1227 **** #endif /* ! * try to open the file */ mfp->mf_fd = open( #ifdef VMS vms_fixfilename(mfp->mf_fname), #else (char *)mfp->mf_fname, #endif ! (trunc_file ? (O_CREAT | O_RDWR | O_TRUNC) : (O_RDONLY)) | O_EXTRA #if defined(UNIX) || defined(RISCOS) /* open in rw------- mode */ , (mode_t)0600 #endif --- 1213,1229 ---- #endif /* ! * Try to open the file. First delete any existing file. */ + if (trunc_file) + mch_remove(mfp->mf_fname); mfp->mf_fd = open( #ifdef VMS vms_fixfilename(mfp->mf_fname), #else (char *)mfp->mf_fname, #endif ! (trunc_file ? (O_CREAT | O_RDWR | O_EXCL) : (O_RDONLY)) | O_EXTRA #if defined(UNIX) || defined(RISCOS) /* open in rw------- mode */ , (mode_t)0600 #endif *** ../vim-5.7.27/src/version.c Thu Mar 29 21:39:51 2001 --- src/version.c Tue Apr 3 11:48:06 2001 *************** *** 439,440 **** --- 439,442 ---- { /* Add new patch number below this line */ + /**/ + 28, /**/ -- While it's true that many normal people whould prefer not to _date_ an engineer, most normal people harbor an intense desire to _mate_ with them, thus producing engineerlike children who will have high-paying jobs long before losing their virginity. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ ((( Creator of Vim - http://www.vim.org -- ftp://ftp.vim.org/pub/vim ))) \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///