Skip to content

Commit fd918f2

Browse files
Davidovory03lws-team
authored andcommitted
mbedtls: translate error codes for caller
#3315
1 parent 39b9046 commit fd918f2

File tree

1 file changed

+26
-12
lines changed
  • lib/tls/mbedtls/wrapper/platform

1 file changed

+26
-12
lines changed

lib/tls/mbedtls/wrapper/platform/ssl_pm.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,24 +423,38 @@ int ssl_pm_clear(SSL *ssl)
423423

424424
int ssl_pm_read(SSL *ssl, void *buffer, int len)
425425
{
426-
int ret;
427-
struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
426+
int ret;
427+
struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
428428

429-
ret = mbedtls_ssl_read(&ssl_pm->ssl, buffer, (size_t)len);
430-
if (ret < 0) {
431-
// lwsl_notice("%s: mbedtls_ssl_read says -0x%x\n", __func__, -ret);
432-
SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "mbedtls_ssl_read() return -0x%x", -ret);
433-
if (ret == MBEDTLS_ERR_NET_CONN_RESET ||
429+
ret = mbedtls_ssl_read(&ssl_pm->ssl, buffer, (size_t)len);
430+
if (ret < 0) {
431+
// lwsl_notice("%s: mbedtls_ssl_read says -0x%x\n", __func__, -ret);
432+
SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "mbedtls_ssl_read() return -0x%x", -ret);
433+
if (ret == MBEDTLS_ERR_NET_CONN_RESET ||
434434
#if defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000
435-
ret <= MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE) /* fatal errors */
435+
ret <= MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE) /* fatal errors */
436436
#else
437-
ret <= MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) /* fatal errors */
437+
ret <= MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) /* fatal errors */
438438
#endif
439439
ssl->err = SSL_ERROR_SYSCALL;
440-
ret = -1;
441-
}
442440

443-
return ret;
441+
switch (ret) {
442+
case MBEDTLS_ERR_NET_CONN_RESET:
443+
ssl->err = SSL_ERROR_SYSCALL;
444+
break;
445+
case MBEDTLS_ERR_SSL_WANT_WRITE:
446+
ssl->err = SSL_ERROR_WANT_WRITE;
447+
break;
448+
case MBEDTLS_ERR_SSL_WANT_READ:
449+
ssl->err = SSL_ERROR_WANT_READ;
450+
break;
451+
default:
452+
break;
453+
}
454+
ret = -1;
455+
}
456+
457+
return ret;
444458
}
445459

446460
/*

0 commit comments

Comments
 (0)