]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid crashes on MS-Windows due to invalid UNC file names
authorEli Zaretskii <eliz@gnu.org>
Wed, 22 May 2024 11:10:53 +0000 (14:10 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 26 May 2024 05:49:54 +0000 (07:49 +0200)
* 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)

src/w32.c
test/src/fileio-tests.el

index d34ab70f82dc1b9549bc3dd6ee38d2deb266b372..a1b34e4103bd1cd3af847b3b2b7386f18c1f06a0 100644 (file)
--- 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++;
        }
index 81eef37b90337b32e2d1a1e9b8c7f68d1c24dfcc..750de8444c9a29670b49734046eefe9d14271720 100644 (file)
@@ -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