From cb13e9a8427eb0f198f6c95f2107a41c264f93a2 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 1 Feb 2014 11:22:51 +0200 Subject: [PATCH] Fix bug #16558 with w32-shell-execute on remote file names. src/w32fns.c (Fw32_shell_execute): Don't call file-exists-p for DOCUMENT that is a "remote" file name, i.e. a file-handler exists for it. --- src/ChangeLog | 6 ++++++ src/w32fns.c | 23 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ec17d7ace4f..8a8956bec31 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2014-02-01 Eli Zaretskii + + * w32fns.c (Fw32_shell_execute): Don't call file-exists-p for + DOCUMENT that is a "remote" file name, i.e. a file-handler exists + for it. (Bug#16558) + 2014-01-30 Andreas Schwab * process.c (create_process): Reset SIGPROF handler in the child. diff --git a/src/w32fns.c b/src/w32fns.c index 98456cd20d4..397b1796215 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -6892,7 +6892,8 @@ an integer representing a ShowWindow flag: #ifndef CYGWIN int use_unicode = w32_unicode_filenames; char *doc_a = NULL, *params_a = NULL, *ops_a = NULL; - Lisp_Object absdoc; + Lisp_Object absdoc, handler; + struct gcpro gcpro1; #endif CHECK_STRING (document); @@ -6927,10 +6928,24 @@ an integer representing a ShowWindow flag: does not have to be a file, it can be a URL, for example. So we make it absolute only if it is an existing file; if it is a file that does not exist, tough. */ + GCPRO1 (absdoc); absdoc = Fexpand_file_name (document, Qnil); - if (!NILP (Ffile_exists_p (absdoc))) - document = absdoc; - document = ENCODE_FILE (document); + /* Don't call file handlers for file-exists-p, since they might + attempt to access the file, which could fail or produce undesired + consequences, see bug#16558 for an example. */ + handler = Ffind_file_name_handler (absdoc, Qfile_exists_p); + if (NILP (handler)) + { + Lisp_Object absdoc_encoded = ENCODE_FILE (absdoc); + + if (faccessat (AT_FDCWD, SSDATA (absdoc_encoded), F_OK, AT_EACCESS) == 0) + document = absdoc_encoded; + else + document = ENCODE_FILE (document); + } + else + document = ENCODE_FILE (document); + UNGCPRO; if (use_unicode) { wchar_t document_w[MAX_PATH], current_dir_w[MAX_PATH]; -- 2.39.2