gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] 02/02: Fixed hypothetical situation when ti


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 02/02: Fixed hypothetical situation when timeout could be larger than possible to measure. Fixed detecting real closest timeout deadline when value wraps upper limit. Fixed compiler warnings.
Date: Wed, 05 Apr 2017 22:22:21 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 8851d88e40a33bb942165c45d4e9d439038106a9
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Wed Apr 5 23:21:59 2017 +0300

    Fixed hypothetical situation when timeout could be larger than possible to 
measure.
    Fixed detecting real closest timeout deadline when value wraps upper limit.
    Fixed compiler warnings.
---
 src/microhttpd/connection.c       |  5 +++--
 src/microhttpd/connection_https.c |  2 +-
 src/microhttpd/daemon.c           | 21 ++++++++++++++++-----
 src/microhttpd/internal.h         |  9 +++++++--
 4 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 0b6ce3bd..70c7268e 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3245,7 +3245,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
     }
   if (! connection->suspended)
     {
-      unsigned int timeout;
+      time_t timeout;
       timeout = connection->connection_timeout;
       if ( (0 != timeout) &&
            (timeout < (MHD_monotonic_sec_counter() - 
connection->last_activity)) )
@@ -3377,7 +3377,8 @@ MHD_get_connection_info (struct MHD_Connection 
*connection,
     case MHD_CONNECTION_INFO_CONNECTION_SUSPENDED:
       return (const union MHD_ConnectionInfo *) &connection->suspended;
     case MHD_CONNECTION_INFO_CONNECTION_TIMEOUT:
-      return (const union MHD_ConnectionInfo *) 
&connection->connection_timeout;
+      connection->connection_timeout_dummy = connection->connection_timeout;
+      return (const union MHD_ConnectionInfo *) 
&connection->connection_timeout_dummy;
     default:
       return NULL;
     };
diff --git a/src/microhttpd/connection_https.c 
b/src/microhttpd/connection_https.c
index fe197f1d..9b441a9a 100644
--- a/src/microhttpd/connection_https.c
+++ b/src/microhttpd/connection_https.c
@@ -132,7 +132,7 @@ MHD_tls_connection_handle_write (struct MHD_Connection 
*connection)
 static int
 MHD_tls_connection_handle_idle (struct MHD_Connection *connection)
 {
-  unsigned int timeout;
+  time_t timeout;
 
 #if DEBUG_STATES
   MHD_DLOG (connection->daemon,
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 8a9df765..b92d5534 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -1803,7 +1803,7 @@ thread_main_handle_connection (void *data)
   while ( (! daemon->shutdown) &&
          (MHD_CONNECTION_CLOSED != con->state) )
     {
-      const unsigned int timeout = daemon->connection_timeout;
+      const time_t timeout = daemon->connection_timeout;
 #ifdef UPGRADE_SUPPORT
       struct MHD_UpgradeResponseHandle * const urh = con->urh;
 #else  /* ! UPGRADE_SUPPORT */
@@ -3276,7 +3276,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
       if (0 != pos->connection_timeout)
        {
          if ( (! have_timeout) ||
-              (earliest_deadline > pos->last_activity + 
pos->connection_timeout) )
+              (earliest_deadline - pos->last_activity > 
pos->connection_timeout) )
            earliest_deadline = pos->last_activity + pos->connection_timeout;
          have_timeout = true;
        }
@@ -3287,7 +3287,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
        (0 != pos->connection_timeout) )
     {
       if ( (! have_timeout) ||
-          (earliest_deadline > pos->last_activity + pos->connection_timeout) )
+          (earliest_deadline - pos->connection_timeout > pos->last_activity) )
        earliest_deadline = pos->last_activity + pos->connection_timeout;
       have_timeout = true;
     }
@@ -4766,6 +4766,7 @@ parse_options_va (struct MHD_Daemon *daemon,
   enum MHD_OPTION opt;
   struct MHD_OptionItem *oa;
   unsigned int i;
+  unsigned int uv;
 #ifdef HTTPS_SUPPORT
   int ret;
   const char *pstr;
@@ -4788,8 +4789,18 @@ parse_options_va (struct MHD_Daemon *daemon,
                                              unsigned int);
           break;
         case MHD_OPTION_CONNECTION_TIMEOUT:
-          daemon->connection_timeout = va_arg (ap,
-                                               unsigned int);
+          uv = va_arg (ap,
+                       unsigned int);
+          if (TIME_T_MAX < uv)
+            {
+#ifdef HAVE_MESSAGES
+              MHD_DLOG (daemon,
+                        _("Warning: Too large timeout value, ignored.\n"));
+#endif
+              daemon->connection_timeout = 0;
+            }
+          else
+            daemon->connection_timeout = (time_t)uv;
           break;
         case MHD_OPTION_NOTIFY_COMPLETED:
           daemon->notify_completed = va_arg (ap,
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 1b9df892..9ced47c1 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -789,7 +789,12 @@ struct MHD_Connection
    * After how many seconds of inactivity should
    * this connection time out?  Zero for no timeout.
    */
-  unsigned int connection_timeout;
+  time_t connection_timeout;
+
+  /**
+   * Special member to be returned by #MHD_get_connection_info()
+   */
+  unsigned int connection_timeout_dummy;
 
   /**
    * Did we ever call the "default_handler" on this connection?  (this
@@ -1517,7 +1522,7 @@ struct MHD_Daemon
    * After how many seconds of inactivity should
    * connections time out?  Zero for no timeout.
    */
-  unsigned int connection_timeout;
+  time_t connection_timeout;
 
   /**
    * Maximum number of connections per IP, or 0 for

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]