openssl: [REGRESSION] CMS_Final() fails when modifying CMS

Root cause: #19919 “Fix SMIME_crlf_copy() to properly report an error” master 9e5bd8923bff3e4f0cbba05c7dadfe289c66eb6f >=openssl-3.0.8 6259cf34eab1abdcfde12b7b3892b4780844091b

Previous behavior required CMS_final() to be called when CMS is modified (for example add recepient). Currently, the CMS_final() fails with:

802BF10400000000:error:100C0102:BIO routines:bio_read_intern:passed a null parameter:crypto/bio/bio_lib.c:274:
802BF10400000000:error:1C80006B:Provider routines:ossl_cipher_generic_block_final:wrong final block length:providers/implementations/ciphers/ciphercommon.c:429:

Interestingly, if the CMS_final() is removed, the CMS is created correctly, however, it leaks memory.

Reproduction project is available here[1].

[1] https://github.com/alonbl/openssl-regression-cms

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 15 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Hi,

Thanks great!

I can confirm that removing the CMS_final() and replacing the i2d_CMS_bio() with i2d_CMS_bio_stream() and adding the BIO_free_all(CMS_dataInit(cms, NULL)) works in all branches.

Look at this branch: https://github.com/alonbl/openssl-regression-cms/tree/no-final

Alon