BUG/MINOR: ocsp: Increment certificate_ocsp refcount in 'ssl_sock_copy_cert_key_and_chain'
ssl_sock_copy_cert_key_and_chain() duplicates a ckch_data and duplicates
its ocsp_cid via OCSP_CERTID_dup(). Since the response tree is keyed on
the OCSP_CERTID itself, the copy points to the very same
certificate_ocsp entry as the original ckch_data, but no additional
reference was taken on it.
This was an issue because ssl_sock_free_cert_key_and_chain_contents
unconditionally decrements this certificate_ocsp's refcount_store while
the matching increment was only performed in ssl_sock_load_ocsp(),
If a duplicated ckch_data is freed (an aborted "set ssl cert"
transaction for instance) while the original ckch_store is still alive,
refcount_store can fall to 0 and the shared certificate_ocsp entry be
freed, leaving the original ckch_store with a dangling pointer. The next
OCSP response lookup or update would then use freed memory.
This was reported by brhenc in GitHub issue #3591.