<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Well, it was happening :-(. It is \\x%02x” and cUnescapedChar is not unsigned.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">So when it had value with MSB 1, then it overflew the buffer.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">There are other problems too with printing the 1-byte register. Current code
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">tries to print it as a character which is probably not the right thing. But that<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">is a separate fix.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Abid<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Ilia K [mailto:ki.stfu@gmail.com]
<br>
<b>Sent:</b> 28 April 2015 15:26<br>
<b>To:</b> Abid, Hafiz<br>
<b>Cc:</b> lldb-commits@cs.uiuc.edu<br>
<b>Subject:</b> Re: [Lldb-commits] [lldb] r235991 - Replace sprintf with snprintf to avoid a crash.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hello Abid,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I thought it never can happen because <span style="font-size:9.5pt">cUnescapedChar is less than 255 and "<a href="file:///\\x%2502hhu">\\x%02hhu</a>" prints something like \x12. Am I wrong?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">Thanks,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">Ilia</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Tue, Apr 28, 2015 at 5:16 PM, Hafiz Abid Qadeer <<a href="mailto:hafiz_abid@mentor.com" target="_blank">hafiz_abid@mentor.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">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("<a href="file:///\\xXX">\\xXX</a>")];<br>
-                    ::sprintf(strEscapedChar, "<a href="file:///\\x%2502">\\x%02</a>" PRIx8, cUnescapedChar);<br>
+                    const size_t size = sizeof("<a href="file:///\\xXX">\\xXX</a>");<br>
+                    char strEscapedChar[size];<br>
+                    ::snprintf(strEscapedChar, size, "<a href="file:///\\x%2502">\\x%02</a>" 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><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>