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

Avoid nullptr dereference in sts creds provider client #173

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SergeyRyabinin
Copy link

Issue #, if available:
Subj, avoid nullptr dereference
Description of changes:
Check for ptr being non-null, don't call

user_data->callback(user_data->credentials, user_data->error_code, user_data->user_data);

(as already called in s_clean_up_user_data).

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@bretambrose bretambrose left a comment

Choose a reason for hiding this comment

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

Seems fine but technically we would have crashed earlier because we're dereferencing provider_user_data from the very first line in the function.

@SergeyRyabinin
Copy link
Author

Seems fine but technically we would have crashed earlier because we're dereferencing provider_user_data from the very first line in the function.

thanks for the comment!

The original finding was

    if (provider_user_data) {
        s_clean_up_user_data(provider_user_data);
    } else {
        provider_user_data->callback(NULL, provider_user_data->error_code, provider_user_data->user_data);
    }

where the ptr provider_user_data is first checked and in case of NULL is being immediately dereferenced to call a callback, which is obviously wrong.
Another option is to simply remove the nullptr check.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 50.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 79.55%. Comparing base (277c8fb) to head (8625bca).

Files Patch % Lines
source/credentials_provider_sts.c 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #173   +/-   ##
=======================================
  Coverage   79.54%   79.55%           
=======================================
  Files          33       33           
  Lines        5872     5873    +1     
=======================================
+ Hits         4671     4672    +1     
  Misses       1201     1201           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@waahm7 waahm7 left a comment

Choose a reason for hiding this comment

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

When the provider_user_data is NULL, we never trigger the callback is wrong. I think the right solution would be to just fatal assert on provider_user_data being not NULL in s_make_request function, but I haven't traced through all the code paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants