-
Notifications
You must be signed in to change notification settings - Fork 1k
20260729 Coverity fixes #11006
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
base: master
Are you sure you want to change the base?
20260729 Coverity fixes #11006
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2165,13 +2165,37 @@ void AddSession(WOLFSSL* ssl) | |||||||||||||||||||||||||||
| if (ssl->rng != NULL) | ||||||||||||||||||||||||||||
| rng = ssl->rng; | ||||||||||||||||||||||||||||
| #if defined(HAVE_GLOBAL_RNG) && defined(OPENSSL_EXTRA) | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 [Medium] initGlobalRNG is not re-checked after taking the lock (documented racy pattern elsewhere) The decision Suggestion:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed thanks. |
||||||||||||||||||||||||||||
| else if (initGlobalRNG == 1 || wolfSSL_RAND_Init() == WOLFSSL_SUCCESS) { | ||||||||||||||||||||||||||||
| else if (initGlobalRNG == 1 || | ||||||||||||||||||||||||||||
| wolfSSL_RAND_Init() == WOLFSSL_SUCCESS) { | ||||||||||||||||||||||||||||
| rng = &globalRNG; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| if (rng == &globalRNG) { | ||||||||||||||||||||||||||||
| if (wc_LockMutex(&globalRNGMutex) != 0) { | ||||||||||||||||||||||||||||
| WOLFSSL_MSG("Bad Lock Mutex rng"); | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| /* The above access requires initGlobalRNG recheck now | ||||||||||||||||||||||||||||
| * that we have the lock. */ | ||||||||||||||||||||||||||||
| if (initGlobalRNG == 0) { | ||||||||||||||||||||||||||||
| wc_UnLockMutex(&globalRNGMutex); | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||
| if (wc_RNG_GenerateBlock(rng, ssl->session->altSessionID, | ||||||||||||||||||||||||||||
| ID_LEN) != 0) | ||||||||||||||||||||||||||||
| ID_LEN) != 0) { | ||||||||||||||||||||||||||||
| #if defined(HAVE_GLOBAL_RNG) && defined(OPENSSL_EXTRA) | ||||||||||||||||||||||||||||
| if (rng == &globalRNG) { | ||||||||||||||||||||||||||||
| wc_UnLockMutex(&globalRNGMutex); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| #if defined(HAVE_GLOBAL_RNG) && defined(OPENSSL_EXTRA) | ||||||||||||||||||||||||||||
| if (rng == &globalRNG) { | ||||||||||||||||||||||||||||
| wc_UnLockMutex(&globalRNGMutex); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||
| ssl->session->haveAltSessionID = 1; | ||||||||||||||||||||||||||||
| id = ssl->session->altSessionID; | ||||||||||||||||||||||||||||
| idSz = ID_LEN; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -330,18 +330,22 @@ int test_wc_Base64_EncodeDecisionCoverage(void) | |||||||||
| byte enc[128]; | ||||||||||
| word32 i; | ||||||||||
| int nlCount = 0; | ||||||||||
|
|
||||||||||
| XMEMSET(enc, 0, sizeof(enc)); | ||||||||||
| for (i = 0; i < (word32)sizeof(in48); i++) | ||||||||||
| in48[i] = (byte)(i + 1); | ||||||||||
| outLen = (word32)sizeof(enc); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 [Low] test_coding.c change guards the read but does not initialize The PR description states "Initialize Suggestion:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, thanks. |
||||||||||
| ExpectIntEQ(Base64_Encode(in48, (word32)sizeof(in48), enc, &outLen), | ||||||||||
| 0); | ||||||||||
| for (i = 0; i < outLen; i++) { | ||||||||||
| if (enc[i] == '\n') | ||||||||||
| nlCount++; | ||||||||||
| if (EXPECT_SUCCESS()) { | ||||||||||
| for (i = 0; i < outLen; i++) { | ||||||||||
| if (enc[i] == '\n') | ||||||||||
| nlCount++; | ||||||||||
| } | ||||||||||
| /* exactly one (trailing) newline -- none inserted mid-stream */ | ||||||||||
| ExpectIntEQ(nlCount, 1); | ||||||||||
| ExpectIntEQ(enc[outLen - 1], '\n'); | ||||||||||
| } | ||||||||||
| /* exactly one (trailing) newline -- none inserted mid-stream */ | ||||||||||
| ExpectIntEQ(nlCount, 1); | ||||||||||
| ExpectIntEQ(enc[outLen - 1], '\n'); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /* --- force a BUFFER_E from CEscape() inside the *main* while loop | ||||||||||
|
|
||||||||||
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.
🟡 [Medium] No test exercises the new oversized-DER rejection path
💡 SUGGEST
testThe only existing coverage for this code path is
tests/api.c:20400-20416(d2i_RSAPrivateKey_biowith NULL args, an empty BIO, and a valid key). Nothing feeds a BIO whose outer SEQUENCE header declares a length above the new cap, so the added branch is never executed and a future refactor of the bound would go unnoticed. This is cheap to cover because only the SEQUENCE header needs to be well-formed — the body never gets read once the length check trips.Suggestion:
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.
New test has been added see
test_wolfSSL_d2i_RSAPrivateKey_bio_oversized()