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

Fixed segfault if chip was not found in chip config files #1166

Merged
merged 1 commit into from Aug 1, 2021
Merged

Fixed segfault if chip was not found in chip config files #1166

merged 1 commit into from Aug 1, 2021

Conversation

gszy
Copy link
Collaborator

@gszy gszy commented Jul 28, 2021

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 in:

if (memcmp (p2, params, sizeof (struct stlink_chipid_params) - sizeof (struct stlink_chipid_params *)) != 0) {

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.

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 Nightwalker-87 added this to In progress in Release v1.8.0 via automation Jul 28, 2021
@Nightwalker-87 Nightwalker-87 added this to the v1.7.1 milestone Jul 28, 2021
@Nightwalker-87 Nightwalker-87 changed the title Do not segfault if cannot find chip in config files Fixed segfault if chip was not found in chip config files Jul 28, 2021
@Nightwalker-87 Nightwalker-87 moved this from In progress to Review in progress in Release v1.8.0 Jul 28, 2021
@Nightwalker-87 Nightwalker-87 linked an issue Jul 31, 2021 that may be closed by this pull request
5 tasks
Release v1.8.0 automation moved this from Review in progress to Reviewer approved Jul 31, 2021
@Nightwalker-87 Nightwalker-87 merged commit 50069e3 into stlink-org:develop Aug 1, 2021
Release v1.8.0 automation moved this from Reviewer approved to Done Aug 1, 2021
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Aug 1, 2021
@gszy gszy deleted the prevent-segfault-on-null-params branch August 1, 2021 15:22
@Nightwalker-87 Nightwalker-87 linked an issue Aug 15, 2021 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
3 participants