<div dir="ltr">It's worth mentioning again that LLVM uses StringRef pretty pervasively and doesn't have issues.  There's nothing fundamentally different about debuggers that makes StringRefs bad whereas they can be good in other types of software.  If we really wanted to avoid use-after-frees we would pick a language other than C++.<div><br></div><div>Note that StringRef is now part of the C++ standard, under the name std::string_view.  Every part of C++ can shoot you in the foot if used incorrectly.  This is equally true for std::string , and pointers in general.  I don't see anything special about this particular bug.  Someone returned a pointer to stack memory.  That's a pretty common class of bug.</div><div><br></div><div>Actually though, I did think of another thing we learn from this example.  We should be running LLDB under ASAN</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 31, 2017 at 8:12 AM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The takeaway from this example is nothing we don't already know.  We need better test coverage.</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 31, 2017 at 8:08 AM Greg Clayton via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br></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>
<br>
<br>
<br>
> On Oct 26, 2017, at 9:53 PM, Pavel Labath via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: labath<br>
> Date: Thu Oct 26 21:53:24 2017<br>
> New Revision: 316740<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=316740&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=316740&view=rev</a><br>
> Log:<br>
> Fix a use-after-free in lldb-server<br>
><br>
> UriParser::Parse is returning a StringRef pointing the the parsed<br>
> string, but we were calling it with a temporary string. Change this to a<br>
> local variable to make sure the string persists as long as we need it.<br>
><br>
> Modified:<br>
>    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp<br>
><br>
> Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp<br>
> 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">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>
> ==============================================================================<br>
> --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (original)<br>
> +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp Thu Oct 26 21:53:24 2017<br>
> @@ -128,8 +128,9 @@ Status GDBRemoteCommunicationServerPlatf<br>
>   llvm::StringRef platform_ip;<br>
>   int platform_port;<br>
>   llvm::StringRef platform_path;<br>
> -  bool ok = UriParser::Parse(GetConnection()->GetURI(), platform_scheme,<br>
> -                             platform_ip, platform_port, platform_path);<br>
> +  std::string platform_uri = GetConnection()->GetURI();<br>
> +  bool ok = UriParser::Parse(platform_uri, platform_scheme, platform_ip,<br>
> +                             platform_port, platform_path);<br>
>   UNUSED_IF_ASSERT_DISABLED(ok);<br>
>   assert(ok);<br>
><br>
><br>
><br>
> _______________________________________________<br>
> lldb-commits mailing list<br>
> <a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div></blockquote></div>