mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Fix potential buffer overruns due to mis-sized constant.
This commit is contained in:
parent
96ab76c6ea
commit
17415772cd
@ -24,11 +24,14 @@
|
||||
*/
|
||||
|
||||
/* Functions relative to the dialog creating the netlist for Pcbnew. The dialog is a notebook
|
||||
* with 4 fixed netlist formats:
|
||||
* with 7 fixed netlist formats:
|
||||
* Pcbnew
|
||||
* ORCADPCB2
|
||||
* Allegro
|
||||
* CADSTAR
|
||||
* Pads
|
||||
* SPICE
|
||||
* SPICE model
|
||||
* and up to CUSTOMPANEL_COUNTMAX user programmable formats. These external converters are
|
||||
* referred to as plugins, but they are really just external binaries.
|
||||
*/
|
||||
@ -59,27 +62,25 @@
|
||||
|
||||
#define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins
|
||||
|
||||
|
||||
/* panel (notebook page) identifiers
|
||||
* if modified, fix also the DEFINED_NETLISTS_COUNT value
|
||||
/*
|
||||
* PANEL_NETLIST_INDEX values are used as index in m_PanelNetType[]
|
||||
*/
|
||||
enum PANEL_NETLIST_INDEX
|
||||
{
|
||||
PANELPCBNEW = 0, /* Handle Netlist format Pcbnew */
|
||||
PANELORCADPCB2, /* Handle Netlist format OracdPcb2 */
|
||||
PANELALLEGRO, /* Handle Netlist format Allegro */
|
||||
PANELCADSTAR, /* Handle Netlist format CadStar */
|
||||
PANELPADS, /* Handle Netlist format PADS */
|
||||
PANELSPICE, /* Handle Netlist format Spice */
|
||||
PANELSPICEMODEL, /* Handle Netlist format Spice Model (subcircuit) */
|
||||
PANELCUSTOMBASE /* First auxiliary panel (custom netlists).
|
||||
* others use PANELCUSTOMBASE+1, PANELCUSTOMBASE+2.. */
|
||||
PANELPCBNEW = 0, /* Handle Netlist format Pcbnew */
|
||||
PANELORCADPCB2, /* Handle Netlist format OracdPcb2 */
|
||||
PANELALLEGRO, /* Handle Netlist format Allegro */
|
||||
PANELCADSTAR, /* Handle Netlist format CadStar */
|
||||
PANELPADS, /* Handle Netlist format PADS */
|
||||
PANELSPICE, /* Handle Netlist format Spice */
|
||||
PANELSPICEMODEL, /* Handle Netlist format Spice Model (subcircuit) */
|
||||
DEFINED_NETLISTS_COUNT,
|
||||
|
||||
/* First auxiliary panel (custom netlists). Subsequent ones use PANELCUSTOMBASE+1,
|
||||
* PANELCUSTOMBASE+2, etc., up to PANELCUSTOMBASE+CUSTOMPANEL_COUNTMAX-1 */
|
||||
PANELCUSTOMBASE = DEFINED_NETLISTS_COUNT
|
||||
};
|
||||
|
||||
// The count of panels for internally defined netlist formats
|
||||
// (the max count of panel is DEFINED_NETLISTS_COUNT+CUSTOMPANEL_COUNTMAX)
|
||||
#define DEFINED_NETLISTS_COUNT 6
|
||||
|
||||
/* wxPanels for creating the NoteBook pages for each netlist format: */
|
||||
class EXPORT_NETLIST_PAGE : public wxPanel
|
||||
@ -294,12 +295,15 @@ DIALOG_EXPORT_NETLIST::DIALOG_EXPORT_NETLIST( SCH_EDIT_FRAME* parent ) :
|
||||
SetupStandardButtons( { { wxID_OK, _( "Export Netlist" ) },
|
||||
{ wxID_CANCEL, _( "Close" ) } } );
|
||||
|
||||
for( int ii = 0; (ii < 4 + CUSTOMPANEL_COUNTMAX) && m_PanelNetType[ii]; ++ii )
|
||||
for( int ii = 0; ii < DEFINED_NETLISTS_COUNT + CUSTOMPANEL_COUNTMAX; ++ii )
|
||||
{
|
||||
if( m_PanelNetType[ii]->GetPageNetFmtName() == settings.m_NetFormatName )
|
||||
if( EXPORT_NETLIST_PAGE* page = m_PanelNetType[ii] )
|
||||
{
|
||||
m_NoteBook->ChangeSelection( ii );
|
||||
break;
|
||||
if( page->GetPageNetFmtName() == settings.m_NetFormatName )
|
||||
{
|
||||
m_NoteBook->ChangeSelection( ii );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,25 +395,16 @@ void DIALOG_EXPORT_NETLIST::InstallCustomPages()
|
||||
{
|
||||
EXPORT_NETLIST_PAGE* currPage;
|
||||
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
wxASSERT( cfg );
|
||||
wxCHECK( cfg, /* void */ );
|
||||
|
||||
if( cfg )
|
||||
for( size_t i = 0; i < CUSTOMPANEL_COUNTMAX && i < cfg->m_NetlistPanel.plugins.size(); i++ )
|
||||
{
|
||||
for( size_t i = 0; i < CUSTOMPANEL_COUNTMAX && i < cfg->m_NetlistPanel.plugins.size(); i++ )
|
||||
{
|
||||
// pairs of (title, command) are stored
|
||||
wxString title = cfg->m_NetlistPanel.plugins[i].name;
|
||||
// pairs of (title, command) are stored
|
||||
currPage = AddOneCustomPage( cfg->m_NetlistPanel.plugins[i].name,
|
||||
cfg->m_NetlistPanel.plugins[i].command,
|
||||
static_cast<NETLIST_TYPE_ID>( NET_TYPE_CUSTOM1 + i ) );
|
||||
|
||||
if( i >= cfg->m_NetlistPanel.plugins.size() )
|
||||
break; // No more panel to install
|
||||
|
||||
wxString command = cfg->m_NetlistPanel.plugins[i].command;
|
||||
|
||||
currPage = AddOneCustomPage( title, command,
|
||||
static_cast<NETLIST_TYPE_ID>( NET_TYPE_CUSTOM1 + i ) );
|
||||
|
||||
m_PanelNetType[PANELCUSTOMBASE + i] = currPage;
|
||||
}
|
||||
m_PanelNetType[PANELCUSTOMBASE + i] = currPage;
|
||||
}
|
||||
}
|
||||
|
||||
@ -739,29 +734,24 @@ void DIALOG_EXPORT_NETLIST::WriteCurrentNetlistSetup()
|
||||
m_Parent->OnModify();
|
||||
|
||||
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
||||
wxASSERT( cfg );
|
||||
|
||||
if( !cfg )
|
||||
return;
|
||||
wxCHECK( cfg, /* void */ );
|
||||
|
||||
cfg->m_NetlistPanel.plugins.clear();
|
||||
|
||||
// Update existing custom pages
|
||||
for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
|
||||
for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
|
||||
{
|
||||
EXPORT_NETLIST_PAGE* currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
|
||||
if( EXPORT_NETLIST_PAGE* currPage = m_PanelNetType[ii] )
|
||||
{
|
||||
wxString title = currPage->m_TitleStringCtrl->GetValue();
|
||||
wxString command = currPage->m_CommandStringCtrl->GetValue();
|
||||
|
||||
if( currPage == nullptr )
|
||||
break;
|
||||
if( title.IsEmpty() || command.IsEmpty() )
|
||||
continue;
|
||||
|
||||
wxString title = currPage->m_TitleStringCtrl->GetValue();
|
||||
wxString command = currPage->m_CommandStringCtrl->GetValue();
|
||||
|
||||
if( title.IsEmpty() || command.IsEmpty() )
|
||||
continue;
|
||||
|
||||
cfg->m_NetlistPanel.plugins.emplace_back( title, wxEmptyString );
|
||||
cfg->m_NetlistPanel.plugins.back().command = command;
|
||||
cfg->m_NetlistPanel.plugins.emplace_back( title, wxEmptyString );
|
||||
cfg->m_NetlistPanel.plugins.back().command = command;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -792,31 +782,34 @@ void DIALOG_EXPORT_NETLIST::OnAddGenerator( wxCommandEvent& event )
|
||||
if( dlg.ShowModal() != wxID_OK )
|
||||
return;
|
||||
|
||||
// Creates a new custom plugin page
|
||||
wxString title = dlg.GetGeneratorTitle();
|
||||
wxString cmd = dlg.GetGeneratorTCommandLine();
|
||||
|
||||
// Verify it does not exists
|
||||
int netTypeId = PANELCUSTOMBASE; // the first not used type id
|
||||
EXPORT_NETLIST_PAGE* currPage;
|
||||
|
||||
for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
|
||||
for( int ii = PANELCUSTOMBASE; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ++ii )
|
||||
{
|
||||
netTypeId = PANELCUSTOMBASE + ii;
|
||||
currPage = m_PanelNetType[ii + PANELCUSTOMBASE];
|
||||
|
||||
if( currPage == nullptr )
|
||||
break;
|
||||
|
||||
if( currPage->GetPageNetFmtName() == title )
|
||||
if( m_PanelNetType[ii] && m_PanelNetType[ii]->GetPageNetFmtName() == title )
|
||||
{
|
||||
wxMessageBox( _("This plugin already exists.") );
|
||||
wxMessageBox( _( "This plugin already exists." ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
wxString cmd = dlg.GetGeneratorTCommandLine();
|
||||
currPage = AddOneCustomPage( title,cmd, (NETLIST_TYPE_ID)netTypeId );
|
||||
m_PanelNetType[netTypeId] = currPage;
|
||||
// Find the first empty slot
|
||||
int netTypeId = PANELCUSTOMBASE;
|
||||
|
||||
while( m_PanelNetType[netTypeId] )
|
||||
{
|
||||
netTypeId++;
|
||||
|
||||
if( netTypeId == PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX )
|
||||
{
|
||||
wxMessageBox( _( "Maximum number of plugins already added to dialog." ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_PanelNetType[netTypeId] = AddOneCustomPage( title, cmd, (NETLIST_TYPE_ID)netTypeId );
|
||||
WriteCurrentNetlistSetup();
|
||||
|
||||
if( IsQuasiModal() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user