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

Jason Molenda jmolenda at apple.com
Mon Jan 19 20:53:21 PST 2015


Should add -- when stopped here,


(lldb) p pathname
(const char *) $6 = 0x00007fb75946b890 "~jmolenda/lldb/simplebt.py"
(lldb) p normalized
(llvm::SmallString<64>) $5 = {
  llvm::SmallVector<char, 64> = {
    llvm::SmallVectorImpl<char> = {
      llvm::SmallVectorTemplateBase<char, true> = {
        llvm::SmallVectorTemplateCommon<char> = {
          llvm::SmallVectorBase = (BeginX = 0x00007fff57d85ee8, EndX = 0x00007fff57d85f02, CapacityX = 0x00007fff57d85f28)

(lldb)  mem r 0x00007fff57d85ee8 0x00007fff57d85f02+1
0x7fff57d85ee8: 7e 6a 6d 6f 6c 65 6e 64 61 2f 6c 6c 64 62 2f 73  ~jmolenda/lldb/s
0x7fff57d85ef8: 69 6d 70 6c 65 62 74 2e 70 79 1b                 implebt.py.

It looks like I'm getting a 0x1b instead of a \0 here.


> On Jan 19, 2015, at 8:51 PM, Jason Molenda <jmolenda at apple.com> wrote:
> 
> 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