mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-17 08:39:17 +00:00
Pcbnew: fix crash when loading a FP from older Kicad version in some cases:
if a "old" footprint (from version 7 and older) use a non kicad font in ref or value field, a use after free pointer created a crash. The use after free is fixed, but the initial font is lost, so this commit needs refinements.
This commit is contained in:
parent
89e281d042
commit
16c87f4914
@ -4750,20 +4750,34 @@ FOOTPRINT* PCB_IO_KICAD_SEXPR_PARSER::parseFOOTPRINT_unchecked( wxArrayString* a
|
||||
{
|
||||
// Fields other than reference and value weren't historically
|
||||
// stored in fp_texts so we don't need to handle them here
|
||||
bool text_must_be_deleted = false;
|
||||
|
||||
switch( field->GetId() )
|
||||
{
|
||||
case REFERENCE_FIELD:
|
||||
footprint->Reference() = PCB_FIELD( *text, REFERENCE_FIELD );
|
||||
const_cast<KIID&>( footprint->Reference().m_Uuid ) = text->m_Uuid;
|
||||
delete text;
|
||||
text_must_be_deleted = true;
|
||||
break;
|
||||
|
||||
case VALUE_FIELD:
|
||||
footprint->Value() = PCB_FIELD( *text, VALUE_FIELD );
|
||||
const_cast<KIID&>( footprint->Value().m_Uuid ) = text->m_Uuid;
|
||||
delete text;
|
||||
text_must_be_deleted = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if( text_must_be_deleted )
|
||||
{
|
||||
// We don't want to leave a dangling pointer in the map
|
||||
if( auto it = m_fontTextMap.find( text ); it != m_fontTextMap.end() )
|
||||
{
|
||||
// TODO: try to keep the font specified in m_fontTextMap
|
||||
m_fontTextMap.erase( it );
|
||||
}
|
||||
|
||||
delete text;
|
||||
}
|
||||
}
|
||||
else
|
||||
footprint->Add( text, ADD_MODE::APPEND, true );
|
||||
|
Loading…
Reference in New Issue
Block a user