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

20231128-misc-fixes #7009

Merged
merged 6 commits into from
Nov 30, 2023
Merged

Conversation

douzzer
Copy link
Contributor

@douzzer douzzer commented Nov 29, 2023

src/ssl.c: remove frivolous (void)heap to clear -Wdeclaration-after-statement.

wolfcrypt/src/aes.c: add NEED_AES_TABLES gate around AesSetKey_C() implementations (fixes WOLFSSL_KCAPI_AES builds, probably among others).

wolfcrypt/src/sp_int.c: add missing casts to clear -Wconversions.

tested with wolfssl-multi-test.sh ... super-quick-check all-gcc-latest-c99-smallstack benchmark-wolfcrypt-intelasm-sp-asm-all fips-140-3-dev-kcapi fips-140-3-dev-kcapi-opensslextra-build linuxkm-aesni-sp-asm-pie-insmod-no-ec521-no-dh-no-rsa-ksanitize

…tatement.

wolfcrypt/src/aes.c: add NEED_AES_TABLES gate around AesSetKey_C() implementations (fixes WOLFSSL_KCAPI_AES builds, probably among others).

wolfcrypt/src/sp_int.c: add missing casts to clear -Wconversions.
@douzzer douzzer requested a review from wolfSSL-Bot November 29, 2023 05:38
@douzzer douzzer assigned wolfSSL-Bot and douzzer and unassigned wolfSSL-Bot Nov 29, 2023
@douzzer douzzer assigned wolfSSL-Bot and unassigned douzzer Nov 29, 2023
@@ -30149,7 +30149,7 @@ static int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names)
char name[MAX_CURVE_NAME_SZ];
byte groups_len = 0;
#ifdef WOLFSSL_SMALL_STACK
void *heap = ssl? ssl->heap : ctx ? ctx->heap : NULL; (void)heap;
void *heap = ssl? ssl->heap : ctx ? ctx->heap : NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

This was added specifically for (#6995). Would like @gojimmypi to comment before undoing the fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for asking. Good catch on a recent change.

remove frivolous (void)heap

I realize that it may look frivolous, however none of the usual explicit syntax adjustments would appease the ESP-IDF v5.1 Espressif compiler. I should have put a comment there as such.

If revisiting this particular line, I've been trying not to assign variables with an expression on the same line as declaring them, per a suggestion from @dgarske. I added the (void)heap as it was least intrusive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for connecting those dots. Reviewing types.h I've already found and fixed several macro implementations of XMALLOC() that were missing the needed (void)ings. Once I'm done I think we'll have it covered.

Copy link
Contributor

Choose a reason for hiding this comment

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

@douzzer you have a clever solution. Upon reconsideration of just applying the (void)(h), (void)(type) to everything in XMALLOC, I thought perhaps we'd have a problem where genuinely unused variables would not be caught. That's not the case, at least not in Visual Studio. This appears to be is working exactly as desired.

I've confirmed even when no code other than the groups = (int*)XMALLOC is included, the "Warning: unused variable" is properly not shown:

image

Further, and this is where it is really cool, when the heap variable is genuinely not used, the intellisense properly detects that, even with your updated XMALLOC.

image

Very nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is the way to do it. And for the record, @julek-wolfssl originated the code pattern for us, and I just expanded its coverage. Works a treat.

…ral XMALLOC/XFREE/XREALLOC macros that were missing them.

src/quic.c: fix misspelled DYNAMIC_TYPE_TMP_BUFFER.
…everal XMALLOC/XFREE/XREALLOC macros that were missing them.
@douzzer
Copy link
Contributor Author

douzzer commented Nov 30, 2023

@JacobBarthelmeh your intuition about the (void)heap was spot on. Turns out there was a slew of missing (void)ings in the macros in types.h and settings.h, and without fixing those, the ESP32 build still warned.

They're all fixed now, and @gojimmypi confirmed clean build on the latest, after replicating the warning on an intermediate commit.

@douzzer
Copy link
Contributor Author

douzzer commented Nov 30, 2023

retest this please.

@JacobBarthelmeh JacobBarthelmeh merged commit cc65c3e into wolfSSL:master Nov 30, 2023
92 checks passed
douzzer added a commit to douzzer/wolfssl that referenced this pull request Dec 5, 2023
…itialized data and resource leak defects around wc_AesInit() and wc_AesFree():

* followup to wolfSSL#7009 "20231128-misc-fixes" and  wolfSSL#7011 "Add missing wc_AesInit calls."

* adds WC_DEBUG_CIPHER_LIFECYCLE, which embeds asserts in low-level AES implementations for proper usage of wc_AesInit() and wc_AesFree().

* fixes native CMAC, AES-EAX, and AES-XTS implementations to assure resource release.

* adds missing wc_AesXtsInit() API, and adds a new wc_AesXtsSetKey_NoInit().

* fixes misspellings in EVP that unconditionally gated out AES-OFB and AES-XTS.

* fixes misspellings in EVP that unconditionally gated out AES-CBC and AES-CFB code in wolfSSL_EVP_CIPHER_CTX_cleanup_cipher().

* openssl compat AES low level cipher API has no counterpart to wc_AesFree(), so these compat APIs will now be gated out in configurations where they would otherwise leak memory or file descriptors (WOLFSSL_AFALG, WOLFSSL_DEVCRYPTO, WOLF_CRYPTO_CB, etc.).  A new macro, WC_AESFREE_IS_MANDATORY, is defined in wolfcrypt/aes.h to streamline this dependency.

* fixes 40 missing EVP_CIPHER_CTX_cleanup()s and 11 wc_AesFree()s in src/ssl.c, src/ssl_crypto.c, tests/api.c, and wolfcrypt/test/test.c.
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.

4 participants