From 8741026ba094cd00db40ff46b89143b753cf2aa9 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Sun, 22 Feb 2009 11:01:08 +0000 Subject: [PATCH] fix tiny buffer overflow in Hex2Ascii() git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2361 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/StringUtil.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/Src/StringUtil.cpp b/Source/Core/Common/Src/StringUtil.cpp index 523ed3133d..1d48efa223 100644 --- a/Source/Core/Common/Src/StringUtil.cpp +++ b/Source/Core/Common/Src/StringUtil.cpp @@ -76,7 +76,9 @@ u32 Ascii2Hex(std::string _Text) u32 Result = 0; // Max 32-bit values are supported - int Length = _Text.length(); if (Length > 4) Length = 4; + int Length = _Text.length(); + if (Length > 4) + Length = 4; for (int i = 0; i < Length; i++) { @@ -86,11 +88,12 @@ u32 Ascii2Hex(std::string _Text) // Return the value return Result; } + // Convert it back again std::string Hex2Ascii(u32 _Text) { // Create temporary storate - char Result[4]; + char Result[5]; // need space for the final \0 // Go through the four characters sprintf(Result, "%c%c%c%c", _Text >> 24, _Text >> 16, _Text >> 8, _Text); // Return the string