From 676093e2533d8f1818c6ff82b7f9e15d5f76f637 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Tue, 8 Jul 2014 15:21:28 +0200 Subject: [PATCH] Check setsockopt() return value in net_bind() --- library/net.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/net.c b/library/net.c index 6333b0ff0..dda52098d 100644 --- a/library/net.c +++ b/library/net.c @@ -176,8 +176,12 @@ int net_bind( int *fd, const char *bind_ip, int port ) return( POLARSSL_ERR_NET_SOCKET_FAILED ); 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 ); + return( POLARSSL_ERR_NET_SOCKET_FAILED ); + } server_addr.sin_addr.s_addr = net_htonl( INADDR_ANY ); server_addr.sin_family = AF_INET;