<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">My takeaway is a bug was added that wasn't previously a bug. If code was designed to carefully use StringRef, then yes, it can be made safe. But we added StringRef support in all of LLDB and we didn't catch all of the possible misuses. My main questions is: is there anything we can do to catch these things now that we have them.<div class=""><br class=""></div><div class="">On Mac we can set the MallocScribble environment variable in our test suite. This will scribble 0x55 on all freed pages. This might catch some extra crashes. Malloc debug details:</div><div class=""><br class=""></div><div class=""><a href="https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html" class="">https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 31, 2017, at 8:12 AM, Zachary Turner <<a href="mailto:zturner@google.com" class="">zturner@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">The takeaway from this example is nothing we don't already know.  We need better test coverage.</div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Oct 31, 2017 at 8:08 AM Greg Clayton via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" class="">lldb-commits@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is one example of how StringRef causes issues because it was adopted everywhere. Is there any way we can change our functions so we can't run into this issue? Anything we can learn from this example?<br class="">
<br class="">
<br class="">
<br class="">
> On Oct 26, 2017, at 9:53 PM, Pavel Labath via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank" class="">lldb-commits@lists.llvm.org</a>> wrote:<br class="">
><br class="">
> Author: labath<br class="">
> Date: Thu Oct 26 21:53:24 2017<br class="">
> New Revision: 316740<br class="">
><br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=316740&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=316740&view=rev</a><br class="">
> Log:<br class="">
> Fix a use-after-free in lldb-server<br class="">
><br class="">
> UriParser::Parse is returning a StringRef pointing the the parsed<br class="">
> string, but we were calling it with a temporary string. Change this to a<br class="">
> local variable to make sure the string persists as long as we need it.<br class="">
><br class="">
> Modified:<br class="">
>    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp<br class="">
><br class="">
> Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp?rev=316740&r1=316739&r2=316740&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp?rev=316740&r1=316739&r2=316740&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (original)<br class="">
> +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp Thu Oct 26 21:53:24 2017<br class="">
> @@ -128,8 +128,9 @@ Status GDBRemoteCommunicationServerPlatf<br class="">
>   llvm::StringRef platform_ip;<br class="">
>   int platform_port;<br class="">
>   llvm::StringRef platform_path;<br class="">
> -  bool ok = UriParser::Parse(GetConnection()->GetURI(), platform_scheme,<br class="">
> -                             platform_ip, platform_port, platform_path);<br class="">
> +  std::string platform_uri = GetConnection()->GetURI();<br class="">
> +  bool ok = UriParser::Parse(platform_uri, platform_scheme, platform_ip,<br class="">
> +                             platform_port, platform_path);<br class="">
>   UNUSED_IF_ASSERT_DISABLED(ok);<br class="">
>   assert(ok);<br class="">
><br class="">
><br class="">
><br class="">
> _______________________________________________<br class="">
> lldb-commits mailing list<br class="">
> <a href="mailto:lldb-commits@lists.llvm.org" target="_blank" class="">lldb-commits@lists.llvm.org</a><br class="">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br class="">
<br class="">
_______________________________________________<br class="">
lldb-commits mailing list<br class="">
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank" class="">lldb-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></body></html>