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-Tag: archive/raspbian/1%29.4+1-4+rpi1~1^2~2^2~17^2~25 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=350ae75f5c1c47a03560e43e8699781c04c9078a;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. --- diff --git a/src/w32.c b/src/w32.c index d463962b6c3..a78d5569fe6 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 764ae662e15..136d3813a2b 100644 --- a/test/src/fileio-tests.el +++ b/test/src/fileio-tests.el @@ -218,4 +218,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