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

Add variable initialization to large SSL TLS function #3311

Merged

Conversation

sander-visser
Copy link
Contributor

@sander-visser sander-visser commented May 6, 2020

Signed-off-by: sander-visser github@visser.se

Description

Added variable initialization for maintainability. Reported as false positive by cpp-check 1.89

Status

READY

Requires Backporting

No

Migrations

NO

Additional comments

Any additional information that could be of interest

Todos

  • Tests
  • Documentation
  • Changelog updated
  • Backported

Steps to test or reproduce

Outline the steps to test or reproduce the PR here.

@yanesca yanesca self-assigned this May 7, 2020
@yanesca
Copy link
Contributor

yanesca commented May 7, 2020

@sander-visser Thank you for your contribution!

Could you please help me finding the line where this uninitialised variable is used?

(As far as I can tell mac_key_len is either initialised on line 972 or on line 1005, otherwise the function exits on line 1080 before using it.)

@sander-visser
Copy link
Contributor Author

@sander-visser Thank you for your contribution!

Could you please help me finding the line where this uninitialised variable is used?

(As far as I can tell mac_key_len is either initialised on line 972 or on line 1005, otherwise the function exits on line 1080 before using it.)

If the mode is neither CHACHAPOLY CCM GCM CBC nor STREAM (or mbed TLS is configured to not support all modes and comehow an unsupported mode still gets processed this far) then it would still be uninitialized

@yanesca
Copy link
Contributor

yanesca commented May 7, 2020

If the mode is neither CHACHAPOLY CCM GCM CBC nor STREAM (or mbed TLS is configured to not support all modes and comehow an unsupported mode still gets processed this far) then it would still be uninitialized

Indeed, in this case it still would be uninitialised, but we would be exiting the function on line 1080 wouldn't we?

@gilles-peskine-arm
Copy link
Contributor

Or mbedtls_md_setup fails when initializing the HMAC contexts, so there's a goto end with mac_key_len uninitialized. It's still ok because mac_key_len is not used in this case. So the code is correct, but it's still fragile and it's good to fix it. I wouldn't blame a static analyzer for a false positive here.

@sander-visser Can you please add a changelog entry in ChangeLog.d, under the Changes category since there's no actual runtime bug?

@sander-visser sander-visser changed the title Fix use of unitialized stack variable Add variable initialization to large SSL TLS function May 7, 2020
@sander-visser
Copy link
Contributor Author

Or mbedtls_md_setup fails when initializing the HMAC contexts, so there's a goto end with mac_key_len uninitialized. It's still ok because mac_key_len is not used in this case. So the code is correct, but it's still fragile and it's good to fix it. I wouldn't blame a static analyzer for a false positive here.

@sander-visser Can you please add a changelog entry in ChangeLog.d, under the Changes category since there's no actual runtime bug?

Im ok with rejecting this PR - anyway the cange is so minor it does not need to be mentioned?

change triggered by false positive reported by Cppcheck 1.89.

Signed-off-by: sander-visser <github@visser.se>
@gilles-peskine-arm
Copy link
Contributor

We normally acknowledge all contributions via the changelog file. But of course as the contributor you can waive this. Anyway this habit dates back from the time when the change history wasn't public, and nowadays acknowledgement is built into the git author field.

Even if there's no behavior change, this is a robustness improvement, since a small change in the code could result in the variable being used without initialization in some configurations. So thanks for catching it!

@gilles-peskine-arm gilles-peskine-arm added component-tls enhancement needs-review Every commit must be reviewed by at least two team members, labels May 7, 2020
@gilles-peskine-arm gilles-peskine-arm added this to To do in Mbed TLS PRs via automation May 7, 2020
@sander-visser
Copy link
Contributor Author

We normally acknowledge all contributions via the changelog file. But of course as the contributor you can waive this. Anyway this habit dates back from the time when the change history wasn't public, and nowadays acknowledgement is built into the git author field.

Even if there's no behavior change, this is a robustness improvement, since a small change in the code could result in the variable being used without initialization in some configurations. So thanks for catching it!

Thank - im ok to waive conrib for this change. BTW: similar construct is present for header_len in ssl_cli.c

Copy link
Contributor

@yanesca yanesca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@sander-visser Thank you again for your contribution.

Mbed TLS PRs automation moved this from To do to Approved May 11, 2020
@yanesca yanesca merged commit 1a4a3f5 into Mbed-TLS:development May 11, 2020
Mbed TLS PRs automation moved this from Approved to Done May 11, 2020
yanesca added a commit that referenced this pull request Jul 1, 2020
Signed-off-by: Janos Follath <janos.follath@arm.com>
@daverodgman daverodgman removed this from Done in Mbed TLS PRs Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-tls enhancement needs-review Every commit must be reviewed by at least two team members,
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants