Commit 7d2355af authored by etienneb's avatar etienneb Committed by Commit Bot

Fix potential missing nul character on resolved symbol names

The symbol name returned by SymFromName may not contains a NUL character
when the symbol name is exactly the size of the buffer. It believe this
may also happen when the symbol name is too long and truncated.

The original code is based on:
  https://msdn.microsoft.com/en-us/library/windows/desktop/ms680580(v=vs.85).aspx

A right implementation can be found here:
  https://cs.chromium.org/chromium/src/base/debug/stack_trace_win.cc?l=145&rcl=f4ecb9e37e9e2d59e32b8b96f23ac4a1e33b9552

As described here:
  https://msdn.microsoft.com/en-us/library/windows/desktop/ms680686(v=vs.85).aspx

  NameLen
    The length of the name, in characters, not including the null-terminating character.
  MaxNameLen
    The size of the Name buffer, in characters. If this member is 0, the Name member is not used.

This issue was causing the catapult symbolisation script to encode incorrect (random) characters into the symbol names.
See the example in the bug.

Original BUG=713741

Review-Url: https://codereview.chromium.org/2832643004
Cr-Commit-Position: refs/heads/master@{#466098}

BUG=724399,b:70905156

Change-Id: Ia6de4ddbd5c66a966b74ecec3fda5e853f36073b
Reviewed-on: https://chromium-review.googlesource.com/1147669Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Commit-Queue: Gabriel Marin <gmx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578373}
parent b76242f6
...@@ -147,6 +147,7 @@ int main(int argc, char *argv[]) { ...@@ -147,6 +147,7 @@ int main(int argc, char *argv[]) {
MAX_SYM_NAME*sizeof(TCHAR) + MAX_SYM_NAME*sizeof(TCHAR) +
sizeof(ULONG64) - 1) sizeof(ULONG64) - 1)
/ sizeof(ULONG64)]; / sizeof(ULONG64)];
memset(buffer, 0, sizeof(buffer));
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
IMAGEHLP_LINE64 line; IMAGEHLP_LINE64 line;
DWORD dummy; DWORD dummy;
...@@ -159,7 +160,8 @@ int main(int argc, char *argv[]) { ...@@ -159,7 +160,8 @@ int main(int argc, char *argv[]) {
ULONG64 absaddr = reladdr + module_base; ULONG64 absaddr = reladdr + module_base;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_SYM_NAME; // The length of the name is not including the null-terminating character.
pSymbol->MaxNameLen = MAX_SYM_NAME - 1;
if (print_function_name) { if (print_function_name) {
if (SymFromAddr(process, (DWORD64)absaddr, NULL, pSymbol)) { if (SymFromAddr(process, (DWORD64)absaddr, NULL, pSymbol)) {
printf("%s\n", pSymbol->Name); printf("%s\n", pSymbol->Name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment