Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/gui/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2418,11 +2418,11 @@ bool PCSX::GUI::about() {
clip::set_text(
fmt::format("Version: {}\nBuild: {}\nChangeset: {}\nDate & time: {:%Y-%m-%d %H:%M:%S}",
version.version, version.buildId.value(), version.changeset,
fmt::localtime(version.timestamp)));
*std::localtime(&version.timestamp)));
} else {
clip::set_text(fmt::format("Version: {}\nChangeset: {}\nDate & time: {:%Y-%m-%d %H:%M:%S}",
version.version, version.changeset,
fmt::localtime(version.timestamp)));
*std::localtime(&version.timestamp)));
}
}
ImGui::Text(_("Version: %s"), version.version.c_str());
Expand All @@ -2434,7 +2434,7 @@ bool PCSX::GUI::about() {
if (ImGui::SmallButton(version.changeset.c_str())) {
openUrl(fmt::format("https://github.com/grumpycoders/pcsx-redux/commit/{}", version.changeset));
}
std::tm tm = fmt::localtime(version.timestamp);
std::tm tm = *std::localtime(&version.timestamp);
std::string timestamp = fmt::format("{:%Y-%m-%d %H:%M:%S}", tm);
ImGui::Text(_("Date & time: %s"), timestamp.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int pcsxMain(int argc, char **argv) {
fmt::print(
"{{\n \"version\": \"{}\",\n \"changeset\": \"{}\",\n \"timestamp\": \"{}\",\n \"timestampDecoded\": "
"\"{:%Y-%m-%d %H:%M:%S}\"\n}}\n",
version.version, version.changeset, version.timestamp, fmt::localtime(version.timestamp));
version.version, version.changeset, version.timestamp, *std::localtime(&version.timestamp));
return 0;
Comment on lines 218 to 222
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Potential null pointer dereference.

std::localtime can return nullptr if the timestamp is invalid or a system error occurs. Dereferencing without a null check will cause undefined behavior and likely crash the application.

Consider adding a null check or using a safer alternative:

+        auto* tm = std::localtime(&version.timestamp);
+        if (!tm) {
+            fmt::print("Failed to convert timestamp\n");
+            return 1;
+        }
         fmt::print(
             "{{\n  \"version\": \"{}\",\n  \"changeset\": \"{}\",\n  \"timestamp\": \"{}\",\n  \"timestampDecoded\": "
             "\"{:%Y-%m-%d %H:%M:%S}\"\n}}\n",
-            version.version, version.changeset, version.timestamp, *std::localtime(&version.timestamp));
+            version.version, version.changeset, version.timestamp, *tm);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fmt::print(
"{{\n \"version\": \"{}\",\n \"changeset\": \"{}\",\n \"timestamp\": \"{}\",\n \"timestampDecoded\": "
"\"{:%Y-%m-%d %H:%M:%S}\"\n}}\n",
version.version, version.changeset, version.timestamp, fmt::localtime(version.timestamp));
version.version, version.changeset, version.timestamp, *std::localtime(&version.timestamp));
return 0;
auto* tm = std::localtime(&version.timestamp);
if (!tm) {
fmt::print("Failed to convert timestamp\n");
return 1;
}
fmt::print(
"{{\n \"version\": \"{}\",\n \"changeset\": \"{}\",\n \"timestamp\": \"{}\",\n \"timestampDecoded\": "
"\"{:%Y-%m-%d %H:%M:%S}\"\n}}\n",
version.version, version.changeset, version.timestamp, *tm);
return 0;
🤖 Prompt for AI Agents
In src/main/main.cc around lines 218-222, the code dereferences the pointer
returned by std::localtime without checking for nullptr which can crash if
std::localtime fails; update the code to call std::localtime (or the thread-safe
localtime_r/localtime_s variant) into a std::tm pointer, check that the pointer
is not null before using it, and if it is null produce a safe fallback (e.g.,
log/print an "invalid timestamp" string or the raw integer timestamp) so the
fmt::print call never dereferences a null pointer.

}

Expand Down
Loading