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?

 

> On Oct 26, 2017, at 9:53 PM, Pavel Labath via lldb-commits 
> <lldb-commits@lists.llvm.org> wrote:
> 
> Author: labath
> Date: Thu Oct 26 21:53:24 2017
> New Revision: 316740
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=316740&view=rev
> Log:
> Fix a use-after-free in lldb-server
> 
> UriParser::Parse is returning a StringRef pointing the the parsed
> string, but we were calling it with a temporary string. Change this to a
> local variable to make sure the string persists as long as we need it.
> 
> Modified:
>    
> lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
> 
> Modified: 
> lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp?rev=316740&r1=316739&r2=316740&view=diff
> ==============================================================================
> --- 
> lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
>  (original)
> +++ 
> lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
>  Thu Oct 26 21:53:24 2017
> @@ -128,8 +128,9 @@ Status GDBRemoteCommunicationServerPlatf
>   llvm::StringRef platform_ip;
>   int platform_port;
>   llvm::StringRef platform_path;
> -  bool ok = UriParser::Parse(GetConnection()->GetURI(), platform_scheme,
> -                             platform_ip, platform_port, platform_path);
> +  std::string platform_uri = GetConnection()->GetURI();
> +  bool ok = UriParser::Parse(platform_uri, platform_scheme, platform_ip,
> +                             platform_port, platform_path);
>   UNUSED_IF_ASSERT_DISABLED(ok);
>   assert(ok);
> 
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to