Add a macro to catch unhandled openssl errors.

svn:r1723
This commit is contained in:
Nick Mathewson 2004-04-26 23:00:07 +00:00
parent e34c201bb3
commit ad07c62938
3 changed files with 19 additions and 1 deletions

View File

@ -618,6 +618,18 @@ unsigned long tor_tls_get_n_bytes_written(tor_tls *tls)
return BIO_number_written(SSL_get_wbio(tls->ssl)); return BIO_number_written(SSL_get_wbio(tls->ssl));
} }
void _assert_no_tls_errors(const char *fname, int line)
{
if (ERR_peek_error() == 0)
return;
log_fn(LOG_ERR, "Unhandled OpenSSL errors found at %s:%d: ",
fname, line);
tls_log_errors(LOG_ERR, NULL);
tor_assert(0);
}
/* /*
Local Variables: Local Variables:
mode:c mode:c

View File

@ -33,6 +33,10 @@ int tor_tls_get_pending_bytes(tor_tls *tls);
unsigned long tor_tls_get_n_bytes_read(tor_tls *tls); unsigned long tor_tls_get_n_bytes_read(tor_tls *tls);
unsigned long tor_tls_get_n_bytes_written(tor_tls *tls); unsigned long tor_tls_get_n_bytes_written(tor_tls *tls);
#define assert_no_tls_errors() _assert_no_tls_errors(__FILE__,__LINE__);
void _assert_no_tls_errors(const char *fname, int line);
#endif #endif
/* /*

View File

@ -221,7 +221,7 @@ int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) {
tor_tls_get_pending_bytes(tls), at_most); tor_tls_get_pending_bytes(tls), at_most);
if (buf_ensure_capacity(buf, at_most+buf->datalen)) if (buf_ensure_capacity(buf, at_most+buf->datalen))
return -1; return TOR_TLS_ERROR;
if (at_most > buf->len - buf->datalen) if (at_most > buf->len - buf->datalen)
at_most = buf->len - buf->datalen; at_most = buf->len - buf->datalen;
@ -231,6 +231,8 @@ int read_to_buf_tls(tor_tls *tls, int at_most, buf_t *buf) {
log_fn(LOG_DEBUG,"before: %d on buf, %d pending, at_most %d.",(int)buf_datalen(buf), log_fn(LOG_DEBUG,"before: %d on buf, %d pending, at_most %d.",(int)buf_datalen(buf),
tor_tls_get_pending_bytes(tls), at_most); tor_tls_get_pending_bytes(tls), at_most);
assert_no_tls_errors();
r = tor_tls_read(tls, buf->mem+buf->datalen, at_most); r = tor_tls_read(tls, buf->mem+buf->datalen, at_most);
if (r<0) if (r<0)
return r; return r;