photosyst: fix read uninit dist if bypass fgets() MISRA C:2023 9.1 - #394
Open
GermanAizek wants to merge 1 commit into
Open
photosyst: fix read uninit dist if bypass fgets() MISRA C:2023 9.1#394GermanAizek wants to merge 1 commit into
GermanAizek wants to merge 1 commit into
Conversation
9.1 The value of an object with an automatic storage time should not be read before it has been set. Reference: https://www.mathworks.com/help/bugfinder/ref/misrac2023rule9.1.html
Owner
|
Could you please explain what can possibly go wrong since 'nr' is initialized to zero (even when fgets is skipped)? |
Contributor
Author
The initialization of nr to 0 and the subsequent if (nr <= 0) check act as a safeguard, ensuring that the dist array is only accessed and calculations are performed if sscanf successfully parsed at least one integer, setting nr to a positive value. @Atoptool well, yes, you're right, Clang compiler and static analyzers can unnecessarily incorrectly determine access to an uninitialized memory area. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@Atoptool, for security reasons, I would merge this urgently, there is no CVE ID for this issue yet, I have not checked whether exploitation of the vulnerability is possible.
9.1 The value of an object with an automatic storage time should not be read before it has been set.
Reference: https://www.mathworks.com/help/bugfinder/ref/misrac2023rule9.1.html