https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1b70ddd834ad81f7def62…
commit 1b70ddd834ad81f7def62c3166dd560de3d23361
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sat Apr 27 18:58:08 2019 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sat Jul 20 13:56:18 2019 +0200
[KERNEL32] Improve path name handling
Fixes GCC 8 warning:
dll/win32/kernel32/client/loader.c: In function 'LoadLibraryA':
dll/win32/kernel32/client/loader.c:129:17: error: 'strncat' specified bound 13
equals source length [-Werror=stringop-overflow=]
strncat(PathBuffer, "\\twain_32.dll", 13);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
dll/win32/kernel32/client/loader.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/dll/win32/kernel32/client/loader.c b/dll/win32/kernel32/client/loader.c
index 905f6ae7037..ec4111470a3 100644
--- a/dll/win32/kernel32/client/loader.c
+++ b/dll/win32/kernel32/client/loader.c
@@ -110,23 +110,25 @@ WINAPI
DECLSPEC_HOTPATCH
LoadLibraryA(LPCSTR lpLibFileName)
{
+ static const CHAR TwainDllName[] = "twain_32.dll";
LPSTR PathBuffer;
UINT Len;
HINSTANCE Result;
/* Treat twain_32.dll in a special way (what a surprise...) */
- if (lpLibFileName && !_strcmpi(lpLibFileName, "twain_32.dll"))
+ if (lpLibFileName && !_strcmpi(lpLibFileName, TwainDllName))
{
/* Allocate space for the buffer */
- PathBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, MAX_PATH);
+ PathBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, MAX_PATH +
sizeof(ANSI_NULL));
if (PathBuffer)
{
/* Get windows dir in this buffer */
- Len = GetWindowsDirectoryA(PathBuffer, MAX_PATH - 13); /* 13 is sizeof of
'\\twain_32.dll' */
- if (Len && Len < (MAX_PATH - 13))
+ Len = GetWindowsDirectoryA(PathBuffer, MAX_PATH);
+ if ((Len != 0) && (Len < (MAX_PATH - sizeof(TwainDllName) -
sizeof('\\'))))
{
/* We successfully got windows directory. Concatenate twain_32.dll to it
*/
- strncat(PathBuffer, "\\twain_32.dll", 13);
+ PathBuffer[Len] = '\\';
+ strcpy(&PathBuffer[Len + 1], TwainDllName);
/* And recursively call ourselves with a new string */
Result = LoadLibraryA(PathBuffer);