Skip to content

Commit

Permalink
Merge pull request ninja-build#2394 from jheydebrand/GetLastErrorStri…
Browse files Browse the repository at this point in the history
…ng-crash

Fix crash when FormatMessageA sets lpBuffer to nullptr
  • Loading branch information
jhasse authored Mar 16, 2024
2 parents 3b23631 + df4c6a4 commit 86997c4
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 86997c4

Please sign in to comment.