fix mbedtls_cipher_finish invocations #122
Open
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.
those mbedtls_cipher_finish calls never did anything like this, since we were passing a null pointer for the third argument and the old included mbedtls just returns an error code (which we completely ignore) if you do that, refer to https://github.com/SciresM/hactool/blob/master/mbedtls/library/cipher.c#L684 for that.
I ran into this when I was building hactool against mbedtls 3.5.1 instead of the repo included one, it segfaults with that version (on dereferencing that third argument pointer), since they removed null pointer checks along the way to go with their stricter requirements on what you can pass as arguments.
you can argue this doesn't really meaningfully change or fix the operation of hactool, since all that crypto stuff is just transient anyway and any potential bad state issue evaporates once the program stops execution, but still I thought it was worth submitting this change.
&out_len reuse as output parameter for the mbedtls_cipher_finish is fine, since we never need that actual value from mbedtls_cipher_update invocation(s) anyway except now with this change to cleanly do the mbedtls_cipher_finish with the correct 2nd argument pointer