gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (d5d03f11 -> 9da5831c


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (d5d03f11 -> 9da5831c)
Date: Tue, 21 May 2019 21:29:04 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from d5d03f11 ChangeLog update
     new edfdbbf7 Fixed doxygen comments, Fixed spelling in comments
     new c011158f Avoid dropping 'const' qualifier in macros
     new 8254bfcd Removed unused macro
     new 93d614ea Fixed compiler warning
     new 240604a3 MHD_start_daemon(): fixed port detection on some platforms, 
avoid re-use variable names.
     new c593fa6b Check TLS strings lengths
     new 93ce7acc Removed extra ';'
     new ff0eb14d MHD_set_connection_value_n_nocheck_() mark as static function
     new c835a233 MHD_start_daemon(): report if TCP_FASTOPEN is used on 
supported platform
     new 9da5831c ChangeLog updated

The 10 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ChangeLog                       |  7 ++++
 src/include/microhttpd.h        |  9 ++---
 src/include/microhttpd2.h       |  4 +-
 src/lib/daemon_start.c          |  8 ++--
 src/microhttpd/connection.c     |  3 +-
 src/microhttpd/daemon.c         | 88 ++++++++++++++++++++++++++++++++---------
 src/microhttpd/digestauth.c     | 14 ++++---
 src/microhttpd/mhd_bithelpers.h | 24 +++++------
 src/microhttpd/sha256.c         |  9 +----
 src/microhttpd/sha256.h         |  2 +-
 10 files changed, 111 insertions(+), 57 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d387b390..add27bfe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue May 21 22:12:43 MSK 2019
+       Fixed doxygen comments,
+       Avoid dropping 'const' qualifier in macros,
+       Fixed some compiler warnings,
+       Properly support automatic port detections on some platforms,
+       Added checks for too long TLS parameters strings. -EG
+
 Tue May 21 17:52:48 MSK 2019
        Spelling fixes. -EG
 
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index a492071a..117062e8 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -1187,9 +1187,9 @@ typedef void
  * @param cls closure
  * @param connection the HTTPS connection
  * @param username the user name claimed by the other side
- * @param psk[out] to be set to the pre-shared-key; should be allocated with 
malloc(),
+ * @param[out] psk to be set to the pre-shared-key; should be allocated with 
malloc(),
  *                 will be freed by MHD
- * @param psk_size[out] to be set to the number of bytes in @a psk
+ * @param[out] psk_size to be set to the number of bytes in @a psk
  * @return 0 on success, -1 on errors
  */
 typedef int
@@ -2654,7 +2654,6 @@ MHD_lookup_connection_value (struct MHD_Connection 
*connection,
  * @param[out] value_size_ptr the pointer variable, which will set to found 
value,
  *                            will not be updated if key not found,
  *                            could be NULL
- * @param key_size the length of @a key in bytes
  * @return #MHD_YES if key is found,
  *         #MHD_NO otherwise.
  * @ingroup request
@@ -2664,8 +2663,8 @@ MHD_lookup_connection_value_n (struct MHD_Connection 
*connection,
                                enum MHD_ValueKind kind,
                                const char *key,
                                size_t key_size,
-                               const char **value,
-                               size_t *value_size);
+                               const char **value_ptr,
+                               size_t *value_size_ptr);
 
 
 /**
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
index 54120570..710115d1 100644
--- a/src/include/microhttpd2.h
+++ b/src/include/microhttpd2.h
@@ -2187,9 +2187,9 @@ MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon,
  * @param cls closure
  * @param connection the HTTPS connection
  * @param username the user name claimed by the other side
- * @param psk[out] to be set to the pre-shared-key; should be allocated with 
malloc(),
+ * @param[out] psk to be set to the pre-shared-key; should be allocated with 
malloc(),
  *                 will be freed by MHD
- * @param psk_size[out] to be set to the number of bytes in @a psk
+ * @param[out] psk_size to be set to the number of bytes in @a psk
  * @return 0 on success, -1 on errors 
  */
 typedef int
diff --git a/src/lib/daemon_start.c b/src/lib/daemon_start.c
index 2d44fe51..8e2c9fb5 100644
--- a/src/lib/daemon_start.c
+++ b/src/lib/daemon_start.c
@@ -35,7 +35,7 @@
  * Set listen socket options to allow port rebinding (or not)
  * depending on how MHD was configured.
  *
- * @param daemon[in,out] the daemon with the listen socket to configure
+ * @param[in,out] daemon the daemon with the listen socket to configure
  * @return #MHD_SC_OK on success (or non-fatal errors)
  */
 static enum MHD_StatusCode
@@ -148,7 +148,7 @@ configure_listen_reuse (struct MHD_Daemon *daemon)
 /**
  * Open, configure and bind the listen socket (if required).
  *
- * @param daemon[in,out] daemon to open the socket for
+ * @param[in,out] daemon daemon to open the socket for
  * @return #MHD_SC_OK on success
  */
 static enum MHD_StatusCode
@@ -413,7 +413,7 @@ open_listen_socket (struct MHD_Daemon *daemon)
  * a listen socket or if the port was 0 and the OS picked
  * a free one).
  *
- * @param daemon[in,out] daemon to obtain the port number for
+ * @param[in,out] daemon daemon to obtain the port number for
  */
 static void
 get_listen_port_number (struct MHD_Daemon *daemon)
@@ -659,7 +659,7 @@ MHD_polling_thread (void *cls)
 /**
  * Setup the thread pool (if needed).
  *
- * @param daemon[in,out] daemon to setup thread pool for
+ * @param[in,out] daemon daemon to setup thread pool for
  * @return #MHD_SC_OK on success
  */
 static enum MHD_StatusCode
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index b73e6d5a..5c874d99 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -779,7 +779,7 @@ MHD_get_connection_values_n (struct MHD_Connection 
*connection,
  *         #MHD_YES on success
  * @ingroup request
  */
-int
+static int
 MHD_set_connection_value_n_nocheck_ (struct MHD_Connection *connection,
                                      enum MHD_ValueKind kind,
                                      const char *key,
@@ -949,7 +949,6 @@ MHD_lookup_connection_value (struct MHD_Connection 
*connection,
  * @param[out] value_size_ptr the pointer variable, which will set to found 
value,
  *                            will not be updated if key not found,
  *                            could be NULL
- * @param key_size the length of @a key in bytes
  * @return #MHD_YES if key is found,
  *         #MHD_NO otherwise.
  * @ingroup request
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index af137a80..b2185b4c 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -517,8 +517,18 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
 #endif
   if (NULL != daemon->https_mem_trust)
     {
+      size_t paramlen;
+      paramlen = strlen (daemon->https_mem_trust);
+      if (UINT_MAX < paramlen)
+        {
+#ifdef HAVE_MESSAGES
+          MHD_DLOG(daemon,
+                   "Too long trust certificate\n");
+#endif
+          return -1;
+        }
       cert.data = (unsigned char *) daemon->https_mem_trust;
-      cert.size = strlen (daemon->https_mem_trust);
+      cert.size = (unsigned int) paramlen;
       if (gnutls_certificate_set_x509_trust_mem (daemon->x509_cred,
                                                  &cert,
                                                 GNUTLS_X509_FMT_PEM) < 0)
@@ -540,10 +550,24 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
   if ( (NULL != daemon->https_mem_cert) &&
        (NULL != daemon->https_mem_key) )
     {
+      size_t param1len;
+      size_t param2len;
+
+      param1len = strlen (daemon->https_mem_key);
+      param2len = strlen (daemon->https_mem_cert);
+      if ( (UINT_MAX < param1len) ||
+           (UINT_MAX < param2len) )
+        {
+#ifdef HAVE_MESSAGES
+          MHD_DLOG(daemon,
+                   "Too long key or certificate\n");
+#endif
+          return -1;
+        }
       key.data = (unsigned char *) daemon->https_mem_key;
-      key.size = strlen (daemon->https_mem_key);
+      key.size = (unsigned int)param1len;
       cert.data = (unsigned char *) daemon->https_mem_cert;
-      cert.size = strlen (daemon->https_mem_cert);
+      cert.size = (unsigned int)param2len;
 
       if (NULL != daemon->https_key_password) {
 #if GNUTLS_VERSION_NUMBER >= 0x030111
@@ -1197,7 +1221,7 @@ call_handlers (struct MHD_Connection *con,
    * connections are processed individually. */
   /* Note: no need to check for read buffer availability for
    * TLS read-ready connection in 'read info' state as connection
-   * without space in read buffer will be market as 'info block'. */
+   * without space in read buffer will be marked as 'info block'. */
   if ( (! con->daemon->data_already_pending) &&
        (0 == (con->daemon->options & MHD_USE_THREAD_PER_CONNECTION)) )
     {
@@ -2177,7 +2201,7 @@ MHD_tls_push_func_(gnutls_transport_ptr_t trnsp,
  *
  * @param session the session to lookup PSK for
  * @param username username to lookup PSK for
- * @param key[out] where to write PSK
+ * @param[out] key where to write PSK
  * @return 0 on success, -1 on error
  */
 static int
@@ -2224,7 +2248,16 @@ psk_gnutls_adapter (gnutls_session_t session,
       free (app_psk);
       return -1;
     }
-  key->size = app_psk_size;
+  if (UINT_MAX < app_psk_size)
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _("PSK authentication failed: PSK too long\n"));
+#endif
+      free (app_psk);
+      return -1;
+    }
+  key->size = (unsigned int)app_psk_size;
   memcpy (key->data,
          app_psk,
          app_psk_size);
@@ -5042,6 +5075,7 @@ parse_options_va (struct MHD_Daemon *daemon,
           if (0 != (daemon->options & MHD_USE_TLS))
             {
               gnutls_datum_t dhpar;
+              size_t pstr_len;
 
               if (gnutls_dh_params_init (&daemon->https_mem_dhparams) < 0)
                 {
@@ -5052,7 +5086,16 @@ parse_options_va (struct MHD_Daemon *daemon,
                   return MHD_NO;
                 }
               dhpar.data = (unsigned char *) pstr;
-              dhpar.size = strlen (pstr);
+              pstr_len = strlen (pstr);
+              if (UINT_MAX < pstr_len)
+                {
+#ifdef HAVE_MESSAGES
+                  MHD_DLOG (daemon,
+                            _("Diffie-Hellman parameters string too long\n"));
+#endif
+                  return MHD_NO;
+                }
+              dhpar.size = (unsigned int) pstr_len;
               if (gnutls_dh_params_import_pkcs3 (daemon->https_mem_dhparams,
                                                  &dhpar,
                                                  GNUTLS_X509_FMT_PEM) < 0)
@@ -5167,12 +5210,18 @@ parse_options_va (struct MHD_Daemon *daemon,
                                               size_t);
           break;
 #endif
-#ifdef TCP_FASTOPEN
         case MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE:
+#ifdef TCP_FASTOPEN
           daemon->fastopen_queue_size = va_arg (ap,
                                                 unsigned int);
           break;
-#endif
+#else  /* ! TCP_FASTOPEN */
+#ifdef HAVE_MESSAGES
+          MHD_DLOG (daemon,
+                    _("TCP fastopen is not supported on this platform\n"));
+          return MHD_NO;
+#endif /* HAVE_MESSAGES */
+#endif /* ! TCP_FASTOPEN */
        case MHD_OPTION_LISTENING_ADDRESS_REUSE:
          daemon->listening_address_reuse = va_arg (ap,
                                                     unsigned int) ? 1 : -1;
@@ -5182,7 +5231,7 @@ parse_options_va (struct MHD_Daemon *daemon,
                                                 unsigned int);
          break;
        case MHD_OPTION_STRICT_FOR_CLIENT:
-          daemon->strict_for_client = va_arg (ap, int);;
+          daemon->strict_for_client = va_arg (ap, int);
 #ifdef HAVE_MESSAGES
          if ( (0 != (daemon->options & MHD_USE_PEDANTIC_CHECKS)) &&
               (1 != daemon->strict_for_client) )
@@ -6029,14 +6078,17 @@ MHD_start_daemon_va (unsigned int flags,
   if ( (0 == daemon->port) &&
        (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) )
     { /* Get port number. */
-      struct sockaddr_storage servaddr;
+      struct sockaddr_storage bindaddr;
 
-      memset (&servaddr,
+      memset (&bindaddr,
               0,
               sizeof (struct sockaddr_storage));
-      addrlen = sizeof (servaddr);
+      addrlen = sizeof (struct sockaddr_storage);
+#ifdef HAVE_SOCKADDR_IN_SIN_LEN
+      bindaddr.sin_len = addrlen;
+#endif
       if (0 != getsockname (listen_fd,
-                            (struct sockaddr *) &servaddr,
+                            (struct sockaddr *) &bindaddr,
                             &addrlen))
       {
 #ifdef HAVE_MESSAGES
@@ -6046,7 +6098,7 @@ MHD_start_daemon_va (unsigned int flags,
 #endif /* HAVE_MESSAGES */
         }
 #ifdef MHD_POSIX_SOCKETS
-      else if (sizeof (servaddr) < addrlen)
+      else if (sizeof (bindaddr) < addrlen)
         {
           /* should be impossible with `struct sockaddr_storage` */
 #ifdef HAVE_MESSAGES
@@ -6057,11 +6109,11 @@ MHD_start_daemon_va (unsigned int flags,
 #endif /* MHD_POSIX_SOCKETS */
       else
         {
-          switch (servaddr.ss_family)
+          switch (bindaddr.ss_family)
           {
           case AF_INET:
             {
-              struct sockaddr_in *s4 = (struct sockaddr_in *) &servaddr;
+              struct sockaddr_in *s4 = (struct sockaddr_in *) &bindaddr;
 
               daemon->port = ntohs (s4->sin_port);
               break;
@@ -6069,7 +6121,7 @@ MHD_start_daemon_va (unsigned int flags,
 #ifdef HAVE_INET6
           case AF_INET6:
             {
-              struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &servaddr;
+              struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &bindaddr;
 
               daemon->port = ntohs(s6->sin6_port);
               mhd_assert (0 != (*pflags & MHD_USE_IPv6));
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index ae5034b8..c2783dd7 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -156,7 +156,7 @@ struct DigestAlgorithm
    * Compute final @a digest.
    *
    * @param ctx context to use
-   * @param digest[out] where to write the result,
+   * @param[out] digest where to write the result,
    *        must be @e digest_length bytes long
    */
   void
@@ -198,7 +198,7 @@ cvthex (const unsigned char *bin,
  * @param alg The hash algorithm used, can be "md5" or "md5-sess"
  *            or "sha-256" or "sha-256-sess"
  *    Note that the rest of the code does not support the the "-sess" variants!
- * @param da[in,out] digest implementation, must match @a alg; the
+ * @param[in,out] da digest implementation, must match @a alg; the
  *          da->sessionkey will be initialized to the digest in HEX
  * @param digest An `unsigned char *' pointer to the binary MD5 sum
  *                     for the precalculated hash value 
"username:realm:password"
@@ -263,7 +263,7 @@ digest_calc_ha1_from_digest (const char *alg,
  * @param password A `char *' pointer to the password value
  * @param nonce A `char *' pointer to the nonce value
  * @param cnonce A `char *' pointer to the cnonce value
- * @param da[in,out] digest algorithm to use, and where to write
+ * @param[in,out] da digest algorithm to use, and where to write
  *         the sessionkey to
  */
 static void
@@ -317,7 +317,7 @@ digest_calc_ha1_from_user (const char *alg,
  * @param method method from request
  * @param uri requested URL
  * @param hentity H(entity body) if qop="auth-int"
- * @param da[in,out] digest algorithm to use, also
+ * @param[in,out] da digest algorithm to use, also
  *        we write da->sessionkey (set to response request-digest or 
response-digest)
  */
 static void
@@ -835,7 +835,7 @@ check_argument_match (struct MHD_Connection *connection,
  * Authenticates the authorization header sent by the client
  *
  * @param connection The MHD connection structure
- * @param da[in,out] digest algorithm to use for checking (written to as
+ * @param[in,out] da digest algorithm to use for checking (written to as
  *         part of the calculations, but the values left in the struct
  *         are not actually expected to be useful for the caller)
  * @param realm The realm presented to the client
@@ -1188,6 +1188,7 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
   } skey;                                         \
   struct DigestAlgorithm da;                      \
                                                   \
+  do {                                            \
   switch (algo) {                                 \
   case MHD_DIGEST_ALG_MD5:                        \
     da.digest_size = MD5_DIGEST_SIZE;             \
@@ -1209,7 +1210,8 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
     da.update = &sha256_update;                         \
     da.digest = &sha256_finish;                         \
     break;                                              \
-  }
+  }                                                     \
+  } while(0)
 
 
 
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h
index caa24846..ac2a13ce 100644
--- a/src/microhttpd/mhd_bithelpers.h
+++ b/src/microhttpd/mhd_bithelpers.h
@@ -136,17 +136,17 @@
  */
 #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
 #define _MHD_GET_32BIT_LE(addr)             \
-        (*(uint32_t*)(addr))
+        (*(const uint32_t*)(addr))
 #elif _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
 #define _MHD_GET_32BIT_LE(addr)             \
-        _MHD_BYTES_SWAP32(*(uint32_t*)(addr))
+        _MHD_BYTES_SWAP32(*(const uint32_t*)(addr))
 #else  /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
 /* Endianess was not detected or non-standard like PDP-endian */
 #define _MHD_GET_32BIT_LE(addr)                       \
-        ( ( (uint32_t)(((uint8_t*)addr)[0]))        | \
-          (((uint32_t)(((uint8_t*)addr)[1])) << 8)  | \
-          (((uint32_t)(((uint8_t*)addr)[2])) << 16) | \
-          (((uint32_t)(((uint8_t*)addr)[3])) << 24) )
+        ( ( (uint32_t)(((const uint8_t*)addr)[0]))        | \
+          (((uint32_t)(((const uint8_t*)addr)[1])) << 8)  | \
+          (((uint32_t)(((const uint8_t*)addr)[2])) << 16) | \
+          (((uint32_t)(((const uint8_t*)addr)[3])) << 24) )
 #endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
 
 
@@ -200,17 +200,17 @@
  */
 #if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
 #define _MHD_GET_32BIT_BE(addr)             \
-        (*(uint32_t*)(addr))
+        (*(const uint32_t*)(addr))
 #elif _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
 #define _MHD_GET_32BIT_BE(addr)             \
-        _MHD_BYTES_SWAP32(*(uint32_t*)(addr))
+        _MHD_BYTES_SWAP32(*(const uint32_t*)(addr))
 #else  /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
 /* Endianess was not detected or non-standard like PDP-endian */
 #define _MHD_GET_32BIT_BE(addr)                       \
-        ( (((uint32_t)(((uint8_t*)addr)[0])) << 24) | \
-          (((uint32_t)(((uint8_t*)addr)[1])) << 16) | \
-          (((uint32_t)(((uint8_t*)addr)[2])) << 8)  | \
-          ((uint32_t) (((uint8_t*)addr)[3])) )
+        ( (((uint32_t)(((const uint8_t*)addr)[0])) << 24) | \
+          (((uint32_t)(((const uint8_t*)addr)[1])) << 16) | \
+          (((uint32_t)(((const uint8_t*)addr)[2])) << 8)  | \
+          ((uint32_t) (((const uint8_t*)addr)[3])) )
 #endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
 
 
diff --git a/src/microhttpd/sha256.c b/src/microhttpd/sha256.c
index 801f920b..244b674a 100644
--- a/src/microhttpd/sha256.c
+++ b/src/microhttpd/sha256.c
@@ -68,11 +68,6 @@ sha256_init (void *ctx_)
  */
 #define SHA256_BYTES_IN_WORD 4
 
-/**
- * Length of data block in words
- */
-#define SHA256_BLOCK_LENGTH (SHA256_BLOCK_SIZE / SHA256_BYTES_IN_WORD)
-
 /**
  * Base of SHA-256 transformation.
  * Gets full 64 bytes block of data and updates hash values;
@@ -135,7 +130,7 @@ sha256_transform (uint32_t H[_SHA256_DIGEST_LENGTH],
      Input data must be read in big-endian bytes order,
      see FIPS PUB 180-4 paragraph 3.1.2. */
 #define GET_W_FROM_DATA(buf,t) \
-        _MHD_GET_32BIT_BE(((uint8_t*)(buf)) + (t) * SHA256_BYTES_IN_WORD)
+        _MHD_GET_32BIT_BE(((const uint8_t*)(buf)) + (t) * SHA256_BYTES_IN_WORD)
 
   /* During first 16 steps, before making any calculations on each step,
      the W element is read from input data buffer as big-endian value and
@@ -300,7 +295,7 @@ sha256_update (void *ctx_,
  * Finalise SHA256 calculation, return digest.
  *
  * @param ctx_ must be a `struct sha256_ctx *`
- * @param digest[out] set to the hash, must be #SHA256_DIGEST_SIZE bytes
+ * @param[out] digest set to the hash, must be #SHA256_DIGEST_SIZE bytes
  */
 void
 sha256_finish (void *ctx_,
diff --git a/src/microhttpd/sha256.h b/src/microhttpd/sha256.h
index 7926e7ea..03700080 100644
--- a/src/microhttpd/sha256.h
+++ b/src/microhttpd/sha256.h
@@ -84,7 +84,7 @@ sha256_update (void *ctx_,
  * Finalise SHA256 calculation, return digest.
  *
  * @param ctx_ must be a `struct sha256_ctx *`
- * @param digest[out] set to the hash, must be #SHA256_DIGEST_SIZE bytes
+ * @param[out] digest set to the hash, must be #SHA256_DIGEST_SIZE bytes
  */
 void
 sha256_finish (void *ctx_,

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



reply via email to

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