From fe76bafd5748fed41bc26447386f8cf6ea27e0aa Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 21 Aug 2024 09:20:25 +0200 Subject: [PATCH] [channels,drive] fix out of bound access --- channels/drive/client/drive_file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/channels/drive/client/drive_file.c b/channels/drive/client/drive_file.c index 8dbf40fcb..ed66592e2 100644 --- a/channels/drive/client/drive_file.c +++ b/channels/drive/client/drive_file.c @@ -96,6 +96,9 @@ static BOOL contains_dotdot(const WCHAR* path, size_t base_length, size_t path_l const WCHAR* dotdot = InitializeConstWCharFromUtf8("..", dotdotbuffer, ARRAYSIZE(dotdotbuffer)); const WCHAR* tst = path; + if (path_length < 2) + return FALSE; + do { tst = _wcsstr(tst, dotdot); @@ -122,13 +125,12 @@ static WCHAR* drive_file_combine_fullpath(const WCHAR* base_path, const WCHAR* p { BOOL ok = FALSE; WCHAR* fullpath = NULL; - size_t length = 0; if (!base_path || (!path && (PathWCharLength > 0))) goto fail; const size_t base_path_length = _wcsnlen(base_path, MAX_PATH); - length = base_path_length + PathWCharLength + 1; + const size_t length = base_path_length + PathWCharLength + 1; fullpath = (WCHAR*)calloc(length, sizeof(WCHAR)); if (!fullpath)