From c00010478c16f0c1cd55272baca10ebcf68c3fc1 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 30 Jan 2019 15:43:46 +0100 Subject: [PATCH] Fix FindNextFileA path termination with a single separator. --- winpr/libwinpr/file/generic.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/winpr/libwinpr/file/generic.c b/winpr/libwinpr/file/generic.c index 40c7b3e..8b54a64 100644 --- a/winpr/libwinpr/file/generic.c +++ b/winpr/libwinpr/file/generic.c @@ -1080,9 +1080,12 @@ BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData) } memcpy(fullpath, pFileSearch->lpPath, pathlen); - fullpath[pathlen] = '/'; - memcpy(fullpath + pathlen + 1, pFileSearch->pDirent->d_name, namelen); - fullpath[pathlen + namelen + 1] = 0; + /* Ensure path is terminated with a separator, but prevent + * duplicate separators */ + if (fullpath[pathlen-1] != '/') + fullpath[pathlen++] = '/'; + memcpy(fullpath + pathlen, pFileSearch->pDirent->d_name, namelen); + fullpath[pathlen + namelen] = 0; if (stat(fullpath, &fileStat) != 0) { -- 2.7.4