# HG changeset patch # User Brian Fox # Date 751524132 0 # Node ID 1774c84aca2e073463b945689d7b7a4fc6364f23 # Parent 57c506c597b9ba08542c8e8a6e20f681c9ff78cd (Fcopy_file): Don't allow the copying of anything other than regular files or symlink files. diff -r 57c506c597b9 -r 1774c84aca2e src/fileio.c --- a/src/fileio.c Sun Oct 24 23:28:06 1993 +0000 +++ b/src/fileio.c Mon Oct 25 04:42:12 1993 +0000 @@ -22,6 +22,14 @@ #include #include +#if !defined (S_ISLNK) && defined (S_IFLNK) +# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#endif + +#if !defined (S_ISREG) && defined (S_IFREG) +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#endif + #ifdef VMS #include "vms-pwd.h" #else @@ -1586,6 +1594,7 @@ struct gcpro gcpro1, gcpro2; int count = specpdl_ptr - specpdl; Lisp_Object args[6]; + int input_file_statable_p; GCPRO2 (filename, newname); CHECK_STRING (filename, 0); @@ -1614,6 +1623,24 @@ record_unwind_protect (close_file_unwind, make_number (ifd)); + /* We can only copy regular files and symbolic links. Other files are not + copyable by us. */ + input_file_statable_p = (fstat (ifd, &st) >= 0); + +#if defined (S_ISREG) && defined (S_ISLNK) + if (input_file_statable_p) + { + if (!(S_ISREG (st.st_mode)) && !(S_ISLNK (st.st_mode))) + { +#if defined (EISDIR) + /* Get a better looking error message. */ + errno = EISDIR; +#endif /* EISDIR */ + report_file_error ("Non-regular file", Fcons (filename, Qnil)); + } + } +#endif /* S_ISREG && S_ISLNK */ + #ifdef VMS /* Create the copy file with the same record format as the input file */ ofd = sys_creat (XSTRING (newname)->data, 0666, ifd); @@ -1632,7 +1659,7 @@ report_file_error ("I/O error", Fcons (newname, Qnil)); immediate_quit = 0; - if (fstat (ifd, &st) >= 0) + if (input_file_statable_p) { if (!NILP (keep_date)) {