[lldb-dev] Invalid iterator dereference in TypeMap::ForEach when it's invoked with TypeMaptoList callback

Mikhail Filimonov via lldb-dev lldb-dev at lists.llvm.org
Tue Nov 17 01:38:02 PST 2015


Hello, Ravi - you're welcome. I haven't filled a bug in lldb bug tracker, just mailed to dev list.

Mikhail 

-----Original Message-----
From: Addepally, Ravitheja [mailto:ravitheja.addepally at intel.com] 
Sent: Tuesday, November 17, 2015 12:34 PM
To: Pavel Labath <labath at google.com>; Mikhail Filimonov <mfilimonov at nvidia.com>
Cc: lldb-dev at lists.llvm.org
Subject: RE: [lldb-dev] Invalid iterator dereference in TypeMap::ForEach when it's invoked with TypeMaptoList callback

Hello,
	Yeah you are right Mikhail, thanks for pointing it out, I must ask, is there any bug already logged for this issue ? 
Ravi

-----Original Message-----
From: Pavel Labath [mailto:labath at google.com]
Sent: Monday, November 16, 2015 5:34 PM
To: Mikhail Filimonov <mfilimonov at nvidia.com>; Addepally, Ravitheja <ravitheja.addepally at intel.com>
Cc: lldb-dev at lists.llvm.org
Subject: Re: [lldb-dev] Invalid iterator dereference in TypeMap::ForEach when it's invoked with TypeMaptoList callback

Thanks for the heads-up Mikhail.

Ravi,

this looks like your code. Could you take a look at this?

pl


On 16 November 2015 at 16:24, Mikhail Filimonov via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> Hi guys and thank you for the excellent community project!
>
>
>
> Recently I’ve stumbled on a pesky, but trivial Invalid iterator 
> dereference bug in SymbolContext and TypeMap implementations at 
> revisions
>
> https://github.com/llvm-mirror/lldb/blob/e528da256d14ecac7df858462b44d
> ca931879509/source/Symbol/SymbolContext.cpp#L823
>
> and
>
> https://github.com/llvm-mirror/lldb/blob/5ac1fc5bc961688505334395598a2
> bb174eabd3b/source/Symbol/TypeMap.cpp#L172
>
>
>
> From the code below it is obvious that TypeMap::ForEach calls the 
> pre-increment operator on m_types iterator right after it has been 
> invalidated by m_types.erase
>
>
>
> SymbolContext::SortTypeList(TypeMap &type_map, TypeList &type_list ) 
> const
>
> {
>
>         TypeMaptoList callbackM2L (type_map, type_list);
>
>         type_map.ForEach(callbackM2L);
>
>                 return ;
>
> }
>
>
>
> void
>
> TypeMap::ForEach (std::function <bool(lldb::TypeSP &type_sp)> const
> &callback)
>
> {
>
>     for (auto pos = m_types.begin(), end = m_types.end(); pos != end;
> ++pos)
>
>     {
>
>         if (!callback(pos->second))
>
>             break;
>
>     }
>
> }
>
>
>
> bool
>
> TypeMap::RemoveTypeWithUID (user_id_t uid)
>
> {
>
>     iterator pos = m_types.find(uid);
>
>
>
>     if (pos != m_types.end())
>
>     {
>
>         m_types.erase(pos);
>
>         return true;
>
>     }
>
>     return false;
>
> }
>
>
>
> class TypeMaptoList
>
> {
>
> public:
>
>     TypeMaptoList(TypeMap &typem, TypeList &typel) :
>
>         type_map(typem),type_list(typel)
>
>     {
>
>     }
>
>
>
>     bool
>
>     operator() (const lldb::TypeSP& type)
>
>     {
>
>         if(type)
>
>         {
>
>             type_list.Insert(type);
>
>             type_map.RemoveTypeWithUID(type->GetID());
>
>             if (type_map.Empty())
>
>                 return false;
>
>         }
>
>         return true;
>
>     }
>
>
>
> private:
>
>     TypeMap &type_map;
>
>     TypeList &type_list;
>
> };
>
>
>
> Regards,
>
> Mikhail Filimonov
>
>
>
>
>
>
>
> ________________________________
> This email message is for the sole use of the intended recipient(s) 
> and may contain confidential information.  Any unauthorized review, 
> use, disclosure or distribution is prohibited.  If you are not the 
> intended recipient, please contact the sender by reply email and 
> destroy all copies of the original message.
> ________________________________
>
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev
>
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928


More information about the lldb-dev mailing list