gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (92749423 -> 1a23dd25


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (92749423 -> 1a23dd25)
Date: Thu, 05 Oct 2017 23:16:21 +0200

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

grothoff pushed a change to branch master
in repository libmicrohttpd.

    from 92749423 update .gitignore
     new 111e08fb fix indentation, use 'true' instead of not 0
     new 1a23dd25 misc style improvements, fixing some tiny rare memory leaks 
in examples

The 2 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:
 doc/examples/largepost.c                     |  4 +-
 src/examples/chunked_example.c               | 35 +++++++++---
 src/examples/demo.c                          |  6 +-
 src/examples/https_fileserver_example.c      | 42 ++++++++------
 src/examples/post_example.c                  | 22 ++++++--
 src/microhttpd/connection.c                  |  7 ++-
 src/microhttpd/response.c                    |  8 +--
 src/microhttpd/test_shutdown_select.c        |  7 ++-
 src/microhttpd/test_upgrade.c                | 45 ++++++++-------
 src/testcurl/https/test_https_session_info.c |  4 +-
 src/testcurl/https/test_tls_extensions.c     |  4 +-
 src/testcurl/https/test_tls_options.c        |  7 ++-
 src/testcurl/https/tls_test_common.c         | 82 +++++++++++++++++-----------
 src/testcurl/https/tls_test_common.h         | 27 ++++++---
 src/testcurl/test_callback.c                 | 14 +++--
 src/testcurl/test_get_chunked.c              | 45 +++++++++++----
 16 files changed, 232 insertions(+), 127 deletions(-)

diff --git a/doc/examples/largepost.c b/doc/examples/largepost.c
index af6a48dd..8ef7c9fe 100644
--- a/doc/examples/largepost.c
+++ b/doc/examples/largepost.c
@@ -151,7 +151,9 @@ iterate_post (void *coninfo_cls,
           con_info->answercode = MHD_HTTP_FORBIDDEN;
           return MHD_YES;
         }
-
+      /* NOTE: This is technically a race with the 'fopen()' above,
+         but there is no easy fix, short of moving to open(O_EXCL)
+         instead of using fopen(). For the example, we do not care. */
       con_info->fp = fopen (filename, "ab");
       if (!con_info->fp)
         {
diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c
index a661216c..9bf73e34 100644
--- a/src/examples/chunked_example.c
+++ b/src/examples/chunked_example.c
@@ -32,6 +32,7 @@ struct ResponseContentCallbackParam
   size_t response_size;
 };
 
+
 static ssize_t
 callback (void *cls,
           uint64_t pos,
@@ -77,12 +78,14 @@ callback (void *cls,
   return size_to_copy;
 }
 
-void
-free_callback_param(void *cls)
+
+static void
+free_callback_param (void *cls)
 {
   free(cls);
 }
 
+
 static const char simple_response_text[] = "<html><head><title>Simple 
response</title></head>"
                                            "<body>Simple response 
text</body></html>";
 
@@ -93,10 +96,12 @@ ahc_echo (void *cls,
           const char *url,
           const char *method,
           const char *version,
-          const char *upload_data, size_t *upload_data_size, void **ptr)
+          const char *upload_data,
+          size_t *upload_data_size,
+          void **ptr)
 {
   static int aptr;
-  struct ResponseContentCallbackParam * callback_param;
+  struct ResponseContentCallbackParam *callback_param;
   struct MHD_Response *response;
   int ret;
   (void)cls;               /* Unused. Silent compiler warning. */
@@ -127,31 +132,47 @@ ahc_echo (void *cls,
                                                 &callback,
                                                 callback_param,
                                                 &free_callback_param);
+  if (NULL == response)
+  {
+    free (callback_param);
+    return MHD_NO;
+  }
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   MHD_destroy_response (response);
   return ret;
 }
 
+
 int
 main (int argc, char *const *argv)
 {
   struct MHD_Daemon *d;
+  int port;
 
   if (argc != 2)
     {
       printf ("%s PORT\n", argv[0]);
       return 1;
     }
+  port = atoi (argv[1]);
+  if ( (1 > port) ||
+       (port > UINT16_MAX) )
+    {
+      fprintf (stderr,
+               "Port must be a number between 1 and 65535\n");
+      return 1;
+    }
   d = MHD_start_daemon (// MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
                         MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | 
MHD_USE_ERROR_LOG,
                         // MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG 
| MHD_USE_POLL,
                        // MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL,
                        // MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
-                        atoi (argv[1]),
-                        NULL, NULL, &ahc_echo, NULL,
+                        (uint16_t) port,
+                        NULL, NULL,
+                        &ahc_echo, NULL,
                        MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
                        MHD_OPTION_END);
-  if (d == NULL)
+  if (NULL == d)
     return 1;
   (void) getc (stdin);
   MHD_stop_daemon (d);
diff --git a/src/examples/demo.c b/src/examples/demo.c
index edf38e98..0b177357 100644
--- a/src/examples/demo.c
+++ b/src/examples/demo.c
@@ -254,7 +254,7 @@ struct ResponseDataContext
  *
  * @param rdc where to store the list of files
  * @param dirname name of the directory to list
- * @return MHD_YES on success, MHD_NO on error
+ * @return #MHD_YES on success, #MHD_NO on error
  */
 static int
 list_directory (struct ResponseDataContext *rdc,
@@ -271,7 +271,7 @@ list_directory (struct ResponseDataContext *rdc,
     {
       if ('.' == de->d_name[0])
        continue;
-      if (sizeof (fullname) <= (size_t)
+      if (sizeof (fullname) <= (unsigned int)
          snprintf (fullname, sizeof (fullname),
                    "%s/%s",
                    dirname, de->d_name))
@@ -555,7 +555,7 @@ process_upload_data (void *cls,
                uc->category,
                filename);
       for (i=strlen (fn)-1;i>=0;i--)
-       if (! isprint ((int) fn[i]))
+       if (! isprint ((unsigned char) fn[i]))
          fn[i] = '_';
       uc->fd = open (fn,
                     O_CREAT | O_EXCL
diff --git a/src/examples/https_fileserver_example.c 
b/src/examples/https_fileserver_example.c
index 453ca2ff..818c8d55 100644
--- a/src/examples/https_fileserver_example.c
+++ b/src/examples/https_fileserver_example.c
@@ -191,38 +191,44 @@ int
 main (int argc, char *const *argv)
 {
   struct MHD_Daemon *TLS_daemon;
+  int port;
 
-  if (argc == 2)
+  if (argc != 2)
     {
-      /* TODO check if this is truly necessary -  disallow usage of the 
blocking /dev/random */
-      /* gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0); */
-      TLS_daemon =
-        MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
-                          MHD_USE_TLS, atoi (argv[1]), NULL, NULL, &http_ahc,
-                          NULL, MHD_OPTION_CONNECTION_TIMEOUT, 256,
-                          MHD_OPTION_HTTPS_MEM_KEY, key_pem,
-                          MHD_OPTION_HTTPS_MEM_CERT, cert_pem,
-                          MHD_OPTION_END);
+      printf ("%s PORT\n", argv[0]);
+      return 1;
     }
-  else
+  port = atoi (argv[1]);
+  if ( (1 > port) ||
+       (port > UINT16_MAX) )
     {
-      printf ("Usage: %s HTTP-PORT\n", argv[0]);
+      fprintf (stderr,
+               "Port must be a number between 1 and 65535\n");
       return 1;
     }
 
-  if (TLS_daemon == NULL)
+  /* TODO check if this is truly necessary -  disallow usage of the blocking 
/dev/random */
+  /* gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0); */
+  TLS_daemon =
+    MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
+                      MHD_USE_TLS,
+                      (uint16_t) port,
+                      NULL, NULL,
+                      &http_ahc, NULL,
+                      MHD_OPTION_CONNECTION_TIMEOUT, 256,
+                      MHD_OPTION_HTTPS_MEM_KEY, key_pem,
+                      MHD_OPTION_HTTPS_MEM_CERT, cert_pem,
+                      MHD_OPTION_END);
+  if (NULL == TLS_daemon)
     {
       fprintf (stderr, "Error: failed to start TLS_daemon\n");
       return 1;
     }
-  else
-    {
-      printf ("MHD daemon listening on port %d\n", atoi (argv[1]));
-    }
+  printf ("MHD daemon listening on port %u\n",
+          (unsigned int) port);
 
   (void) getc (stdin);
 
   MHD_stop_daemon (TLS_daemon);
-
   return 0;
 }
diff --git a/src/examples/post_example.c b/src/examples/post_example.c
index 8b92956d..6c9a3f4b 100644
--- a/src/examples/post_example.c
+++ b/src/examples/post_example.c
@@ -313,23 +313,28 @@ fill_v1_form (const void *cls,
              struct MHD_Connection *connection)
 {
   int ret;
+  size_t slen;
   char *reply;
   struct MHD_Response *response;
   (void)cls; /* Unused. Silent compiler warning. */
 
-  reply = malloc (strlen (MAIN_PAGE) + strlen (session->value_1) + 1);
+  slen = strlen (MAIN_PAGE) + strlen (session->value_1);
+  reply = malloc (slen + 1);
   if (NULL == reply)
     return MHD_NO;
   snprintf (reply,
-           strlen (MAIN_PAGE) + strlen (session->value_1) + 1,
+           slen + 1,
            MAIN_PAGE,
            session->value_1);
   /* return static form */
-  response = MHD_create_response_from_buffer (strlen (reply),
+  response = MHD_create_response_from_buffer (slen,
                                              (void *) reply,
                                              MHD_RESPMEM_MUST_FREE);
   if (NULL == response)
+  {
+    free (reply);
     return MHD_NO;
+  }
   add_session_cookie (session, response);
   MHD_add_response_header (response,
                           MHD_HTTP_HEADER_CONTENT_ENCODING,
@@ -359,22 +364,27 @@ fill_v1_v2_form (const void *cls,
   int ret;
   char *reply;
   struct MHD_Response *response;
+  size_t slen;
   (void)cls; /* Unused. Silent compiler warning. */
 
-  reply = malloc (strlen (SECOND_PAGE) + strlen (session->value_1) + strlen 
(session->value_2) + 1);
+  slen = strlen (SECOND_PAGE) + strlen (session->value_1) + strlen 
(session->value_2);
+  reply = malloc (slen + 1);
   if (NULL == reply)
     return MHD_NO;
   snprintf (reply,
-           strlen (SECOND_PAGE) + strlen (session->value_1) + strlen 
(session->value_2) + 1,
+           slen + 1,
            SECOND_PAGE,
            session->value_1,
             session->value_2);
   /* return static form */
-  response = MHD_create_response_from_buffer (strlen (reply),
+  response = MHD_create_response_from_buffer (slen,
                                              (void *) reply,
                                              MHD_RESPMEM_MUST_FREE);
   if (NULL == response)
+  {
+    free (reply);
     return MHD_NO;
+  }
   add_session_cookie (session, response);
   MHD_add_response_header (response,
                           MHD_HTTP_HEADER_CONTENT_ENCODING,
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index c33d484a..9b040418 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1070,7 +1070,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
  * Prepare the response buffer of this connection for sending.
  * Assumes that the response mutex is already held.  If the
  * transmission is complete, this function may close the socket (and
- * return MHD_NO).
+ * return #MHD_NO).
  *
  * @param connection the connection
  * @return #MHD_NO if readying the response failed
@@ -1086,6 +1086,8 @@ try_ready_chunked_body (struct MHD_Connection *connection)
   int cblen;
 
   response = connection->response;
+  if (NULL == response->crc)
+    return MHD_YES;
   if (0 == connection->write_buffer_size)
     {
       size = MHD_MIN (connection->daemon->pool_size,
@@ -3533,8 +3535,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
                 socket_start_no_buffering (connection);
               continue;
             }
-          if (NULL != connection->response->crc)
-            MHD_mutex_unlock_chk_ (&connection->response->mutex);
+          MHD_mutex_unlock_chk_ (&connection->response->mutex);
           break;
         case MHD_CONNECTION_BODY_SENT:
           if (MHD_NO == build_header_response (connection))
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index a0ecf3ea..fa1cedf4 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -316,10 +316,10 @@ MHD_create_response_from_callback (uint64_t size,
   response->data = (void *) &response[1];
   response->data_buffer_size = block_size;
   if (! MHD_mutex_init_ (&response->mutex))
-    {
-      free (response);
-      return NULL;
-    }
+  {
+    free (response);
+    return NULL;
+  }
   response->crc = crc;
   response->crfc = crfc;
   response->crc_cls = crc_cls;
diff --git a/src/microhttpd/test_shutdown_select.c 
b/src/microhttpd/test_shutdown_select.c
index e8942c0b..1e4e3d82 100644
--- a/src/microhttpd/test_shutdown_select.c
+++ b/src/microhttpd/test_shutdown_select.c
@@ -112,10 +112,11 @@ has_in_name(const char *prog_name, const char *marker)
       pos++;
     }
   if (name_pos == pos)
-    return !0;
+    return true;
   return strstr(prog_name + name_pos, marker) != NULL;
 }
 
+
 static MHD_socket
 start_socket_listen(int domain)
 {
@@ -290,7 +291,7 @@ main (int argc, char *const *argv)
 
   test_poll = has_in_name(argv[0], "_poll");
   must_ignore = has_in_name(argv[0], "_ignore");
-  if (!test_poll)
+  if (! test_poll)
     test_func = &select_thread;
   else
     {
@@ -324,7 +325,7 @@ main (int argc, char *const *argv)
       if (MHD_INVALID_SOCKET == listen_socket)
         return 99;
 
-      check_err = !0;
+      check_err = true;
       /* fprintf (stdout, "Starting select() thread...\n"); */
 #if defined(MHD_USE_POSIX_THREADS)
       if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket))
diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c
index 377e712d..4fc4051c 100644
--- a/src/microhttpd/test_upgrade.c
+++ b/src/microhttpd/test_upgrade.c
@@ -201,7 +201,8 @@ typedef struct wr_socket_strc* wr_socket;
  * Create wr_socket with plain TCP underlying socket
  * @return created socket on success, WR_BAD otherwise
  */
-static wr_socket wr_create_plain_sckt(void)
+static wr_socket
+wr_create_plain_sckt(void)
 {
   wr_socket s = (wr_socket)malloc(sizeof(struct wr_socket_strc));
   if (WR_BAD == s)
@@ -219,7 +220,8 @@ static wr_socket wr_create_plain_sckt(void)
  * Create wr_socket with TLS TCP underlying socket
  * @return created socket on success, WR_BAD otherwise
  */
-static wr_socket wr_create_tls_sckt(void)
+static wr_socket
+wr_create_tls_sckt(void)
 {
 #ifdef HTTPS_SUPPORT
   wr_socket s = (wr_socket)malloc(sizeof(struct wr_socket_strc));
@@ -264,9 +266,11 @@ static wr_socket wr_create_tls_sckt(void)
  * @param plain_sk real TCP socket
  * @return created socket on success, WR_BAD otherwise
  */
-static wr_socket wr_create_from_plain_sckt(MHD_socket plain_sk)
+static wr_socket
+wr_create_from_plain_sckt(MHD_socket plain_sk)
 {
   wr_socket s = (wr_socket)malloc(sizeof(struct wr_socket_strc));
+
   if (WR_BAD == s)
     return WR_BAD;
   s->t = wr_plain;
@@ -282,32 +286,25 @@ static wr_socket wr_create_from_plain_sckt(MHD_socket 
plain_sk)
  * @param length of sturcture pointed by @a addr
  * @return zero on success, -1 otherwise.
  */
-static int wr_connect(wr_socket s, struct sockaddr * addr, int length)
+static int
+wr_connect(wr_socket s,
+           const struct sockaddr *addr,
+           int length)
 {
-  if (0 != connect(s->fd, addr, length))
+  if (0 != connect (s->fd, addr, length))
     return -1;
   if (wr_plain == s->t)
     return 0;
 #ifdef HTTPS_SUPPORT
   if (wr_tls == s->t)
     {
-      s->tls_connected = 0;
-      return 0;
       /* Do not try handshake here as
        * it require processing on MHD side and
        * when testing with "external" polling,
        * test will call MHD processing only
        * after return from wr_connect(). */
-      /*
-      int res = gnutls_handshake (s->tls_s);
-      if (GNUTLS_E_SUCCESS == res)
-        {
-          s->tls_connected = !0;
-          return 0;
-        }
-      if (GNUTLS_E_AGAIN == res)
-        return 0;
-       */
+      s->tls_connected = 0;
+      return 0;
     }
 #endif /* HTTPS_SUPPORT */
   return -1;
@@ -319,7 +316,7 @@ static bool wr_handshake(wr_socket s)
 {
   int res = gnutls_handshake (s->tls_s);
   if (GNUTLS_E_SUCCESS == res)
-    s->tls_connected = !0;
+    s->tls_connected = true;
   else if (GNUTLS_E_AGAIN == res)
     MHD_socket_set_error_ (MHD_SCKT_EAGAIN_);
   else
@@ -338,7 +335,10 @@ static bool wr_handshake(wr_socket s)
  *         -1 if failed. Use #MHD_socket_get_error_()
  *         to get socket error.
  */
-static ssize_t wr_send(wr_socket s, const void *buf, size_t len)
+static ssize_t
+wr_send (wr_socket s,
+         const void *buf,
+         size_t len)
 {
   if (wr_plain == s->t)
     return MHD_send_(s->fd, buf, len);
@@ -371,7 +371,10 @@ static ssize_t wr_send(wr_socket s, const void *buf, 
size_t len)
  *         -1 if failed. Use #MHD_socket_get_error_()
  *         to get socket error.
  */
-static ssize_t wr_recv(wr_socket s, void *buf, size_t len)
+static ssize_t
+wr_recv (wr_socket s,
+         void *buf,
+         size_t len)
 {
   if (wr_plain == s->t)
     return MHD_recv_ (s->fd, buf, len);
@@ -401,7 +404,7 @@ static ssize_t wr_recv(wr_socket s, void *buf, size_t len)
  * @return zero on succeed, -1 otherwise
  */
 static int
-wr_close(wr_socket s)
+wr_close (wr_socket s)
 {
   int ret = (MHD_socket_close_(s->fd)) ? 0 : -1;
 #ifdef HTTPS_SUPPORT
diff --git a/src/testcurl/https/test_https_session_info.c 
b/src/testcurl/https/test_https_session_info.c
index eb821240..f21e03b0 100644
--- a/src/testcurl/https/test_https_session_info.c
+++ b/src/testcurl/https/test_https_session_info.c
@@ -141,7 +141,9 @@ test_query_session ()
       aes256_sha = "rsa_aes_256_sha";
     }
 
-  gen_test_file_url (url, port);
+  gen_test_file_url (url,
+                     sizeof (url),
+                     port);
   c = curl_easy_init ();
 #if DEBUG_HTTPS_TEST
   curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
diff --git a/src/testcurl/https/test_tls_extensions.c 
b/src/testcurl/https/test_tls_extensions.c
index a7bb6d4e..98725ee3 100644
--- a/src/testcurl/https/test_tls_extensions.c
+++ b/src/testcurl/https/test_tls_extensions.c
@@ -168,7 +168,9 @@ test_hello_extension (gnutls_session_t session, int port, 
extensions_t exten_t,
 
   gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd);
 
-  if (gen_test_file_url (url, port))
+  if (gen_test_file_url (url,
+                         sizeof (url),
+                         port))
     {
       ret = -1;
       goto cleanup;
diff --git a/src/testcurl/https/test_tls_options.c 
b/src/testcurl/https/test_tls_options.c
index a0f053a0..6eed7932 100644
--- a/src/testcurl/https/test_tls_options.c
+++ b/src/testcurl/https/test_tls_options.c
@@ -57,10 +57,13 @@ test_unmatching_ssl_version (void * cls, int port, const 
char *cipher_suite,
   cbc.pos = 0;
 
   char url[255];
-  if (gen_test_file_url (url, port))
+  if (gen_test_file_url (url,
+                         sizeof (url),
+                         port))
     {
       free (cbc.buf);
-      fprintf (stderr, "Internal error in gen_test_file_url\n");
+      fprintf (stderr,
+               "Internal error in gen_test_file_url\n");
       return -1;
     }
 
diff --git a/src/testcurl/https/tls_test_common.c 
b/src/testcurl/https/tls_test_common.c
index 63cb1013..e929334b 100644
--- a/src/testcurl/https/tls_test_common.c
+++ b/src/testcurl/https/tls_test_common.c
@@ -84,7 +84,9 @@ test_daemon_get (void *cls,
   cbc.pos = 0;
 
   /* construct url - this might use doc_path */
-  gen_test_file_url (url, port);
+  gen_test_file_url (url,
+                     sizeof (url),
+                     port);
 
   c = curl_easy_init ();
 #if DEBUG_HTTPS_TEST
@@ -108,7 +110,7 @@ test_daemon_get (void *cls,
     curl_easy_setopt (c, CURLOPT_CAINFO, ca_cert_file_name);
   curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
-  
+
   /* NOTE: use of CONNECTTIMEOUT without also
      setting NOSIGNAL results in really weird
      crashes on my system! */
@@ -258,12 +260,15 @@ send_curl_req (char *url, struct CBC * cbc, const char 
*cipher_suite,
 /**
  * compile test file url pointing to the current running directory path
  *
- * @param url - char buffer into which the url is compiled
+ * @param[out] url - char buffer into which the url is compiled
+ * @param url_len number of bytes available in url
  * @param port port to use for the test
  * @return -1 on error
  */
 int
-gen_test_file_url (char *url, int port)
+gen_test_file_url (char *url,
+                   size_t url_len,
+                   int port)
 {
   int ret = 0;
   char *doc_path;
@@ -279,46 +284,54 @@ gen_test_file_url (char *url, int port)
       fprintf (stderr, MHD_E_MEM);
       return -1;
     }
-  if (getcwd (doc_path, doc_path_len) == NULL)
+  if (NULL == getcwd (doc_path, doc_path_len))
     {
-      fprintf (stderr, "Error: failed to get working directory. %s\n",
+      fprintf (stderr,
+               "Error: failed to get working directory. %s\n",
                strerror (errno));
-      ret = -1;
+      free (doc_path);
+      return -1;
     }
 #ifdef WINDOWS
+  for (int i = 0; i < doc_path_len; i++)
   {
-    int i;
-    for (i = 0; i < doc_path_len; i++)
-    {
-      if (doc_path[i] == 0)
-        break;
-      if (doc_path[i] == '\\')
+    if (doc_path[i] == 0)
+      break;
+    if (doc_path[i] == '\\')
       {
         doc_path[i] = '/';
       }
-      if (doc_path[i] != ':')
-        continue;
-      if (i == 0)
-        break;
-      doc_path[i] = doc_path[i - 1];
-      doc_path[i - 1] = '/';
-    }
+    if (doc_path[i] != ':')
+      continue;
+    if (i == 0)
+      break;
+    doc_path[i] = doc_path[i - 1];
+    doc_path[i - 1] = '/';
   }
 #endif
-  /* construct url - this might use doc_path */
-  if (sprintf (url, "%s:%d%s/%s", "https://127.0.0.1";, port,
-               doc_path, "urlpath") < 0)
+  /* construct url */
+  if (snprintf (url,
+                url_len,
+                "%s:%d%s/%s",
+                "https://127.0.0.1";,
+                port,
+                doc_path,
+                "urlpath") >= url_len)
     ret = -1;
 
   free (doc_path);
   return ret;
 }
 
+
 /**
  * test HTTPS file transfer
  */
 int
-test_https_transfer (void *cls, int port, const char *cipher_suite, int 
proto_version)
+test_https_transfer (void *cls,
+                     int port,
+                     const char *cipher_suite,
+                     int proto_version)
 {
   int len;
   int ret = 0;
@@ -334,13 +347,16 @@ test_https_transfer (void *cls, int port, const char 
*cipher_suite, int proto_ve
   cbc.size = len;
   cbc.pos = 0;
 
-  if (gen_test_file_url (url, port))
+  if (gen_test_file_url (url,
+                         sizeof (url),
+                         port))
     {
       ret = -1;
       goto cleanup;
     }
 
-  if (CURLE_OK != send_curl_req (url, &cbc, cipher_suite, proto_version))
+  if (CURLE_OK !=
+      send_curl_req (url, &cbc, cipher_suite, proto_version))
     {
       ret = -1;
       goto cleanup;
@@ -348,8 +364,8 @@ test_https_transfer (void *cls, int port, const char 
*cipher_suite, int proto_ve
 
   /* compare test file & daemon responce */
   if ( (len != strlen (test_data)) ||
-       (memcmp (cbc.buf, 
-               test_data, 
+       (memcmp (cbc.buf,
+               test_data,
                len) != 0) )
     {
       fprintf (stderr, "Error: local file & received file differ.\n");
@@ -404,7 +420,7 @@ teardown_testcase (struct MHD_Daemon *d)
 int
 setup_session (gnutls_session_t * session,
                gnutls_datum_t * key,
-               gnutls_datum_t * cert, 
+               gnutls_datum_t * cert,
               gnutls_certificate_credentials_t * xcred)
 {
   int ret;
@@ -413,7 +429,7 @@ setup_session (gnutls_session_t * session,
   gnutls_certificate_allocate_credentials (xcred);
   key->size = strlen (srv_key_pem) + 1;
   key->data = malloc (key->size);
-  if (NULL == key->data) 
+  if (NULL == key->data)
      {
        gnutls_certificate_free_credentials (*xcred);
        return -1;
@@ -424,7 +440,7 @@ setup_session (gnutls_session_t * session,
   if (NULL == cert->data)
     {
         gnutls_certificate_free_credentials (*xcred);
-       free (key->data); 
+       free (key->data);
        return -1;
     }
   memcpy (cert->data, srv_self_signed_cert_pem, cert->size);
@@ -440,8 +456,8 @@ setup_session (gnutls_session_t * session,
        free (key->data);
        return -1;
     }
-  gnutls_credentials_set (*session, 
-                         GNUTLS_CRD_CERTIFICATE, 
+  gnutls_credentials_set (*session,
+                         GNUTLS_CRD_CERTIFICATE,
                          *xcred);
   return 0;
 }
diff --git a/src/testcurl/https/tls_test_common.h 
b/src/testcurl/https/tls_test_common.h
index a59c43f4..07849e44 100644
--- a/src/testcurl/https/tls_test_common.h
+++ b/src/testcurl/https/tls_test_common.h
@@ -68,12 +68,15 @@ struct CipherDef
 };
 
 
-int curl_check_version (const char *req_version, ...);
-int curl_uses_nss_ssl ();
+int
+curl_check_version (const char *req_version, ...);
+
+int
+curl_uses_nss_ssl (void);
 
 
 FILE *
-setup_ca_cert ();
+setup_ca_cert (void);
 
 /**
  * perform cURL request for file
@@ -83,9 +86,11 @@ test_daemon_get (void * cls,
                 const char *cipher_suite, int proto_version,
                  int port, int ver_peer);
 
-void print_test_result (int test_outcome, char *test_name);
+void
+print_test_result (int test_outcome, char *test_name);
 
-size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx);
+size_t
+copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx);
 
 int
 http_ahc (void *cls, struct MHD_Connection *connection,
@@ -102,11 +107,15 @@ http_dummy_ahc (void *cls, struct MHD_Connection 
*connection,
 /**
  * compile test file url pointing to the current running directory path
  *
- * @param url - char buffer into which the url is compiled
+ * @param[out] url - char buffer into which the url is compiled
+ * @param url_len number of bytes available in @a url
  * @param port port to use for the test
  * @return -1 on error
  */
-int gen_test_file_url (char *url, int port);
+int
+gen_test_file_url (char *url,
+                   size_t url_len,
+                   int port);
 
 int
 send_curl_req (char *url, struct CBC *cbc, const char *cipher_suite,
@@ -118,7 +127,9 @@ test_https_transfer (void *cls, int port, const char 
*cipher_suite, int proto_ve
 int
 setup_testcase (struct MHD_Daemon **d, int port, int daemon_flags, va_list 
arg_list);
 
-void teardown_testcase (struct MHD_Daemon *d);
+void
+teardown_testcase (struct MHD_Daemon *d);
+
 
 int
 setup_session (gnutls_session_t * session,
diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c
index 6901be0f..9c9e125f 100644
--- a/src/testcurl/test_callback.c
+++ b/src/testcurl/test_callback.c
@@ -69,15 +69,21 @@ callback(void *cls,
 {
   struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure));
   struct MHD_Response *r;
+  int ret;
 
   r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024,
                                         &called_twice, cbc,
                                         &free);
-  MHD_queue_response (connection,
-                      MHD_HTTP_OK,
-                      r);
+  if (NULL == r)
+  {
+    free (cbc);
+    return MHD_NO;
+  }
+  ret = MHD_queue_response (connection,
+                            MHD_HTTP_OK,
+                            r);
   MHD_destroy_response (r);
-  return MHD_YES;
+  return ret;
 }
 
 
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c
index 425776af..2c6ec2d4 100644
--- a/src/testcurl/test_get_chunked.c
+++ b/src/testcurl/test_get_chunked.c
@@ -54,8 +54,12 @@ struct CBC
   size_t size;
 };
 
+
 static size_t
-copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
+copyBuffer (void *ptr,
+            size_t size,
+            size_t nmemb,
+            void *ctx)
 {
   struct CBC *cbc = ctx;
 
@@ -66,28 +70,34 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
   return size * nmemb;
 }
 
+
 /**
- * MHD content reader callback that returns
- * data in chunks.
+ * MHD content reader callback that returns data in chunks.
  */
 static ssize_t
-crc (void *cls, uint64_t pos, char *buf, size_t max)
+crc (void *cls,
+     uint64_t pos,
+     char *buf,
+     size_t max)
 {
   struct MHD_Response **responseptr = cls;
 
   if (pos == 128 * 10)
-    {
-      MHD_add_response_header (*responseptr, "Footer", "working");
-      return MHD_CONTENT_READER_END_OF_STREAM;
-    }
+  {
+    MHD_add_response_footer (*responseptr,
+                             "Footer",
+                             "working");
+    return MHD_CONTENT_READER_END_OF_STREAM;
+  }
   if (max < 128)
     abort ();                   /* should not happen in this testcase... */
   memset (buf, 'A' + (pos / 128), 128);
   return 128;
 }
 
+
 /**
- * Dummy function that does nothing.
+ * Dummy function that frees the "responseptr".
  */
 static void
 crcf (void *ptr)
@@ -95,6 +105,7 @@ crcf (void *ptr)
   free (ptr);
 }
 
+
 static int
 ahc_echo (void *cls,
           struct MHD_Connection *connection,
@@ -118,17 +129,27 @@ ahc_echo (void *cls,
       return MHD_YES;
     }
   responseptr = malloc (sizeof (struct MHD_Response *));
-  if (responseptr == NULL)
+  if (NULL == responseptr)
     return MHD_NO;
   response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
                                                 1024,
-                                                &crc, responseptr, &crcf);
+                                                &crc,
+                                                responseptr,
+                                                &crcf);
+  if (NULL == response)
+  {
+    free (responseptr);
+    return MHD_NO;
+  }
   *responseptr = response;
-  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+  ret = MHD_queue_response (connection,
+                            MHD_HTTP_OK,
+                            response);
   MHD_destroy_response (response);
   return ret;
 }
 
+
 static int
 validate (struct CBC cbc, int ebase)
 {

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



reply via email to

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