From 526bc873d91b134ffab0c484553d42a510bccd96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Thu, 21 Mar 2019 17:31:47 +0100 Subject: erts: Fix incorrect UNC path length calculation This didn't cause any issues for the most part since the path was still properly formed, but it broke down when appending the wildcards in file:list_dir/1. The ASSERT_PATH_FORMAT macro would have caught this in no time, but it went unnoticed because we don't run debug builds on Windows. --- erts/emulator/nifs/win32/win_prim_file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'erts/emulator/nifs/win32') diff --git a/erts/emulator/nifs/win32/win_prim_file.c b/erts/emulator/nifs/win32/win_prim_file.c index d0aa70542f..e7d3924240 100644 --- a/erts/emulator/nifs/win32/win_prim_file.c +++ b/erts/emulator/nifs/win32/win_prim_file.c @@ -142,12 +142,15 @@ static posix_errno_t get_full_path(ErlNifEnv *env, WCHAR *input, efile_path_t *r maybe_unc_path = !sys_memcmp(result->data, L"\\\\", sizeof(WCHAR) * 2); if(maybe_unc_path && !is_long_path) { - /* \\localhost\c$\gurka -> \\?\UNC\localhost\c$\gurka */ + /* \\localhost\c$\gurka -> \\?\UNC\localhost\c$\gurka + * + * Note that the length is reduced by 2 as the "\\" is replaced by + * the UNC prefix */ sys_memmove(result->data + LP_UNC_PREFIX_SIZE, &((WCHAR*)result->data)[2], - (actual_length - 1) * sizeof(WCHAR)); + (actual_length + 1 - 2) * sizeof(WCHAR)); sys_memcpy(result->data, LP_UNC_PREFIX, LP_UNC_PREFIX_SIZE); - actual_length += LP_UNC_PREFIX_LENGTH; + actual_length += LP_UNC_PREFIX_LENGTH - 2; } else if(!is_long_path) { /* C:\gurka -> \\?\C:\gurka */ sys_memmove(result->data + LP_PREFIX_SIZE, result->data, -- cgit v1.2.3