Skip to content

Commit

Permalink
Check the success of setsockopt
Browse files Browse the repository at this point in the history
Static analysis (coverity) reported a defect for not checking
the return from setsockopt.  Put in the check, and log if the
setsockopt fails (unlikely).

Fixes coverity 746751 and 746752
(cherry picked from commit 8ec9a2d)

Fixes #11598

Signed-off-by: Stuart Morgan <smorgan@mythtv.org>
  • Loading branch information
garybuhrmaster authored and stuartm committed Jun 15, 2013
1 parent a08ece5 commit 6c84654
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions mythtv/libs/libmythupnp/httprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ long HTTPRequest::SendResponse( void )

#ifdef USE_SETSOCKOPT
// Never send out partially complete segments
setsockopt( getSocketHandle(), SOL_TCP, TCP_CORK, &g_on, sizeof( g_on ));
if (setsockopt(getSocketHandle(), SOL_TCP, TCP_CORK,
&g_on, sizeof( g_on )) < 0)
{
LOG(VB_UPNP, LOG_INFO,
QString("HTTPRequest::SendResponse(xml/html) "
"setsockopt error setting TCP_CORK on ") + ENO);
}
#endif

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -319,7 +325,13 @@ long HTTPRequest::SendResponse( void )
// ----------------------------------------------------------------------

#ifdef USE_SETSOCKOPT
setsockopt( getSocketHandle(), SOL_TCP, TCP_CORK, &g_off, sizeof( g_off ));
if (setsockopt(getSocketHandle(), SOL_TCP, TCP_CORK,
&g_off, sizeof( g_off )) < 0)
{
LOG(VB_UPNP, LOG_INFO,
QString("HTTPRequest::SendResponse(xml/html) "
"setsockopt error setting TCP_CORK off ") + ENO);
}
#endif

return( nBytes );
Expand Down Expand Up @@ -357,7 +369,14 @@ long HTTPRequest::SendResponseFile( QString sFileName )

#ifdef USE_SETSOCKOPT
// Never send out partially complete segments
setsockopt( getSocketHandle(), SOL_TCP, TCP_CORK, &g_on, sizeof( g_on ));
if (setsockopt(getSocketHandle(), SOL_TCP, TCP_CORK,
&g_on, sizeof( g_on )) < 0)
{
LOG(VB_UPNP, LOG_INFO,
QString("HTTPRequest::SendResponseFile(%1) "
"setsockopt error setting TCP_CORK on " ).arg(sFileName) +
ENO);
}
#endif

QFile tmpFile( sFileName );
Expand Down Expand Up @@ -469,7 +488,14 @@ long HTTPRequest::SendResponseFile( QString sFileName )
// ----------------------------------------------------------------------

#ifdef USE_SETSOCKOPT
setsockopt( getSocketHandle(), SOL_TCP, TCP_CORK, &g_off, sizeof( g_off ));
if (setsockopt(getSocketHandle(), SOL_TCP, TCP_CORK,
&g_off, sizeof( g_off )) < 0)
{
LOG(VB_UPNP, LOG_INFO,
QString("HTTPRequest::SendResponseFile(%1) "
"setsockopt error setting TCP_CORK off ").arg(sFileName) +
ENO);
}
#endif

// -=>TODO: Only returns header length...
Expand Down

0 comments on commit 6c84654

Please sign in to comment.