gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (c02d8f03 -> 218694a4


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (c02d8f03 -> 218694a4)
Date: Wed, 05 Apr 2017 12:00:18 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from c02d8f03 ChangeLog: added missing entries.
     new e3014350 Fixed some compiler warnings
     new 6ac4608c digestauth.c: fixed snprintf() error detection, used calloc 
instead of malloc (security).
     new 218694a4 Converted many 'strlen()' from run-time to compile-time 
processing

The 3 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                      |  5 +++++
 src/microhttpd/basicauth.c     |  4 ++--
 src/microhttpd/connection.c    | 28 ++++++++++++++--------------
 src/microhttpd/daemon.c        |  8 ++++----
 src/microhttpd/digestauth.c    | 12 ++++++------
 src/microhttpd/internal.h      |  4 ++++
 src/microhttpd/postprocessor.c | 22 +++++++++++-----------
 src/microhttpd/response.c      |  4 ++--
 8 files changed, 48 insertions(+), 39 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 643dd071..d9f9b5be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Apr 05 12:53:26 MSK 2017
+       Fixed some compiler warnings.
+       Fixed error snprintf() errors detection in digestauth.c.
+       Converted many run-time 'strlen()' to compile-time calculations. -EG
+
 Sun Mar 26 13:49:01 MSK 2017
        Internal refactoring for simplification and unification.
        Minor optimizations and minor fixes.
diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c
index b25e54fa..b2c4180d 100644
--- a/src/microhttpd/basicauth.c
+++ b/src/microhttpd/basicauth.c
@@ -57,9 +57,9 @@ MHD_basic_auth_get_username_password (struct MHD_Connection 
*connection,
                                                       
MHD_HTTP_HEADER_AUTHORIZATION))) ||
        (0 != strncmp (header,
                       _BASIC_BASE,
-                      strlen (_BASIC_BASE))) )
+                      MHD_STATICSTR_LEN_ (_BASIC_BASE))) )
     return NULL;
-  header += strlen (_BASIC_BASE);
+  header += MHD_STATICSTR_LEN_ (_BASIC_BASE);
   if (NULL == (decode = BASE64Decode (header)))
     {
 #ifdef HAVE_MESSAGES
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 29be44f1..95835d59 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -489,7 +489,7 @@ need_100_continue (struct MHD_Connection *connection)
           (MHD_str_equal_caseless_(expect,
                                     "100-continue")) &&
           (connection->continue_message_write_offset <
-           strlen (HTTP_100_CONTINUE)) );
+           MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE)) );
 }
 
 
@@ -1201,11 +1201,11 @@ build_header_response (struct MHD_Connection 
*connection)
     }
 
   if (must_add_close)
-    size += strlen ("Connection: close\r\n");
+    size += MHD_STATICSTR_LEN_ ("Connection: close\r\n");
   if (must_add_keep_alive)
-    size += strlen ("Connection: Keep-Alive\r\n");
+    size += MHD_MACROSTR_LEN_ ("Connection: Keep-Alive\r\n");
   if (must_add_chunked_encoding)
-    size += strlen ("Transfer-Encoding: chunked\r\n");
+    size += MHD_MACROSTR_LEN_ ("Transfer-Encoding: chunked\r\n");
   if (must_add_content_length)
     size += content_length_len;
   EXTRA_CHECK (! (must_add_close && must_add_keep_alive) );
@@ -1241,24 +1241,24 @@ build_header_response (struct MHD_Connection 
*connection)
       /* we must add the 'Connection: close' header */
       memcpy (&data[off],
               "Connection: close\r\n",
-             strlen ("Connection: close\r\n"));
-      off += strlen ("Connection: close\r\n");
+              MHD_STATICSTR_LEN_ ("Connection: close\r\n"));
+      off += MHD_STATICSTR_LEN_ ("Connection: close\r\n");
     }
   if (must_add_keep_alive)
     {
       /* we must add the 'Connection: Keep-Alive' header */
       memcpy (&data[off],
               "Connection: Keep-Alive\r\n",
-             strlen ("Connection: Keep-Alive\r\n"));
-      off += strlen ("Connection: Keep-Alive\r\n");
+              MHD_STATICSTR_LEN_ ("Connection: Keep-Alive\r\n"));
+      off += MHD_STATICSTR_LEN_ ("Connection: Keep-Alive\r\n");
     }
   if (must_add_chunked_encoding)
     {
       /* we must add the 'Transfer-Encoding: chunked' header */
       memcpy (&data[off],
               "Transfer-Encoding: chunked\r\n",
-             strlen ("Transfer-Encoding: chunked\r\n"));
-      off += strlen ("Transfer-Encoding: chunked\r\n");
+              MHD_STATICSTR_LEN_ ("Transfer-Encoding: chunked\r\n"));
+      off += MHD_STATICSTR_LEN_ ("Transfer-Encoding: chunked\r\n");
     }
   if (must_add_content_length)
     {
@@ -1743,7 +1743,7 @@ parse_initial_message_line (struct MHD_Connection 
*connection,
   while ( (' ' == uri[0]) &&
           ( (size_t)(uri - line) < line_len) )
     uri++;
-  if (uri - line == line_len)
+  if ((size_t)(uri - line) == line_len)
     {
       curi = "";
       uri = NULL;
@@ -2343,7 +2343,7 @@ parse_connection_headers (struct MHD_Connection 
*connection)
 #endif
       EXTRA_CHECK (NULL == connection->response);
       response =
-        MHD_create_response_from_buffer (strlen (REQUEST_LACKS_HOST),
+        MHD_create_response_from_buffer (MHD_STATICSTR_LEN_ 
(REQUEST_LACKS_HOST),
                                         REQUEST_LACKS_HOST,
                                         MHD_RESPMEM_PERSISTENT);
       MHD_queue_response (connection,
@@ -2535,7 +2535,7 @@ MHD_connection_handle_write (struct MHD_Connection 
*connection)
           ret = connection->send_cls (connection,
                                       &HTTP_100_CONTINUE
                                       
[connection->continue_message_write_offset],
-                                      strlen (HTTP_100_CONTINUE) -
+                                      MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE) -
                                       
connection->continue_message_write_offset);
           if (ret < 0)
             {
@@ -2912,7 +2912,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
           continue;
         case MHD_CONNECTION_CONTINUE_SENDING:
           if (connection->continue_message_write_offset ==
-              strlen (HTTP_100_CONTINUE))
+              MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE))
             {
               connection->state = MHD_CONNECTION_CONTINUE_SENT;
               if (MHD_NO != socket_flush_possible (connection))
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index a4a9a2b8..c2bd59f8 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2169,7 +2169,7 @@ recv_param_adapter (struct MHD_Connection *connection,
       if (MHD_SCKT_ERR_IS_EAGAIN_ (MHD_socket_get_error_ ()))
         connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
     }
-  else if (i > ret)
+  else if (i > (size_t)ret)
     connection->epoll_state &= ~MHD_EPOLL_STATE_READ_READY;
 #endif
   return ret;
@@ -2249,7 +2249,7 @@ send_param_adapter (struct MHD_Connection *connection,
       if (0 < ret)
         {
           /* write successful */
-          if (left > ret)
+          if (left > (uint64_t)ret)
             connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
           return ret;
         }
@@ -2286,7 +2286,7 @@ send_param_adapter (struct MHD_Connection *connection,
       if (MHD_SCKT_ERR_IS_EAGAIN_(err))
         connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
     }
-  else if (i > ret)
+  else if (i > (size_t)ret)
     connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
 #endif
   /* Handle broken kernel / libc, returning -1 but not setting errno;
@@ -3300,7 +3300,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
   else
     {
       const time_t second_left = earliest_deadline - now;
-      if (second_left > ULLONG_MAX / 1000)
+      if (second_left > ULLONG_MAX / 1000) /* Ignore compiler warning: 
'second_left' is always positive. */
         *timeout = ULLONG_MAX;
       else
         *timeout = 1000LL * second_left;
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 638c0825..8b219296 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -477,9 +477,9 @@ MHD_digest_auth_get_username(struct MHD_Connection 
*connection)
     return NULL;
   if (0 != strncmp (header,
                     _BASE,
-                    strlen (_BASE)))
+                    MHD_STATICSTR_LEN_ (_BASE)))
     return NULL;
-  header += strlen (_BASE);
+  header += MHD_STATICSTR_LEN_ (_BASE);
   if (0 == (len = lookup_sub_value (user,
                                    sizeof (user),
                                    header,
@@ -699,9 +699,9 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
     return MHD_NO;
   if (0 != strncmp (header,
                     _BASE,
-                    strlen(_BASE)))
+                    MHD_STATICSTR_LEN_(_BASE)))
     return MHD_NO;
-  header += strlen (_BASE);
+  header += MHD_STATICSTR_LEN_ (_BASE);
   left = strlen (header);
 
   {
@@ -950,7 +950,7 @@ MHD_queue_auth_fail_response (struct MHD_Connection 
*connection,
                              int signal_stale)
 {
   int ret;
-  size_t hlen;
+  int hlen;
   char nonce[NONCE_STD_LEN + 1];
 
   /* Generating the server nonce */
@@ -986,7 +986,7 @@ MHD_queue_auth_fail_response (struct MHD_Connection 
*connection,
     {
       char *header;
 
-      header = malloc (hlen + 1);
+      header = MHD_calloc_ (1, hlen + 1);
       if (NULL == header)
         {
 #ifdef HAVE_MESSAGES
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 52bd8520..1b9df892 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -117,6 +117,10 @@ extern void *mhd_panic_cls;
 #define BUILTIN_NOT_REACHED
 #endif
 
+/**
+ * Determine length of static string / macro strings at compile time.
+ */
+#define MHD_STATICSTR_LEN_(macro) (sizeof(macro)/sizeof(char) - 1)
 
 /**
  * State of the socket with respect to epoll (bitmask).
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index cf3c31ec..208686bb 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -296,19 +296,19 @@ MHD_create_post_processor (struct MHD_Connection 
*connection,
   boundary = NULL;
   if (! MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
                                    encoding,
-                                   strlen 
(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
+                                   MHD_STATICSTR_LEN_ 
(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
     {
       if (! MHD_str_equal_caseless_n_ 
(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
                                        encoding,
-                                       strlen 
(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
+                                       MHD_STATICSTR_LEN_ 
(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
         return NULL;
       boundary =
-        &encoding[strlen (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)];
+        &encoding[MHD_STATICSTR_LEN_ 
(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)];
       /* Q: should this be "strcasestr"? */
       boundary = strstr (boundary, "boundary=");
       if (NULL == boundary)
        return NULL; /* failed to determine boundary */
-      boundary += strlen ("boundary=");
+      boundary += MHD_STATICSTR_LEN_ ("boundary=");
       blen = strlen (boundary);
       if ( (blen == 0) ||
            (blen * 2 + 2 > buffer_size) )
@@ -710,12 +710,12 @@ process_multipart_headers (struct MHD_PostProcessor *pp,
   buf[newline] = '\0';
   if (MHD_str_equal_caseless_n_ ("Content-disposition: ",
                                  buf,
-                                 strlen ("Content-disposition: ")))
+                                 MHD_STATICSTR_LEN_ ("Content-disposition: ")))
     {
-      try_get_value (&buf[strlen ("Content-disposition: ")],
+      try_get_value (&buf[MHD_STATICSTR_LEN_ ("Content-disposition: ")],
                      "name",
                      &pp->content_name);
-      try_get_value (&buf[strlen ("Content-disposition: ")],
+      try_get_value (&buf[MHD_STATICSTR_LEN_ ("Content-disposition: ")],
                      "filename",
                      &pp->content_filename);
     }
@@ -1043,7 +1043,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
           if ( (NULL != pp->content_type) &&
                (MHD_str_equal_caseless_n_ (pp->content_type,
                                            "multipart/mixed",
-                                           strlen ("multipart/mixed"))))
+                                           MHD_STATICSTR_LEN_ 
("multipart/mixed"))))
             {
               pp->nested_boundary = strstr (pp->content_type,
                                             "boundary=");
@@ -1053,7 +1053,7 @@ post_process_multipart (struct MHD_PostProcessor *pp,
                   return MHD_NO;
                 }
               pp->nested_boundary =
-                strdup (&pp->nested_boundary[strlen ("boundary=")]);
+                strdup (&pp->nested_boundary[MHD_STATICSTR_LEN_ 
("boundary=")]);
               if (NULL == pp->nested_boundary)
                 {
                   /* out of memory */
@@ -1221,13 +1221,13 @@ MHD_post_process (struct MHD_PostProcessor *pp,
     return MHD_NO;
   if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
                                  pp->encoding,
-                                 
strlen(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
+                                 
MHD_STATICSTR_LEN_(MHD_HTTP_POST_ENCODING_FORM_URLENCODED)))
     return post_process_urlencoded (pp,
                                     post_data,
                                     post_data_len);
   if (MHD_str_equal_caseless_n_ (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
                                  pp->encoding,
-                                 strlen 
(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
+                                 MHD_STATICSTR_LEN_ 
(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA)))
     return post_process_multipart (pp,
                                    post_data,
                                    post_data_len);
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index e8707480..a86e58fc 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -75,8 +75,8 @@ add_response_entry (struct MHD_Response *response,
   if ( (NULL == response) ||
        (NULL == header) ||
        (NULL == content) ||
-       (0 == strlen (header)) ||
-       (0 == strlen (content)) ||
+       (0 == header[0]) ||
+       (0 == content[0]) ||
        (NULL != strchr (header, '\t')) ||
        (NULL != strchr (header, '\r')) ||
        (NULL != strchr (header, '\n')) ||

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



reply via email to

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