SWI-Prolog / packages-ssl

The SWI-Prolog SSL interface
5 stars 14 forks source link

Zero the PL_CRYPTO_HASH_CONTEXT struct on first allocation #166

Closed matko closed 2 years ago

matko commented 2 years ago

On first allocation, the PL_CRYPTO_HASH_CONTEXT was not properly zero'd (only some fields were explicitely set to NULL). This caused later code to think the mac context was there when it in fact wasn't.

The code that triggered this bug for me was in pl_crypto_hash_context_copy. This checks if the mac field is NULL. If not, it'll use the mac_ctx field.

Zeroing the whole struct will prevent bugs like this from cropping up in the future without having to explicitely remember to NULL-initialize new fields and such.

See also https://github.com/SWI-Prolog/swipl-devel/issues/1014.

JanWielemaker commented 2 years ago

Thanks! Merged (squashed and updated commit message).