mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
More fine-grained logging messages on ZeroReturn/Syscall error cases
svn:r467
This commit is contained in:
parent
3f3f8921f6
commit
5f9ac2bdfd
@ -57,8 +57,11 @@ tls_log_error(int severity, const char *doing)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CATCH_SYSCALL 1
|
||||||
|
#define CATCH_ZERO 2
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tor_tls_get_error(tor_tls *tls, int r, int extra,
|
tor_tls_get_error(tor_tls *tls, int r, int extra,
|
||||||
const char *doing, int severity)
|
const char *doing, int severity)
|
||||||
{
|
{
|
||||||
int err = SSL_get_error(tls->ssl, r);
|
int err = SSL_get_error(tls->ssl, r);
|
||||||
@ -70,13 +73,15 @@ tor_tls_get_error(tor_tls *tls, int r, int extra,
|
|||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
return TOR_TLS_WANTWRITE;
|
return TOR_TLS_WANTWRITE;
|
||||||
case SSL_ERROR_SYSCALL:
|
case SSL_ERROR_SYSCALL:
|
||||||
/* This is oververbose XXX */
|
if (extra&CATCH_SYSCALL)
|
||||||
tls_log_error(severity, doing);
|
return _TOR_TLS_SYSCALL;
|
||||||
return extra ? _TOR_TLS_SYSCALL : TOR_TLS_ERROR;
|
log(severity, "TLS error: <syscall error>.");
|
||||||
|
return TOR_TLS_ERROR;
|
||||||
case SSL_ERROR_ZERO_RETURN:
|
case SSL_ERROR_ZERO_RETURN:
|
||||||
/* This is oververbose XXX */
|
if (extra&CATCH_ZERO)
|
||||||
tls_log_error(severity, doing);
|
return _TOR_TLS_ZERORETURN;
|
||||||
return extra ? _TOR_TLS_ZERORETURN : TOR_TLS_ERROR;
|
log(severity, "TLS error: Zero return");
|
||||||
|
return TOR_TLS_ERROR;
|
||||||
default:
|
default:
|
||||||
tls_log_error(severity, doing);
|
tls_log_error(severity, doing);
|
||||||
return TOR_TLS_ERROR;
|
return TOR_TLS_ERROR;
|
||||||
@ -299,11 +304,8 @@ tor_tls_read(tor_tls *tls, char *cp, int len)
|
|||||||
r = SSL_read(tls->ssl, cp, len);
|
r = SSL_read(tls->ssl, cp, len);
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
return r;
|
return r;
|
||||||
err = tor_tls_get_error(tls, r, 1, "reading", LOG_ERR);
|
err = tor_tls_get_error(tls, r, CATCH_ZERO, "reading", LOG_ERR);
|
||||||
if (err == _TOR_TLS_SYSCALL) {
|
if (err == _TOR_TLS_ZERORETURN) {
|
||||||
log(LOG_ERR, "TLS error while reading: syscall error");
|
|
||||||
return TOR_TLS_ERROR;
|
|
||||||
} else if (err == _TOR_TLS_ZERORETURN) {
|
|
||||||
tls->state = TOR_TLS_ST_CLOSED;
|
tls->state = TOR_TLS_ST_CLOSED;
|
||||||
return TOR_TLS_CLOSE;
|
return TOR_TLS_CLOSE;
|
||||||
} else {
|
} else {
|
||||||
@ -326,8 +328,7 @@ tor_tls_write(tor_tls *tls, char *cp, int n)
|
|||||||
if (n == 0)
|
if (n == 0)
|
||||||
return 0;
|
return 0;
|
||||||
r = SSL_write(tls->ssl, cp, n);
|
r = SSL_write(tls->ssl, cp, n);
|
||||||
err = tor_tls_get_error(tls, r, 1, "writing", LOG_ERR);
|
err = tor_tls_get_error(tls, r, 0, "writing", LOG_ERR);
|
||||||
assert(err != _TOR_TLS_ZERORETURN);
|
|
||||||
if (err == TOR_TLS_DONE) {
|
if (err == TOR_TLS_DONE) {
|
||||||
return r;
|
return r;
|
||||||
} else {
|
} else {
|
||||||
@ -376,13 +377,12 @@ tor_tls_shutdown(tor_tls *tls)
|
|||||||
do {
|
do {
|
||||||
r = SSL_read(tls->ssl, buf, 128);
|
r = SSL_read(tls->ssl, buf, 128);
|
||||||
} while (r>0);
|
} while (r>0);
|
||||||
err = tor_tls_get_error(tls, r, 1, "reading to shut down", LOG_ERR);
|
err = tor_tls_get_error(tls, r, CATCH_ZERO, "reading to shut down",
|
||||||
|
LOG_ERR);
|
||||||
if (err == _TOR_TLS_ZERORETURN) {
|
if (err == _TOR_TLS_ZERORETURN) {
|
||||||
tls->state = TOR_TLS_ST_GOTCLOSE;
|
tls->state = TOR_TLS_ST_GOTCLOSE;
|
||||||
/* fall through... */
|
/* fall through... */
|
||||||
} else {
|
} else {
|
||||||
if (err == _TOR_TLS_SYSCALL)
|
|
||||||
err = TOR_TLS_ERROR;
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -393,7 +393,8 @@ tor_tls_shutdown(tor_tls *tls)
|
|||||||
tls->state = TOR_TLS_ST_CLOSED;
|
tls->state = TOR_TLS_ST_CLOSED;
|
||||||
return TOR_TLS_DONE;
|
return TOR_TLS_DONE;
|
||||||
}
|
}
|
||||||
err = tor_tls_get_error(tls, r, 1, "shutting down", LOG_ERR);
|
err = tor_tls_get_error(tls, r, CATCH_SYSCALL|CATCH_ZERO, "shutting down",
|
||||||
|
LOG_ERR);
|
||||||
if (err == _TOR_TLS_SYSCALL) {
|
if (err == _TOR_TLS_SYSCALL) {
|
||||||
/* The underlying TCP connection closed while we were shutting down. */
|
/* The underlying TCP connection closed while we were shutting down. */
|
||||||
tls->state = TOR_TLS_ST_CLOSED;
|
tls->state = TOR_TLS_ST_CLOSED;
|
||||||
|
Loading…
Reference in New Issue
Block a user