Skip to content

Commit

Permalink
CADSTAR: Fix potential nullptr dereferencing bug
Browse files Browse the repository at this point in the history
Don't assume the footprint will have the pad index that the file references.
  • Loading branch information
Qbort committed Feb 5, 2022
1 parent 00ba580 commit 290354e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,15 @@ PAD* CADSTAR_PCB_ARCHIVE_LOADER::getKiCadPad( const COMPONENT_PAD& aCadstarPad,
PAD*& CADSTAR_PCB_ARCHIVE_LOADER::getPadReference( FOOTPRINT* aFootprint,
const PAD_ID aCadstarPadID )
{
return aFootprint->Pads().at( aCadstarPadID - (long long) 1 );
size_t index = aCadstarPadID - (long) 1;

if( !( index < aFootprint->Pads().size() ) )
{
THROW_IO_ERROR( _( "Unable to find pad index '%d' in footprint '%s'.", (long) aCadstarPadID,
aFootprint->GetReference() ) );
}

return aFootprint->Pads().at( index );
}


Expand Down Expand Up @@ -1703,12 +1711,11 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadComponents()
csPad.Side = padEx.Side;

// Find the pad in the footprint definition
PAD* kiPad = getPadReference( footprint, padEx.ID );
wxString padNumber = kiPad->GetNumber();
PAD* kiPad = getPadReference( footprint, padEx.ID );

if( kiPad )
delete kiPad;
wxString padNumber = kiPad->GetNumber();

delete kiPad;
kiPad = getKiCadPad( csPad, footprint );
kiPad->SetNumber( padNumber );

Expand Down

0 comments on commit 290354e

Please sign in to comment.