Skip to content

Commit

Permalink
Fix crash when FormatMessageA sets lpBuffer to nullptr
Browse files Browse the repository at this point in the history
The std::string constructor would try to perform a strlen() call on the invalid pointer
  • Loading branch information
von Heydebrand Julian committed Mar 14, 2024
1 parent ab510c7 commit df4c6a4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ string GetLastErrorString() {
(char*)&msg_buf,
0,
NULL);

if (msg_buf == nullptr) {
char fallback_msg[128] = {0};
snprintf(fallback_msg, sizeof(fallback_msg), "GetLastError() = %d", err);
return fallback_msg;
}

string msg = msg_buf;
LocalFree(msg_buf);
return msg;
Expand Down

0 comments on commit df4c6a4

Please sign in to comment.