-
Notifications
You must be signed in to change notification settings - Fork 105
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
Fix possible NULL pointer dereference. #858
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #858 +/- ##
==========================================
- Coverage 72.43% 72.41% -0.02%
==========================================
Files 34 34
Lines 9773 9775 +2
==========================================
Hits 7079 7079
- Misses 2694 2696 +2 ☔ View full report in Codecov by Sentry. |
src/lib/db.c
Outdated
@@ -2169,7 +2169,7 @@ static CK_RV dbup_handler_from_7_to_8(sqlite3 *updb) { | |||
|
|||
/* for each tobject */ | |||
CK_ATTRIBUTE_PTR a = attr_get_attribute_by_type(tobj->attrs, CKA_ALLOWED_MECHANISMS); | |||
CK_BYTE type = type_from_ptr(a->pValue, a->ulValueLen); | |||
CK_BYTE type = a ? type_from_ptr(a->pValue, a->ulValueLen): 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the object doesn't have the attribute CKA_ALLOWED_MECHANISMS, it should just be skipped. This patch would cause us to process everything no matter what, which is harmless, but not needed.
if (a) {
CK_BYTE type = type_from_ptr(a->pValue, a->ulValueLen);
if (type != TYPE_BYTE_INT_SEQ) {
rv = _db_update_tobject_attrs(updb, tobj->id, tobj->attrs);
}
}
tobject_free(tobj);
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean something like this?
if (a) {
CK_BYTE type = type_from_ptr(a->pValue, a->ulValueLen);
if (type != TYPE_BYTE_INT_SEQ) {
rv = _db_update_tobject_attrs(updb, tobj->id, tobj->attrs);
}
} else {
tobject_free(tobj);
continue;
}
or let it fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for an else clause, as we need it to perform the tobject_free()
or a memory leak will ensue. We also need to step the database so we can get the next row item to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we shouldn't check rv
in this case, right?
if (a && rv != CKR_OK) {
goto error;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you could also just unconditionally set rv = CKR_OK
before the statement, either way is fine by me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So overall the diff is fine, but you need to squash your two commits into one and improve the commit message and add Fixes: #845 and don't forget to signoff on your commit. Thanks!
Fixes: tpm2-software#845 Signed-off-by: Victor Makarov <[email protected]>
done |
@williamcroberts could u take a look? the fix is critical |
also tagging some other active maintainers (https://github.com/orgs/tpm2-software/people) cuz last William's activity was on August 11. @AndreasFuchsTPM guys could you take a look? ps: after merging this one we could reject #849 as a duplicate |
@williamcroberts could you please also give any ETA for next release with the fix? |
I'm gonna start the release process this week.
…On Wed, Sep 4, 2024, 07:21 Sergey ***@***.***> wrote:
@williamcroberts <https://github.com/williamcroberts> could you please
also give any ETA for next release with the fix?
—
Reply to this email directly, view it on GitHub
<#858 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEHNWB5HDVFPOK2YSZBR2SLZU33LJAVCNFSM6AAAAABEZROBW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRYHAZTGMRSGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This caused SEGFAULT when moving sql3 db from 1.7 to 1.9. With this fix I've managed to use old db successfully.