crypto: handle i2d_SSL_SESSION() error return
i2d_SSL_SESSION() can return a value <= 0 when the session is malformed or otherwise invalid. Handle that case.
This change comes without a regression test because I couldn't figure out a good way to generate an existing but invalid session in a timely fashion.