Skip to content

Commit

Permalink
TLS: Fixed bogus error result
Browse files Browse the repository at this point in the history
While testing I ran into a situation where a read was returning -1 signaling an
error, but the socket error was 0. This then triggered an assertion failure in
LiteCore.

mbedTLS was returning the code MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY, which our
`translate_mbed_error` method converts to errno 0, i.e. it's not an error at
our level. However, `check_mbed_io` still returned -1.

Fixed by making `check_mbed_io` return 0, not -1, if the error code translates
to 0.
  • Loading branch information
snej committed Sep 2, 2021
1 parent c874ac3 commit 82c9342
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/mbedtls_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ namespace sockpp {
inline ssize_t check_mbed_io(int mbedResult) {
if (mbedResult < 0) {
clear(translate_mbed_err(mbedResult)); // sets last_error
return -1;
return last_error() ? -1 : 0;
}
return mbedResult;
}
Expand Down

0 comments on commit 82c9342

Please sign in to comment.