Reject len < -1 in ASN1_mbstring_ncopy#3232
Open
samuel40791765 wants to merge 1 commit intoaws:mainfrom
Open
Conversation
justsmth
previously approved these changes
May 8, 2026
Contributor
justsmth
left a comment
There was a problem hiding this comment.
NP: We could add testing to the end of TEST(ASN1Test, MBString)
// |len| values below -1 must be rejected. Only -1 is special-cased to mean
// "call strlen on |in|"; any other negative value would otherwise be cast to
// a huge |size_t| by |CBS_init|.
static const uint8_t kDummy[] = {'a'};
for (ossl_ssize_t bad_len : {(ossl_ssize_t)-2, (ossl_ssize_t)INT_MIN,
std::numeric_limits<ossl_ssize_t>::min()}) {
SCOPED_TRACE(bad_len);
EXPECT_EQ(-1, ASN1_mbstring_copy(nullptr, kDummy, bad_len, MBSTRING_UTF8,
B_ASN1_UTF8STRING));
ERR_clear_error();
ASN1_STRING *str = nullptr;
EXPECT_EQ(-1, ASN1_mbstring_ncopy(&str, kDummy, bad_len, MBSTRING_UTF8,
B_ASN1_UTF8STRING, /*minsize=*/0,
/*maxsize=*/0));
EXPECT_EQ(nullptr, str);
ERR_clear_error();
}
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3232 +/- ##
==========================================
+ Coverage 78.08% 78.12% +0.04%
==========================================
Files 689 689
Lines 122755 123129 +374
Branches 17083 17125 +42
==========================================
+ Hits 95856 96199 +343
- Misses 25996 26031 +35
+ Partials 903 899 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
96d6966 to
988afd0
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issues:
Addresses
V2196133741Description of changes:
ASN1_mbstring_ncopytreatslen == -1as "call strlen on in". Any other negative value fell through unchanged and was cast tosize_tbyCBS_init, producing a huge length. Adds an explicit early reject forlen < -1withASN1_R_ILLEGAL_FORMAT;-1and non-negative values continue to behave as before.Call-outs:
None.
Testing:
Existing ASN.1 string tests continue to pass.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.