From c747c155678c0ee85b682dc91abce6f707b1fc02 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 18 Jan 2023 14:30:44 +0100 Subject: [PATCH] fix: Buffer overflow caused by hex input boxes --- lib/libimhex/include/hex/ui/imgui_imhex_extensions.h | 2 +- lib/libimhex/source/ui/imgui_imhex_extensions.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index bddd7e9df..1c00e0a8b 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -87,7 +87,7 @@ namespace ImGui { bool ToolBarButton(const char *symbol, ImVec4 color); bool IconButton(const char *symbol, ImVec4 color, ImVec2 size_arg = ImVec2(0, 0)); - bool InputIntegerPrefix(const char* label, const char *prefix, void *value, ImGuiDataType type, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None); + bool InputIntegerPrefix(const char* label, const char *prefix, void *value, ImGuiDataType type, const char *format, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None); bool InputHexadecimal(const char* label, u32 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None); bool InputHexadecimal(const char* label, u64 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None); diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index a28566c83..d6089d35f 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -507,7 +507,7 @@ namespace ImGui { return pressed; } - bool InputIntegerPrefix(const char *label, const char *prefix, void *value, ImGuiDataType type, ImGuiInputTextFlags flags) { + bool InputIntegerPrefix(const char *label, const char *prefix, void *value, ImGuiDataType type, const char *format, ImGuiInputTextFlags flags) { auto window = ImGui::GetCurrentWindow(); const ImGuiID id = window->GetID(label); const ImGuiStyle &style = GImGui->Style; @@ -520,11 +520,11 @@ namespace ImGui { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + frame_size.x); char buf[64]; - DataTypeFormatString(buf, IM_ARRAYSIZE(buf), type, value, "%llX"); + DataTypeFormatString(buf, IM_ARRAYSIZE(buf), type, value, format); bool value_changed = false; if (InputTextEx(label, nullptr, buf, IM_ARRAYSIZE(buf), ImVec2(CalcItemWidth() - frame_size.x, label_size.y + style.FramePadding.y * 2.0f), flags)) - value_changed = DataTypeApplyFromText(buf, ImGuiDataType_U64, value, "%llX"); + value_changed = DataTypeApplyFromText(buf, type, value, format); if (value_changed) MarkItemEdited(GImGui->LastItemData.ID); @@ -540,11 +540,11 @@ namespace ImGui { } bool InputHexadecimal(const char *label, u32 *value, ImGuiInputTextFlags flags) { - return InputIntegerPrefix(label, "0x", value, ImGuiDataType_U32, flags | ImGuiInputTextFlags_CharsHexadecimal); + return InputIntegerPrefix(label, "0x", value, ImGuiDataType_U32, "%lX", flags | ImGuiInputTextFlags_CharsHexadecimal); } bool InputHexadecimal(const char *label, u64 *value, ImGuiInputTextFlags flags) { - return InputIntegerPrefix(label, "0x", value, ImGuiDataType_U64, flags | ImGuiInputTextFlags_CharsHexadecimal); + return InputIntegerPrefix(label, "0x", value, ImGuiDataType_U64, "%llX", flags | ImGuiInputTextFlags_CharsHexadecimal); } void SmallProgressBar(float fraction, float yOffset) {