Skip to content

Commit

Permalink
Don't pass buffer as format string and free buffer
Browse files Browse the repository at this point in the history
Fixes warning "format string is not a string literal (potentially insecure)" and a memory leak.
  • Loading branch information
oold committed May 31, 2021
1 parent 7794605 commit c9f2b47
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions backward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3637,13 +3637,14 @@ template <> class TraceResolverImpl<system_tag::windows_tag>
char* lpMsgBuf;
DWORD dw = GetLastError();

FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(char*)&lpMsgBuf, 0, NULL);

printf(lpMsgBuf);
if (!FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(char*)&lpMsgBuf, 0, NULL)) {
std::fprintf(stderr, "%s\n", lpMsgBuf);
LocalFree(lpMsgBuf);
}

// abort();
}
Expand Down

0 comments on commit c9f2b47

Please sign in to comment.