diff options
author | Eli Zaretskii <eliz@gnu.org> | 2024-05-22 14:10:53 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2024-05-22 14:10:53 +0300 |
commit | 350ae75f5c1c47a03560e43e8699781c04c9078a (patch) | |
tree | dc42cd7ebedebce5fd3d0ec0c3f3b23ada713c9e | |
parent | ccf8dba44a3071d56e54a20276e00a6cdcc4b135 (diff) | |
download | emacs-350ae75f5c1c47a03560e43e8699781c04c9078a.tar.gz emacs-350ae75f5c1c47a03560e43e8699781c04c9078a.tar.bz2 emacs-350ae75f5c1c47a03560e43e8699781c04c9078a.zip |
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.
-rw-r--r-- | src/w32.c | 2 | ||||
-rw-r--r-- | test/src/fileio-tests.el | 6 |
2 files changed, 7 insertions, 1 deletions
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 |