Skip to content

Commit c93d0c5

Browse files
committed
bounds check for last_interrupt_index
1 parent 12f8d2c commit c93d0c5

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

cores/arduino/IRQManager.cpp

+32-15
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ bool IRQManager::addADCScanEnd(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
6767
/* set the displacement to the "programmable" part of the table */
6868
irq_ptr += FIXED_IRQ_NUM;
6969
bool rv = true;
70-
71-
if (adc->cfg.scan_end_irq == FSP_INVALID_VECTOR) {
70+
if (last_interrupt_index >= PROG_IRQ_NUM){
71+
rv = false;
72+
}
73+
else if (adc->cfg.scan_end_irq == FSP_INVALID_VECTOR) {
7274
if(set_adc_end_link_event(last_interrupt_index, adc->cfg.unit)) {
7375
adc->cfg.scan_end_ipl = TIMER_PRIORITY;
7476
adc->cfg.scan_end_irq = (IRQn_Type)last_interrupt_index;
@@ -101,8 +103,10 @@ bool IRQManager::addADCScanEndB(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
101103
/* set the displacement to the "programmable" part of the table */
102104
irq_ptr += FIXED_IRQ_NUM;
103105
bool rv = true;
104-
105-
if (adc->cfg.scan_end_b_irq == FSP_INVALID_VECTOR) {
106+
if (last_interrupt_index >= PROG_IRQ_NUM){
107+
rv = false;
108+
}
109+
else if (adc->cfg.scan_end_b_irq == FSP_INVALID_VECTOR) {
106110
if(set_adc_end_b_link_event(last_interrupt_index, adc->cfg.unit)) {
107111
adc->cfg.scan_end_b_ipl = TIMER_PRIORITY;
108112
adc->cfg.scan_end_b_irq = (IRQn_Type)last_interrupt_index;
@@ -125,8 +129,10 @@ bool IRQManager::addADCWinCmpA(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
125129
/* set the displacement to the "programmable" part of the table */
126130
irq_ptr += FIXED_IRQ_NUM;
127131
bool rv = true;
128-
129-
if( ((adc_extended_cfg_t *)(adc->cfg.p_extend))->window_a_irq == FSP_INVALID_VECTOR) {
132+
if (last_interrupt_index >= PROG_IRQ_NUM){
133+
rv = false;
134+
}
135+
else if( ((adc_extended_cfg_t *)(adc->cfg.p_extend))->window_a_irq == FSP_INVALID_VECTOR) {
130136
if(set_adc_win_a_link_event(last_interrupt_index, adc->cfg.unit)) {
131137
((adc_extended_cfg_t *)(adc->cfg.p_extend))->window_a_ipl = TIMER_PRIORITY;
132138
((adc_extended_cfg_t *)(adc->cfg.p_extend))->window_a_irq = (IRQn_Type)last_interrupt_index;
@@ -150,8 +156,10 @@ bool IRQManager::addADCWinCmpB(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
150156
/* set the displacement to the "programmable" part of the table */
151157
irq_ptr += FIXED_IRQ_NUM;
152158
bool rv = true;
153-
154-
if (((adc_extended_cfg_t *)(adc->cfg.p_extend))->window_b_irq == FSP_INVALID_VECTOR) {
159+
if (last_interrupt_index >= PROG_IRQ_NUM){
160+
rv = false;
161+
}
162+
else if (((adc_extended_cfg_t *)(adc->cfg.p_extend))->window_b_irq == FSP_INVALID_VECTOR) {
155163
if(set_adc_win_b_link_event(last_interrupt_index, adc->cfg.unit)) {
156164
((adc_extended_cfg_t *)(adc->cfg.p_extend))->window_b_ipl = TIMER_PRIORITY;
157165
((adc_extended_cfg_t *)(adc->cfg.p_extend))->window_b_irq = (IRQn_Type)last_interrupt_index;
@@ -177,8 +185,10 @@ bool IRQManager::addTimerOverflow(TimerIrqCfg_t &cfg, Irq_f fnc /* = nullptr */)
177185
/* set the displacement to the "programmable" part of the table */
178186
irq_ptr += FIXED_IRQ_NUM;
179187
bool rv = true;
180-
181-
if (cfg.base_cfg->cycle_end_irq == FSP_INVALID_VECTOR) {
188+
if (last_interrupt_index >= PROG_IRQ_NUM){
189+
rv = false;
190+
}
191+
else if (cfg.base_cfg->cycle_end_irq == FSP_INVALID_VECTOR) {
182192
if(cfg.gpt_ext_cfg != nullptr) {
183193
if(set_gpt_over_link_event(last_interrupt_index, cfg.base_cfg->channel)) {
184194
cfg.base_cfg->cycle_end_ipl = TIMER_PRIORITY;
@@ -224,7 +234,7 @@ bool IRQManager::addTimerUnderflow(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullptr*/)
224234
irq_ptr += FIXED_IRQ_NUM;
225235
bool rv = true;
226236

227-
if(cfg.agt_ext_cfg != nullptr) {
237+
if((cfg.agt_ext_cfg != nullptr) || (last_interrupt_index >= PROG_IRQ_NUM)) {
228238
/* not supported for AGT */
229239
rv = false;
230240
}
@@ -258,7 +268,7 @@ bool IRQManager::addTimerCompareCaptureA(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullp
258268
irq_ptr += FIXED_IRQ_NUM;
259269
bool rv = true;
260270

261-
if(cfg.agt_ext_cfg != nullptr) {
271+
if((cfg.agt_ext_cfg != nullptr) || (last_interrupt_index >= PROG_IRQ_NUM)) {
262272
/* not supported for AGT */
263273
rv = false;
264274
}
@@ -292,7 +302,7 @@ bool IRQManager::addTimerCompareCaptureB(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullp
292302
irq_ptr += FIXED_IRQ_NUM;
293303
bool rv = true;
294304

295-
if(cfg.agt_ext_cfg != nullptr) {
305+
if((cfg.agt_ext_cfg != nullptr) || (last_interrupt_index >= PROG_IRQ_NUM)) {
296306
/* not supported for AGT */
297307
rv = false;
298308
}
@@ -326,8 +336,10 @@ bool IRQManager::addDMA(dmac_extended_cfg_t &cfg, Irq_f fnc /* = nullptr */) {
326336
/* set the displacement to the "programmable" part of the table */
327337
irq_ptr += FIXED_IRQ_NUM;
328338
bool rv = true;
329-
330-
if (cfg.irq == FSP_INVALID_VECTOR) {
339+
if (last_interrupt_index >= PROG_IRQ_NUM){
340+
rv = false;
341+
}
342+
else if (cfg.irq == FSP_INVALID_VECTOR) {
331343
/* to check correctness of the channel */
332344
if(set_dma_link_event(last_interrupt_index, cfg.channel)) {
333345
cfg.ipl = DMA_PRIORITY;
@@ -357,6 +369,11 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
357369
irq_ptr += FIXED_IRQ_NUM;
358370
bool rv = true;
359371

372+
if(last_interrupt_index >= PROG_IRQ_NUM){
373+
rv = false;
374+
goto end_config;
375+
}
376+
360377
__disable_irq();
361378
/* **********************************************************************
362379
USB

0 commit comments

Comments
 (0)