summaryrefslogtreecommitdiffstats
path: root/lldb/tools/lldb-mi/MIUtilString.cpp
diff options
context:
space:
mode:
authorHafiz Abid Qadeer <hafiz_abid@mentor.com>2015-04-28 14:16:00 +0000
committerHafiz Abid Qadeer <hafiz_abid@mentor.com>2015-04-28 14:16:00 +0000
commit7f2f0ccb0a145dd0b4618c15f16777c43568b3d0 (patch)
tree72ee242e9db55a5a4768b381358429fad1b23b56 /lldb/tools/lldb-mi/MIUtilString.cpp
parent7dea2e39824eb1d699c41bb113ce1f2b2a17d211 (diff)
downloadbcm5719-llvm-7f2f0ccb0a145dd0b4618c15f16777c43568b3d0.tar.gz
bcm5719-llvm-7f2f0ccb0a145dd0b4618c15f16777c43568b3d0.zip
Replace sprintf with snprintf to avoid a crash.
During testing -data-list-register-values, I saw a crash here due to buffer overflow. This commit should fix the crash. There is still problem with printing 1-byte register in some cases that I will fix separately. No regression on MI test cases. llvm-svn: 235991
Diffstat (limited to 'lldb/tools/lldb-mi/MIUtilString.cpp')
-rw-r--r--lldb/tools/lldb-mi/MIUtilString.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/lldb/tools/lldb-mi/MIUtilString.cpp b/lldb/tools/lldb-mi/MIUtilString.cpp
index 9fd1aef4e98..675bc465639 100644
--- a/lldb/tools/lldb-mi/MIUtilString.cpp
+++ b/lldb/tools/lldb-mi/MIUtilString.cpp
@@ -17,6 +17,7 @@
// In-house headers:
#include "MIUtilString.h"
+#include "Platform.h"
//++ ------------------------------------------------------------------------------------
// Details: CMIUtilString constructor.
@@ -844,8 +845,9 @@ CMIUtilString::Escape(const bool vbEscapeQuotes /* = false */) const
strNew.push_back(cUnescapedChar);
else
{
- char strEscapedChar[sizeof("\\xXX")];
- ::sprintf(strEscapedChar, "\\x%02" PRIx8, cUnescapedChar);
+ const size_t size = sizeof("\\xXX");
+ char strEscapedChar[size];
+ ::snprintf(strEscapedChar, size, "\\x%02" PRIx8, cUnescapedChar);
strNew.append(strEscapedChar);
}
break;
OpenPOWER on IntegriCloud