Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coverity CID :208200] Bad bit shift operation in drivers/interrupt_controller/intc_exti_stm32.c #22649

Closed
zephyrbot opened this issue Feb 9, 2020 · 1 comment
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix platform: STM32 ST Micro STM32 priority: low Low impact/importance bug

Comments

@zephyrbot
Copy link
Collaborator

Static code scan issues found in file:

https://github.com/zephyrproject-rtos/zephyr/tree/e089906b339aad4cd1b6589a3b6ce94782d93f54/drivers/interrupt_controller/intc_exti_stm32.c#L183

Category: Integer handling issues
Function: stm32_exti_trigger
Component: Drivers
CID: 208200

Details:

173         case STM32_EXTI_TRIG_RISING:
174             LL_EXTI_EnableRisingTrig_0_31(1 << line);
175             LL_EXTI_DisableFallingTrig_0_31(1 << line);
176             break;
177         case STM32_EXTI_TRIG_FALLING:
178             LL_EXTI_EnableFallingTrig_0_31(1 << line);
>>>     CID 208200:    (BAD_SHIFT)
>>>     In expression "1 << line", left shifting by more than 31 bits has undefined behavior.  The shift amount, "line", is at least 32.
179             LL_EXTI_DisableRisingTrig_0_31(1 << line);
180             break;
181         case STM32_EXTI_TRIG_BOTH:
182             LL_EXTI_EnableRisingTrig_0_31(1 << line);
183             LL_EXTI_EnableFallingTrig_0_31(1 << line);
184         default:
169         case STM32_EXTI_TRIG_NONE:
170             LL_EXTI_DisableRisingTrig_0_31(1 << line);
171             LL_EXTI_DisableFallingTrig_0_31(1 << line);
172             break;
173         case STM32_EXTI_TRIG_RISING:
174             LL_EXTI_EnableRisingTrig_0_31(1 << line);
>>>     CID 208200:    (BAD_SHIFT)
>>>     In expression "1 << line", left shifting by more than 31 bits has undefined behavior.  The shift amount, "line", is at least 32.
175             LL_EXTI_DisableFallingTrig_0_31(1 << line);
176             break;
177         case STM32_EXTI_TRIG_FALLING:
178             LL_EXTI_EnableFallingTrig_0_31(1 << line);
179             LL_EXTI_DisableRisingTrig_0_31(1 << line);
180             break;
172             break;
173         case STM32_EXTI_TRIG_RISING:
174             LL_EXTI_EnableRisingTrig_0_31(1 << line);
175             LL_EXTI_DisableFallingTrig_0_31(1 << line);
176             break;
177         case STM32_EXTI_TRIG_FALLING:
>>>     CID 208200:    (BAD_SHIFT)
>>>     In expression "1 << line", left shifting by more than 31 bits has undefined behavior.  The shift amount, "line", is at least 32.
178             LL_EXTI_EnableFallingTrig_0_31(1 << line);
179             LL_EXTI_DisableRisingTrig_0_31(1 << line);
180             break;
181         case STM32_EXTI_TRIG_BOTH:
182             LL_EXTI_EnableRisingTrig_0_31(1 << line);
183             LL_EXTI_EnableFallingTrig_0_31(1 << line);
168         switch (trigger) {
169         case STM32_EXTI_TRIG_NONE:
170             LL_EXTI_DisableRisingTrig_0_31(1 << line);
171             LL_EXTI_DisableFallingTrig_0_31(1 << line);
172             break;
173         case STM32_EXTI_TRIG_RISING:
>>>     CID 208200:    (BAD_SHIFT)
>>>     In expression "1 << line", left shifting by more than 31 bits has undefined behavior.  The shift amount, "line", is at least 32.
174             LL_EXTI_EnableRisingTrig_0_31(1 << line);
175             LL_EXTI_DisableFallingTrig_0_31(1 << line);
176             break;
177         case STM32_EXTI_TRIG_FALLING:
178             LL_EXTI_EnableFallingTrig_0_31(1 << line);
179             LL_EXTI_DisableRisingTrig_0_31(1 << line);
165             __ASSERT_NO_MSG(line);
166         }
167    
168         switch (trigger) {
169         case STM32_EXTI_TRIG_NONE:
170             LL_EXTI_DisableRisingTrig_0_31(1 << line);
>>>     CID 208200:    (BAD_SHIFT)
>>>     In expression "1 << line", left shifting by more than 31 bits has undefined behavior.  The shift amount, "line", is at least 32.
171             LL_EXTI_DisableFallingTrig_0_31(1 << line);
172             break;
173         case STM32_EXTI_TRIG_RISING:
174             LL_EXTI_EnableRisingTrig_0_31(1 << line);
175             LL_EXTI_DisableFallingTrig_0_31(1 << line);
176             break;
164         if (line >= 32) {
165             __ASSERT_NO_MSG(line);
166         }
167    
168         switch (trigger) {
169         case STM32_EXTI_TRIG_NONE:
>>>     CID 208200:    (BAD_SHIFT)
>>>     In expression "1 << line", left shifting by more than 31 bits has undefined behavior.  The shift amount, "line", is at least 32.
170             LL_EXTI_DisableRisingTrig_0_31(1 << line);
171             LL_EXTI_DisableFallingTrig_0_31(1 << line);
172             break;
173         case STM32_EXTI_TRIG_RISING:
174             LL_EXTI_EnableRisingTrig_0_31(1 << line);
175             LL_EXTI_DisableFallingTrig_0_31(1 << line);
176             break;
177         case STM32_EXTI_TRIG_FALLING:
178             LL_EXTI_EnableFallingTrig_0_31(1 << line);
179             LL_EXTI_DisableRisingTrig_0_31(1 << line);
180             break;
181         case STM32_EXTI_TRIG_BOTH:
>>>     CID 208200:    (BAD_SHIFT)
>>>     In expression "1 << line", left shifting by more than 31 bits has undefined behavior.  The shift amount, "line", is at least 32.
182             LL_EXTI_EnableRisingTrig_0_31(1 << line);
183             LL_EXTI_EnableFallingTrig_0_31(1 << line);
184         default:
185             __ASSERT_NO_MSG(trigger);
186         }
187     }
177         case STM32_EXTI_TRIG_FALLING:
178             LL_EXTI_EnableFallingTrig_0_31(1 << line);
179             LL_EXTI_DisableRisingTrig_0_31(1 << line);
180             break;
181         case STM32_EXTI_TRIG_BOTH:
182             LL_EXTI_EnableRisingTrig_0_31(1 << line);
>>>     CID 208200:    (BAD_SHIFT)
>>>     In expression "1 << line", left shifting by more than 31 bits has undefined behavior.  The shift amount, "line", is at least 32.
183             LL_EXTI_EnableFallingTrig_0_31(1 << line);
184         default:
185             __ASSERT_NO_MSG(trigger);
186         }
187     }
188    

Please fix or provide comments in coverity using the link:

https://scan9.coverity.com/reports.htm#v32951/p12996.

Note: This issue was created automatically. Priority was set based on classification
of the file affected and the impact field in coverity. Assignees were set using the CODEOWNERS file.

@zephyrbot zephyrbot added bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug labels Feb 9, 2020
@nashif nashif assigned erwango and unassigned andrewboie Feb 9, 2020
@erwango erwango added the platform: STM32 ST Micro STM32 label Feb 10, 2020
@erwango
Copy link
Member

erwango commented Feb 12, 2020

Line value is protected by following check at the beginning of the function:

	if (line >= 32) {
		__ASSERT_NO_MSG(line);
	}

Setting CID as intentional/ignore

@erwango erwango closed this as completed Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix platform: STM32 ST Micro STM32 priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

3 participants