aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChong Yidong2012-02-19 17:58:23 +0800
committerChong Yidong2012-02-19 17:58:23 +0800
commit2375c96a71874756c132de1d0508a224c0fea0ab (patch)
tree9a5387f4e70e360e03d597d8fa67c5aff054085e /src
parent55645c67978eb15884ed5ca919b1691b3715e3ad (diff)
downloademacs-2375c96a71874756c132de1d0508a224c0fea0ab.tar.gz
emacs-2375c96a71874756c132de1d0508a224c0fea0ab.zip
Protect fileio.c primitives against invalid file handler return values.
* src/fileio.c (Ffile_name_directory, Ffile_name_nondirectory) (Funhandled_file_name_directory, Ffile_name_as_directory) (Fdirectory_file_name, Fexpand_file_name) (Fsubstitute_in_file_name): Protect against invalid file handler return values. Fixes: debbugs:10845
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/fileio.c71
2 files changed, 69 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 472dcc13d14..3716aee7d69 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
12012-02-19 Chong Yidong <cyd@gnu.org>
2
3 * fileio.c (Ffile_name_directory, Ffile_name_nondirectory)
4 (Funhandled_file_name_directory, Ffile_name_as_directory)
5 (Fdirectory_file_name, Fexpand_file_name)
6 (Fsubstitute_in_file_name): Protect against invalid file handler
7 return values (Bug#10845).
8
12012-02-18 Eli Zaretskii <eliz@gnu.org> 92012-02-18 Eli Zaretskii <eliz@gnu.org>
2 10
3 * .gdbinit (pitx): Fix incorrect references to fields of the 11 * .gdbinit (pitx): Fix incorrect references to fields of the
diff --git a/src/fileio.c b/src/fileio.c
index 9e940c9a324..1fd5ebed651 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -328,7 +328,11 @@ Given a Unix syntax file name, returns a string ending in slash. */)
328 call the corresponding file handler. */ 328 call the corresponding file handler. */
329 handler = Ffind_file_name_handler (filename, Qfile_name_directory); 329 handler = Ffind_file_name_handler (filename, Qfile_name_directory);
330 if (!NILP (handler)) 330 if (!NILP (handler))
331 return call2 (handler, Qfile_name_directory, filename); 331 {
332 Lisp_Object handled_name = call2 (handler, Qfile_name_directory,
333 filename);
334 return STRINGP (handled_name) ? handled_name : Qnil;
335 }
332 336
333 filename = FILE_SYSTEM_CASE (filename); 337 filename = FILE_SYSTEM_CASE (filename);
334#ifdef DOS_NT 338#ifdef DOS_NT
@@ -397,7 +401,13 @@ or the entire name if it contains no slash. */)
397 call the corresponding file handler. */ 401 call the corresponding file handler. */
398 handler = Ffind_file_name_handler (filename, Qfile_name_nondirectory); 402 handler = Ffind_file_name_handler (filename, Qfile_name_nondirectory);
399 if (!NILP (handler)) 403 if (!NILP (handler))
400 return call2 (handler, Qfile_name_nondirectory, filename); 404 {
405 Lisp_Object handled_name = call2 (handler, Qfile_name_nondirectory,
406 filename);
407 if (STRINGP (handled_name))
408 return handled_name;
409 error ("Invalid handler in `file-name-handler-alist'");
410 }
401 411
402 beg = SSDATA (filename); 412 beg = SSDATA (filename);
403 end = p = beg + SBYTES (filename); 413 end = p = beg + SBYTES (filename);
@@ -434,7 +444,11 @@ get a current directory to run processes in. */)
434 call the corresponding file handler. */ 444 call the corresponding file handler. */
435 handler = Ffind_file_name_handler (filename, Qunhandled_file_name_directory); 445 handler = Ffind_file_name_handler (filename, Qunhandled_file_name_directory);
436 if (!NILP (handler)) 446 if (!NILP (handler))
437 return call2 (handler, Qunhandled_file_name_directory, filename); 447 {
448 Lisp_Object handled_name = call2 (handler, Qunhandled_file_name_directory,
449 filename);
450 return STRINGP (handled_name) ? handled_name : Qnil;
451 }
438 452
439 return Ffile_name_directory (filename); 453 return Ffile_name_directory (filename);
440} 454}
@@ -488,7 +502,13 @@ For a Unix-syntax file name, just appends a slash. */)
488 call the corresponding file handler. */ 502 call the corresponding file handler. */
489 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); 503 handler = Ffind_file_name_handler (file, Qfile_name_as_directory);
490 if (!NILP (handler)) 504 if (!NILP (handler))
491 return call2 (handler, Qfile_name_as_directory, file); 505 {
506 Lisp_Object handled_name = call2 (handler, Qfile_name_as_directory,
507 file);
508 if (STRINGP (handled_name))
509 return handled_name;
510 error ("Invalid handler in `file-name-handler-alist'");
511 }
492 512
493 buf = (char *) alloca (SBYTES (file) + 10); 513 buf = (char *) alloca (SBYTES (file) + 10);
494 file_name_as_directory (buf, SSDATA (file)); 514 file_name_as_directory (buf, SSDATA (file));
@@ -547,7 +567,13 @@ In Unix-syntax, this function just removes the final slash. */)
547 call the corresponding file handler. */ 567 call the corresponding file handler. */
548 handler = Ffind_file_name_handler (directory, Qdirectory_file_name); 568 handler = Ffind_file_name_handler (directory, Qdirectory_file_name);
549 if (!NILP (handler)) 569 if (!NILP (handler))
550 return call2 (handler, Qdirectory_file_name, directory); 570 {
571 Lisp_Object handled_name = call2 (handler, Qdirectory_file_name,
572 directory);
573 if (STRINGP (handled_name))
574 return handled_name;
575 error ("Invalid handler in `file-name-handler-alist'");
576 }
551 577
552 buf = (char *) alloca (SBYTES (directory) + 20); 578 buf = (char *) alloca (SBYTES (directory) + 20);
553 directory_file_name (SSDATA (directory), buf); 579 directory_file_name (SSDATA (directory), buf);
@@ -747,7 +773,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
747 int is_escaped = 0; 773 int is_escaped = 0;
748#endif /* DOS_NT */ 774#endif /* DOS_NT */
749 ptrdiff_t length; 775 ptrdiff_t length;
750 Lisp_Object handler, result; 776 Lisp_Object handler, result, handled_name;
751 int multibyte; 777 int multibyte;
752 Lisp_Object hdir; 778 Lisp_Object hdir;
753 779
@@ -757,7 +783,14 @@ filesystem tree, not (expand-file-name ".." dirname). */)
757 call the corresponding file handler. */ 783 call the corresponding file handler. */
758 handler = Ffind_file_name_handler (name, Qexpand_file_name); 784 handler = Ffind_file_name_handler (name, Qexpand_file_name);
759 if (!NILP (handler)) 785 if (!NILP (handler))
760 return call3 (handler, Qexpand_file_name, name, default_directory); 786 {
787 handled_name = call3 (handler, Qexpand_file_name,
788 name, default_directory);
789 if (STRINGP (handled_name))
790 return handled_name;
791 error ("Invalid handler in `file-name-handler-alist'");
792 }
793
761 794
762 /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */ 795 /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */
763 if (NILP (default_directory)) 796 if (NILP (default_directory))
@@ -783,7 +816,13 @@ filesystem tree, not (expand-file-name ".." dirname). */)
783 { 816 {
784 handler = Ffind_file_name_handler (default_directory, Qexpand_file_name); 817 handler = Ffind_file_name_handler (default_directory, Qexpand_file_name);
785 if (!NILP (handler)) 818 if (!NILP (handler))
786 return call3 (handler, Qexpand_file_name, name, default_directory); 819 {
820 handled_name = call3 (handler, Qexpand_file_name,
821 name, default_directory);
822 if (STRINGP (handled_name))
823 return handled_name;
824 error ("Invalid handler in `file-name-handler-alist'");
825 }
787 } 826 }
788 827
789 { 828 {
@@ -1284,7 +1323,13 @@ filesystem tree, not (expand-file-name ".." dirname). */)
1284 to be expanded again. */ 1323 to be expanded again. */
1285 handler = Ffind_file_name_handler (result, Qexpand_file_name); 1324 handler = Ffind_file_name_handler (result, Qexpand_file_name);
1286 if (!NILP (handler)) 1325 if (!NILP (handler))
1287 return call3 (handler, Qexpand_file_name, result, default_directory); 1326 {
1327 handled_name = call3 (handler, Qexpand_file_name,
1328 result, default_directory);
1329 if (STRINGP (handled_name))
1330 return handled_name;
1331 error ("Invalid handler in `file-name-handler-alist'");
1332 }
1288 1333
1289 return result; 1334 return result;
1290} 1335}
@@ -1537,7 +1582,13 @@ those `/' is discarded. */)
1537 call the corresponding file handler. */ 1582 call the corresponding file handler. */
1538 handler = Ffind_file_name_handler (filename, Qsubstitute_in_file_name); 1583 handler = Ffind_file_name_handler (filename, Qsubstitute_in_file_name);
1539 if (!NILP (handler)) 1584 if (!NILP (handler))
1540 return call2 (handler, Qsubstitute_in_file_name, filename); 1585 {
1586 Lisp_Object handled_name = call2 (handler, Qsubstitute_in_file_name,
1587 filename);
1588 if (STRINGP (handled_name))
1589 return handled_name;
1590 error ("Invalid handler in `file-name-handler-alist'");
1591 }
1541 1592
1542 /* Always work on a copy of the string, in case GC happens during 1593 /* Always work on a copy of the string, in case GC happens during
1543 decode of environment variables, causing the original Lisp_String 1594 decode of environment variables, causing the original Lisp_String