From 874bd64b2861851b7e9d2dc74be541ab55b0c896 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Thu, 17 Apr 2014 12:43:05 +0200
Subject: [PATCH] Check setsockopt() return value in net_bind()
---
library/net.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/library/net.c b/library/net.c
index 53bbf2fe7d..ff489864e4 100644
--- a/library/net.c
+++ b/library/net.c
@@ -281,8 +281,13 @@ int net_bind( int *fd, const char *bind_ip, int port )
}
n = 1;
- setsockopt( *fd, SOL_SOCKET, SO_REUSEADDR,
- (const char *) &n, sizeof( n ) );
+ if( setsockopt( *fd, SOL_SOCKET, SO_REUSEADDR,
+ (const char *) &n, sizeof( n ) ) != 0 )
+ {
+ close( *fd );
+ ret = POLARSSL_ERR_NET_SOCKET_FAILED;
+ continue;
+ }
if( bind( *fd, cur->ai_addr, cur->ai_addrlen ) != 0 )
{