ruby-changes:65318
From: Nobuyoshi <ko1@a...>
Date: Mon, 22 Feb 2021 19:48:34 +0900 (JST)
Subject: [ruby-changes:65318] 67d2619463 (master): Expand final path name buffer for namespace prefix
https://git.ruby-lang.org/ruby.git/commit/?id=67d2619463 From 67d2619463061beafe86a773310962365380577f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 21 Feb 2021 13:12:03 +0900 Subject: Expand final path name buffer for namespace prefix As final path name includes the namespace prefix, so expand room for it in path name buffer. --- win32/win32.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/win32/win32.c b/win32/win32.c index 8f99805..03e5f13 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1989,12 +1989,16 @@ open_special(const WCHAR *path, DWORD access, DWORD flags) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1989 #define BitOfIsRep(n) ((n) * 2 + 1) #define DIRENT_PER_CHAR (CHAR_BIT / 2) +static const WCHAR namespace_prefix[] = {L'\\', L'\\', L'?', L'\\'}; + +enum {FINAL_PATH_MAX = PATH_MAX + numberof(namespace_prefix)}; + /* License: Artistic or GPL */ static HANDLE open_dir_handle(const WCHAR *filename, WIN32_FIND_DATAW *fd) { HANDLE fh; - WCHAR fullname[PATH_MAX + rb_strlen_lit("\\*")]; + WCHAR fullname[FINAL_PATH_MAX + rb_strlen_lit("\\*")]; WCHAR *p; int len = 0; @@ -2004,8 +2008,12 @@ open_dir_handle(const WCHAR *filename, WIN32_FIND_DATAW *fd) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L2008 fh = open_special(filename, 0, 0); if (fh != INVALID_HANDLE_VALUE) { - len = get_final_path(fh, fullname, PATH_MAX, 0); + len = get_final_path(fh, fullname, FINAL_PATH_MAX, 0); CloseHandle(fh); + if (len >= FINAL_PATH_MAX) { + errno = ENAMETOOLONG; + return INVALID_HANDLE_VALUE; + } } if (!len) { len = lstrlenW(filename); @@ -5666,8 +5674,6 @@ path_drive(const WCHAR *path) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5674 towupper(path[0]) - L'A' : _getdrive() - 1; } -static const WCHAR namespace_prefix[] = {L'\\', L'\\', L'?', L'\\'}; - /* License: Ruby's */ static int winnt_stat(const WCHAR *path, struct stati128 *st, BOOL lstat) -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/