mirror of
https://github.com/clearlinux/graphene.git
synced 2026-09-05 13:21:37 +00:00
[Pal/lib] Return PAL_ERROR_TRYAGAIN on try-again read/write errors in mbedTLS
Previously, lib_SSLRead() and lib_SSLWrite() returned PAL_ERROR_DENIED on any error, even on benign try-again errors from mbedTLS. This led to LibOS returning EACCES to the application which doesn't expect such error code. This commit converts benign try-again errors into corresponding PAL_ERROR_TRYAGAIN errors.
This commit is contained in:
@@ -105,6 +105,12 @@ int mbedtls_to_pal_error(int error)
|
||||
case MBEDTLS_ERR_RSA_RNG_FAILED:
|
||||
return -PAL_ERROR_CRYPTO_RNG_FAILED;
|
||||
|
||||
case MBEDTLS_ERR_SSL_WANT_READ:
|
||||
case MBEDTLS_ERR_SSL_WANT_WRITE:
|
||||
case MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS:
|
||||
case MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS:
|
||||
return -PAL_ERROR_TRYAGAIN;
|
||||
|
||||
default:
|
||||
return -PAL_ERROR_DENIED;
|
||||
}
|
||||
@@ -456,15 +462,15 @@ int lib_SSLHandshake(LIB_SSL_CONTEXT* ssl_ctx) {
|
||||
|
||||
int lib_SSLRead(LIB_SSL_CONTEXT* ssl_ctx, uint8_t* buf, size_t len) {
|
||||
int ret = mbedtls_ssl_read(&ssl_ctx->ssl, buf, len);
|
||||
if (ret <= 0)
|
||||
return -PAL_ERROR_DENIED;
|
||||
if (ret < 0)
|
||||
return mbedtls_to_pal_error(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lib_SSLWrite(LIB_SSL_CONTEXT* ssl_ctx, const uint8_t* buf, size_t len) {
|
||||
int ret = mbedtls_ssl_write(&ssl_ctx->ssl, buf, len);
|
||||
if (ret <= 0)
|
||||
return -PAL_ERROR_DENIED;
|
||||
if (ret < 0)
|
||||
return mbedtls_to_pal_error(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user