From b98ed825080df50e50b528a4b372e78c4f9a1f83 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 22 May 2024 14:10:53 +0300 Subject: [PATCH] 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) --- src/w32.c | 2 +- test/src/fileio-tests.el | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 -- 2.39.5