0

CertGetNameString() throws heap corruption error randomly, using the function CertGetNameStringW() does the same

LPCWSTR pszName = (LPCWSTR)malloc(cbSize * sizeof(TCHAR));
if (CertGetNameString( pCurrentCertContext, dwType, dwFlags, nullptr, pszName, cbSize)) {}

namus
  • 59
  • 1
  • 7
  • Don't mix `LPCWSTR` and `TCHAR`. You may not be compiling with the correct `UNICODE` and `_UNICODE` definitions, which makes `TCHAR` == `char` instead of `wchar_t` and your `malloc` half the expected size. Use `LPCWSTR`, `WCHAR` and `CertGetNameStringW` consistently. – Mark Tolonen Jun 21 '21 at 16:53

1 Answers1

0

The code which involves usage of CertGetNameString() cyrpt api requires the code be built using preprocessor directive UNICODE enabled.

namus
  • 59
  • 1
  • 7