Skip to content

mz_os_win32.c: kernel32.dll is always loaded, so use GetModuleHandleW().#448

Merged
nmoinvaz merged 1 commit into
zlib-ng:devfrom
GerbilSoft:bugfix/kernel32-path-overflow
Feb 9, 2020
Merged

mz_os_win32.c: kernel32.dll is always loaded, so use GetModuleHandleW().#448
nmoinvaz merged 1 commit into
zlib-ng:devfrom
GerbilSoft:bugfix/kernel32-path-overflow

Conversation

@GerbilSoft

Copy link
Copy Markdown
Contributor

The kernel32.dll pathname code had two issues:

  1. Using sizeof() for wchar_t[]. sizeof() returns the number of bytes, but the wcs*() functions need number of characters, so we end up telling wcsncat() that the buffer is twice as big as it actually is.

  2. wcsncat()'s size parameter is supposed to be the remaining size in the buffer, not the total size. wcscat_s() should be used instead, since it takes the total size of the buffer.

None of this is actually needed, since kernel32.dll is used by all Windows programs, so it's always loaded in memory.

The kernel32.dll pathname code had two issues:

1. Using sizeof() for wchar_t[]. sizeof() returns the number of bytes,
   but the wcs*() functions need number of characters, so we end up
   telling wcsncat() that the buffer is twice as big as it actually is.

2. wcsncat()'s size parameter is supposed to be the *remaining* size
   in the buffer, not the total size. wcscat_s() should be used instead,
   since it takes the total size of the buffer.

None of this is actually needed, since kernel32.dll is used by all
Windows programs, so it's always loaded in memory.
@GerbilSoft GerbilSoft changed the base branch from master to dev February 9, 2020 03:17
@nmoinvaz nmoinvaz merged commit cec7468 into zlib-ng:dev Feb 9, 2020
@nmoinvaz

nmoinvaz commented Feb 9, 2020

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants