Skip to content

Commit

Permalink
Fix for issue #442: avoids insecure sprintf functions
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-langholtz committed Feb 7, 2023
1 parent b579ca4 commit bb0a2de
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Testbed/Framework/DebugDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ void DebugDraw::DrawString(const Length2& pw, TextAlign align, const char *strin
char buffer[512];
va_list arg;
va_start(arg, string);
vsprintf(buffer, string, arg);
std::vsnprintf(buffer, sizeof(buffer), string, arg);
va_end(arg);

const auto textSize = ImGui::CalcTextSize(buffer);
Expand Down
4 changes: 2 additions & 2 deletions Testbed/Framework/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3539,8 +3539,8 @@ int main()
const auto buildDetails = GetBuildDetails();

char title[64];
std::sprintf(title, "PlayRho Testbed Version %d.%d.%d",
buildVersion.major, buildVersion.minor, buildVersion.revision);
std::snprintf(title, sizeof(title), "PlayRho Testbed Version %d.%d.%d",
buildVersion.major, buildVersion.minor, buildVersion.revision);

SetupGlfwWindowHints();

Expand Down
4 changes: 2 additions & 2 deletions Testbed/Framework/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,13 +1271,13 @@ void Test::Step(const Settings& settings, Drawer& drawer, UiState& ui)
ImGuiWindowFlags_NoCollapse);
char buffer[40];

std::sprintf(buffer, "Max of %u", m_stats.m_maxTouching);
std::snprintf(buffer, sizeof(buffer), "Max of %u", m_stats.m_maxTouching);
ImGui::PlotHistogram("# Touching", DequeValuesGetter<std::size_t>::Func,
&m_numTouchingPerStep, static_cast<int>(size(m_numTouchingPerStep)),
0, buffer, 0.0f, static_cast<float>(m_stats.m_maxContacts),
ImVec2(600, 100));

std::sprintf(buffer, "Max of %u", m_stats.m_maxContacts);
std::snprintf(buffer, sizeof(buffer), "Max of %u", m_stats.m_maxContacts);
ImGui::PlotHistogram("# Contacts", DequeValuesGetter<std::size_t>::Func,
&m_numContactsPerStep, static_cast<int>(size(m_numContactsPerStep)),
0, buffer, 0.0f, static_cast<float>(m_stats.m_maxContacts),
Expand Down

0 comments on commit bb0a2de

Please sign in to comment.