Fix some bugs.

Make sure cert_bio is NULL. If we have to break early it won't be
erroneously freed.

Fix up the pointer math walking the certificate attribute table.

Make sure the certificate length fits in what we have to work with.

Only handle PKCS#7 and Revision 2 for now.

Fix a memory leak by freeing cert_bio at the end of each loop.