From: Eli Zaretskii Date: Wed, 22 May 2024 11:10:53 +0000 (+0300) Subject: Avoid crashes on MS-Windows due to invalid UNC file names X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b98ed825080df50e50b528a4b372e78c4f9a1f83;p=emacs.git Avoid crashes on MS-Windows due to invalid UNC file names * src/w32.c (parse_root): Avoid crashes due to invalid (too short) UNC names, such as "\\". (Bug#70914) * test/src/fileio-tests.el (fileio-tests-invalid-UNC): New test. (cherry picked from commit 350ae75f5c1c47a03560e43e8699781c04c9078a) --- diff --git a/src/w32.c b/src/w32.c index d34ab70f82d..a1b34e4103b 100644 --- a/src/w32.c +++ b/src/w32.c @@ -2572,7 +2572,7 @@ parse_root (const char * name, const char ** pPath) name += 2; do { - if (IS_DIRECTORY_SEP (*name) && --slashes == 0) + if (!*name || (IS_DIRECTORY_SEP (*name) && --slashes == 0)) break; name++; } diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el index 81eef37b903..750de8444c9 100644 --- a/test/src/fileio-tests.el +++ b/test/src/fileio-tests.el @@ -217,4 +217,10 @@ Also check that an encoding error can appear in a symlink." (should (equal (expand-file-name file nil) file)) (file-name-case-insensitive-p file))) +(ert-deftest fileio-tests-invalid-UNC () + (skip-unless (eq system-type 'windows-nt)) + ;; These should not crash, see bug#70914. + (should-not (file-exists-p "//")) + (should (file-attributes "//"))) + ;;; fileio-tests.el ends here