Hi, I ran Coverity Scan on last version of libmicrohttpd and it found an unchecked return value of setsockopt when setting and removing TCP_CORK. >From my understanding of TCP_CORK it won't do much harm if setting of cork fails, but it might do some if we are not able to remove the cork - some data might not be sent.
On the other hand, I don't think the connection should be closed when we cannot remove the cork, so I just added message to log, so the user is able to identify the issue. (see the attached patch) Second thing Coverity is complaining about, is that you can find always-false condition in file daemon/daemon.c on line 783: 782 left = connection->response->total_size - connection->response_write_position; 783 if (left > SSIZE_MAX) 784 left = SSIZE_MAX; /* cap at return value limit */ As SSIZE_MAX is the max value of left's type, it can never be greater. >From the expression assigning value to variable left I would expect left should not be less than zero. But I am not sure if I got meaning of total_size and response_write_position completely right. So my question is if we should not rather check left against zero instead of SSIZE_MAX?
>From b0b4e9bbe0ff04cf46290c3977a4035dd0f74a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Pavl=C3=ADn?= <[email protected]> Date: Wed, 9 Jan 2013 10:33:33 +0100 Subject: [PATCH] Check result of setsockopt and log the error --- src/daemon/connection.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/daemon/connection.c b/src/daemon/connection.c index b612b8e..d146998 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c @@ -2376,8 +2376,15 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) /* done sending, uncork */ { const int val = 0; - setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, &val, + int r = 0; + r = setsockopt (connection->socket_fd, IPPROTO_TCP, TCP_CORK, &val, sizeof (val)); + if(r<0) { +#if HAVE_MESSAGES + MHD_DLOG (connection->daemon, "Unable to uncork socket (setsockopt failed): %s.\n", STRERROR(errno)); +#endif + } + } #endif end = -- 1.7.11.7
