[Lldb-commits] [lldb] r226544 - Fix creation of StringRef in FileSpec::ResolveUsername()

Jason Molenda jmolenda at apple.com
Mon Jan 19 20:51:24 PST 2015


I'm open to the idea that I'm fixing the wrong problem.  This came from FielSpec::SetFile -

void
FileSpec::SetFile (const char *pathname, bool resolve, PathSyntax syntax)
{
    m_filename.Clear();
    m_directory.Clear();
    m_is_resolved = false;
    m_syntax = (syntax == ePathSyntaxHostNative) ? FileSystem::GetNativePathSyntax() : syntax;

    if (pathname == NULL || pathname[0] == '\0')
        return;

    llvm::SmallString<64> normalized(pathname);

    if (resolve)
    {
        FileSpec::Resolve (normalized);
        m_is_resolved = true;
    }

I'm guessing SmallString doesn't store the terminal nul char in its buffer.  


> On Jan 19, 2015, at 8:27 PM, Zachary Turner <zturner at google.com> wrote:
> 
> While it's true that SmallString, and hence SmallVector support non null-terminated strings, it worries me if we have a non null-terminated string somewhere in LLDB.  
> 
> On Mon Jan 19 2015 at 8:25:17 PM Jason Molenda <jmolenda at apple.com> wrote:
> Author: jmolenda
> Date: Mon Jan 19 22:20:42 2015
> New Revision: 226544
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=226544&view=rev
> Log:
> Fix creation of StringRef in FileSpec::ResolveUsername()
> so it doesn't assume that the SmallVector<char> will have
> nul terminator.  It did not in at least one case.
> Caught by ASAN instrumentation.
> 
> Modified:
>     lldb/trunk/source/Host/common/FileSpec.cpp
> 
> Modified: lldb/trunk/source/Host/common/FileSpec.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=226544&r1=226543&r2=226544&view=diff
> ==============================================================================
> --- lldb/trunk/source/Host/common/FileSpec.cpp (original)
> +++ lldb/trunk/source/Host/common/FileSpec.cpp Mon Jan 19 22:20:42 2015
> @@ -65,7 +65,7 @@ FileSpec::ResolveUsername (llvm::SmallVe
>      if (path.empty() || path[0] != '~')
>          return;
> 
> -    llvm::StringRef path_str(path.data());
> +    llvm::StringRef path_str(path.data(), path.size());
>      size_t slash_pos = path_str.find_first_of("/", 1);
>      if (slash_pos == 1 || path.size() == 1)
>      {
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits





More information about the lldb-commits mailing list