Fixed segfault if chip was not found in chip config files#1166
Merged
Nightwalker-87 merged 1 commit intostlink-org:developfrom Aug 1, 2021
gszy:prevent-segfault-on-null-params
Merged
Fixed segfault if chip was not found in chip config files#1166Nightwalker-87 merged 1 commit intostlink-org:developfrom gszy:prevent-segfault-on-null-params
Nightwalker-87 merged 1 commit intostlink-org:developfrom
gszy:prevent-segfault-on-null-params
Conversation
stlink_chipid_get_params() used to segfault on memcmp() when struct stlink_chipid_params *params was NULL. This could happen if either: - there were no chip config files (*.chip), or - process_chipfile() failed to parse chip_id from the chip config files. The latter case is caused by the usage of atoi() to parse the chip id. Since the chip id is stored in hex, atoi() returns 0; such id cannot be matched to any actual chip. The segfault occurs on commit a52e1bc, in file src/stlink-lib/chipid.c:957 (https://github.com/stlink-org/stlink/blob/a52e1bc5489e23f3c1071c6912820efacaa3b22c/src/stlink-lib/chipid.c#L957). Check if params is NULL, in such case, set it to p2, which should not be NULL as long as struct stlink_chipid_params devices[] exists. May fix (workaround) #1163.
Nightwalker-87
approved these changes
Jul 28, 2021
This was
linked to
issues
Jul 28, 2021
5 tasks
Ant-ON
approved these changes
Jul 31, 2021
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
stlink_chipid_get_params()used to segfault onmemcmp()whenstruct stlink_chipid_params *paramswasNULL. This could happen if either:*.chip), orprocess_chipfile()failed to parsechip_idfrom the chip config files.The latter case is caused by the usage of
atoi()to parse the chip id. Since the chip id is stored in hex,atoi()returns 0; such id cannot be matched to any actual chip.The segfault occurs in:
stlink/src/stlink-lib/chipid.c
Line 957 in a52e1bc
Check if
paramsisNULL, in such case, set it top2, which should not beNULLas long asstruct stlink_chipid_params devices[]exists.May fix (workaround) #1163.