From b62e1e920b292c4928395db89e96fada29dd7c38 Mon Sep 17 00:00:00 2001 From: zeho11 <73569575+zeho11@users.noreply.github.com> Date: Wed, 7 Dec 2022 14:39:36 +0900 Subject: [PATCH 1/3] dll: fuse: change name limit to 255 chars Fixes #191 Fixes #455 --- src/dll/fuse/fuse_intf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dll/fuse/fuse_intf.c b/src/dll/fuse/fuse_intf.c index 5ee5d739..e6f247c8 100644 --- a/src/dll/fuse/fuse_intf.c +++ b/src/dll/fuse/fuse_intf.c @@ -1939,7 +1939,7 @@ int fsp_fuse_intf_AddDirInfo(void *buf, const char *name, } SizeA = lstrlenA(name); - if (SizeA > 255) + if (SizeA > 1020) { fsp_fuse_intf_LogBadDirInfo(filedesc->PosixPath, name, "too long"); @@ -1953,6 +1953,15 @@ int fsp_fuse_intf_AddDirInfo(void *buf, const char *name, "MultiByteToWideChar failed"); return 0; } + else if (255 == SizeW) + { + if (255 < MultiByteToWideChar(CP_UTF8, 0, name, SizeA, NULL, 0)) + { + fsp_fuse_intf_LogBadDirInfo(filedesc->PosixPath, name, + "too long"); + return 0; + } + } memset(DirInfo, 0, sizeof *DirInfo); DirInfo->Size = (UINT16)(sizeof(FSP_FSCTL_DIR_INFO) + SizeW * sizeof(WCHAR)); From cb81e81985170719de9726747480f42d0a8400da Mon Sep 17 00:00:00 2001 From: zeho11 <73569575+zeho11@users.noreply.github.com> Date: Wed, 7 Dec 2022 15:17:59 +0900 Subject: [PATCH 2/3] Update fuse_intf.c --- src/dll/fuse/fuse_intf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dll/fuse/fuse_intf.c b/src/dll/fuse/fuse_intf.c index e6f247c8..3012a49c 100644 --- a/src/dll/fuse/fuse_intf.c +++ b/src/dll/fuse/fuse_intf.c @@ -2000,7 +2000,7 @@ static NTSTATUS fsp_fuse_intf_FixDirInfo(FSP_FILE_SYSTEM *FileSystem, NTSTATUS Result; SizeA = lstrlenA(filedesc->PosixPath); - PosixPath = MemAlloc(SizeA + 1 + 255 + 1); + PosixPath = MemAlloc(SizeA + 1 + 1020 + 1); if (0 == PosixPath) { Result = STATUS_INSUFFICIENT_RESOURCES; @@ -2049,7 +2049,7 @@ static NTSTATUS fsp_fuse_intf_FixDirInfo(FSP_FILE_SYSTEM *FileSystem, else { PosixPathEnd = 0; - SizeA = WideCharToMultiByte(CP_UTF8, 0, DirInfo->FileNameBuf, SizeW, PosixName, 255, 0, 0); + SizeA = WideCharToMultiByte(CP_UTF8, 0, DirInfo->FileNameBuf, SizeW, PosixName, 1020, 0, 0); if (0 == SizeA) { /* this should never happen because we just converted using MultiByteToWideChar */ From db07b24342772467844117805372381a31c50cea Mon Sep 17 00:00:00 2001 From: zeho11 Date: Thu, 8 Dec 2022 18:02:19 +0900 Subject: [PATCH 3/3] Update --- Contributors.asciidoc | 1 + src/dll/fuse/fuse_intf.c | 6 +++--- tst/winfsp-tests/create-test.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Contributors.asciidoc b/Contributors.asciidoc index dfef611b..ee52e117 100644 --- a/Contributors.asciidoc +++ b/Contributors.asciidoc @@ -74,4 +74,5 @@ CONTRIBUTOR LIST |Santiago Ganis |sganis at gmail.com |Tobias Urlaub |saibotu at outlook.de |Victor Gao |victgm at outlook.com +|Zeho Huang |zeho11 at protonmail.com |=== diff --git a/src/dll/fuse/fuse_intf.c b/src/dll/fuse/fuse_intf.c index 3012a49c..287f2e48 100644 --- a/src/dll/fuse/fuse_intf.c +++ b/src/dll/fuse/fuse_intf.c @@ -1939,7 +1939,7 @@ int fsp_fuse_intf_AddDirInfo(void *buf, const char *name, } SizeA = lstrlenA(name); - if (SizeA > 1020) + if (SizeA > 255 * 4) { fsp_fuse_intf_LogBadDirInfo(filedesc->PosixPath, name, "too long"); @@ -2000,7 +2000,7 @@ static NTSTATUS fsp_fuse_intf_FixDirInfo(FSP_FILE_SYSTEM *FileSystem, NTSTATUS Result; SizeA = lstrlenA(filedesc->PosixPath); - PosixPath = MemAlloc(SizeA + 1 + 1020 + 1); + PosixPath = MemAlloc(SizeA + 1 + 255 * 4 + 1); if (0 == PosixPath) { Result = STATUS_INSUFFICIENT_RESOURCES; @@ -2049,7 +2049,7 @@ static NTSTATUS fsp_fuse_intf_FixDirInfo(FSP_FILE_SYSTEM *FileSystem, else { PosixPathEnd = 0; - SizeA = WideCharToMultiByte(CP_UTF8, 0, DirInfo->FileNameBuf, SizeW, PosixName, 1020, 0, 0); + SizeA = WideCharToMultiByte(CP_UTF8, 0, DirInfo->FileNameBuf, SizeW, PosixName, 255 * 4, 0, 0); if (0 == SizeA) { /* this should never happen because we just converted using MultiByteToWideChar */ diff --git a/tst/winfsp-tests/create-test.c b/tst/winfsp-tests/create-test.c index e89cb2a3..5e5777e2 100644 --- a/tst/winfsp-tests/create-test.c +++ b/tst/winfsp-tests/create-test.c @@ -1287,6 +1287,38 @@ void create_namelen_dotest(ULONG Flags, PWSTR Prefix, PWSTR Drive) ASSERT(INVALID_HANDLE_VALUE == Handle); ASSERT(ERROR_INVALID_NAME == GetLastError()); + for (P = FilePathBgn, EndP = P + MaxComponentLength - 1; EndP > P; P++) + *P = (P - FilePathBgn) % 10 + 0x3041; + *P = L'\0'; + + Handle = CreateFileW(FilePath, + GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, + CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0); + ASSERT(INVALID_HANDLE_VALUE != Handle); + Success = CloseHandle(Handle); + ASSERT(Success); + + for (P = FilePathBgn, EndP = P + MaxComponentLength; EndP > P; P++) + *P = (P - FilePathBgn) % 10 + 0x3041; + *P = L'\0'; + + Handle = CreateFileW(FilePath, + GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, + CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0); + ASSERT(INVALID_HANDLE_VALUE != Handle); + Success = CloseHandle(Handle); + ASSERT(Success); + + for (P = FilePathBgn, EndP = P + MaxComponentLength + 1; EndP > P; P++) + *P = (P - FilePathBgn) % 10 + 0x3041; + *P = L'\0'; + + Handle = CreateFileW(FilePath, + GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, + CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0); + ASSERT(INVALID_HANDLE_VALUE == Handle); + ASSERT(ERROR_INVALID_NAME == GetLastError()); + memfs_stop(memfs); }