Merge remote-tracking branch 'upstream-public/pr/916' into mbedtls-2.1
diff --git a/ChangeLog b/ChangeLog
index 0518b88..a3e8715 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -41,6 +41,8 @@
* Don't print X.509 version tag for v1 CRT's, and omit extensions for
non-v3 CRT's.
* Fix bugs in RSA test suite under MBEDTLS_NO_PLATFORM_ENTROPY. #1023 #1024
+ * Fix net_would_block to avoid modification by errno through fcntl call.
+ Found by nkolban. Fixes #845.
Changes
* Extend cert_write example program by options to set the CRT version
diff --git a/library/net.c b/library/net.c
index b6b08ed..f08bbec 100644
--- a/library/net.c
+++ b/library/net.c
@@ -259,13 +259,18 @@
*/
static int net_would_block( const mbedtls_net_context *ctx )
{
+ int err = errno;
+
/*
* Never return 'WOULD BLOCK' on a non-blocking socket
*/
if( ( fcntl( ctx->fd, F_GETFL ) & O_NONBLOCK ) != O_NONBLOCK )
+ {
+ errno = err;
return( 0 );
+ }
- switch( errno )
+ switch( errno = err )
{
#if defined EAGAIN
case EAGAIN: