aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Fox1993-10-25 04:42:12 +0000
committerBrian Fox1993-10-25 04:42:12 +0000
commitf73b0adae74fa2470bb5a4cb238af38a4fdef985 (patch)
treed2a10e68e24b0469a23d007fca0fc5b61e5b407d /src
parent84d91fda2ee57bb9f5ba844f3d8cfa0ceda2ce5f (diff)
downloademacs-f73b0adae74fa2470bb5a4cb238af38a4fdef985.tar.gz
emacs-f73b0adae74fa2470bb5a4cb238af38a4fdef985.zip
(Fcopy_file): Don't allow the copying of anything other than regular
files or symlink files.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 02d4e635a51..129438fa07a 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -22,6 +22,14 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22#include <sys/types.h> 22#include <sys/types.h>
23#include <sys/stat.h> 23#include <sys/stat.h>
24 24
25#if !defined (S_ISLNK) && defined (S_IFLNK)
26# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
27#endif
28
29#if !defined (S_ISREG) && defined (S_IFREG)
30# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
31#endif
32
25#ifdef VMS 33#ifdef VMS
26#include "vms-pwd.h" 34#include "vms-pwd.h"
27#else 35#else
@@ -1586,6 +1594,7 @@ A prefix arg makes KEEP-TIME non-nil.")
1586 struct gcpro gcpro1, gcpro2; 1594 struct gcpro gcpro1, gcpro2;
1587 int count = specpdl_ptr - specpdl; 1595 int count = specpdl_ptr - specpdl;
1588 Lisp_Object args[6]; 1596 Lisp_Object args[6];
1597 int input_file_statable_p;
1589 1598
1590 GCPRO2 (filename, newname); 1599 GCPRO2 (filename, newname);
1591 CHECK_STRING (filename, 0); 1600 CHECK_STRING (filename, 0);
@@ -1614,6 +1623,24 @@ A prefix arg makes KEEP-TIME non-nil.")
1614 1623
1615 record_unwind_protect (close_file_unwind, make_number (ifd)); 1624 record_unwind_protect (close_file_unwind, make_number (ifd));
1616 1625
1626 /* We can only copy regular files and symbolic links. Other files are not
1627 copyable by us. */
1628 input_file_statable_p = (fstat (ifd, &st) >= 0);
1629
1630#if defined (S_ISREG) && defined (S_ISLNK)
1631 if (input_file_statable_p)
1632 {
1633 if (!(S_ISREG (st.st_mode)) && !(S_ISLNK (st.st_mode)))
1634 {
1635#if defined (EISDIR)
1636 /* Get a better looking error message. */
1637 errno = EISDIR;
1638#endif /* EISDIR */
1639 report_file_error ("Non-regular file", Fcons (filename, Qnil));
1640 }
1641 }
1642#endif /* S_ISREG && S_ISLNK */
1643
1617#ifdef VMS 1644#ifdef VMS
1618 /* Create the copy file with the same record format as the input file */ 1645 /* Create the copy file with the same record format as the input file */
1619 ofd = sys_creat (XSTRING (newname)->data, 0666, ifd); 1646 ofd = sys_creat (XSTRING (newname)->data, 0666, ifd);
@@ -1632,7 +1659,7 @@ A prefix arg makes KEEP-TIME non-nil.")
1632 report_file_error ("I/O error", Fcons (newname, Qnil)); 1659 report_file_error ("I/O error", Fcons (newname, Qnil));
1633 immediate_quit = 0; 1660 immediate_quit = 0;
1634 1661
1635 if (fstat (ifd, &st) >= 0) 1662 if (input_file_statable_p)
1636 { 1663 {
1637 if (!NILP (keep_date)) 1664 if (!NILP (keep_date))
1638 { 1665 {