<div dir="ltr">Hello Abid,<div><br></div><div>I thought it never can happen because <span style="font-size:12.8000001907349px">cUnescapedChar is less than 255 and "\\x%02hhu" prints something like \x12. Am I wrong?</span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">Thanks,</span></div><div><span style="font-size:12.8000001907349px">Ilia</span></div><div><span style="font-size:12.8000001907349px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 28, 2015 at 5:16 PM, Hafiz Abid Qadeer <span dir="ltr"><<a href="mailto:hafiz_abid@mentor.com" target="_blank">hafiz_abid@mentor.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: abidh<br>
Date: Tue Apr 28 09:16:00 2015<br>
New Revision: 235991<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=235991&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=235991&view=rev</a><br>
Log:<br>
Replace sprintf with snprintf to avoid a crash.<br>
During testing -data-list-register-values, I saw a crash here due to buffer overflow.<br>
This commit should fix the crash. There is still problem with printing 1-byte register<br>
in some cases that I will fix separately.<br>
<br>
No regression on MI test cases.<br>
<br>
<br>
Modified:<br>
    lldb/trunk/tools/lldb-mi/MIUtilString.cpp<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MIUtilString.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilString.cpp?rev=235991&r1=235990&r2=235991&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilString.cpp?rev=235991&r1=235990&r2=235991&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MIUtilString.cpp (original)<br>
+++ lldb/trunk/tools/lldb-mi/MIUtilString.cpp Tue Apr 28 09:16:00 2015<br>
@@ -17,6 +17,7 @@<br>
<br>
 // In-house headers:<br>
 #include "MIUtilString.h"<br>
+#include "Platform.h"<br>
<br>
 //++ ------------------------------------------------------------------------------------<br>
 // Details: CMIUtilString constructor.<br>
@@ -844,8 +845,9 @@ CMIUtilString::Escape(const bool vbEscap<br>
                     strNew.push_back(cUnescapedChar);<br>
                 else<br>
                 {<br>
-                    char strEscapedChar[sizeof("\\xXX")];<br>
-                    ::sprintf(strEscapedChar, "\\x%02" PRIx8, cUnescapedChar);<br>
+                    const size_t size = sizeof("\\xXX");<br>
+                    char strEscapedChar[size];<br>
+                    ::snprintf(strEscapedChar, size, "\\x%02" PRIx8, cUnescapedChar);<br>
                     strNew.append(strEscapedChar);<br>
                 }<br>
                 break;<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br></div>