gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated: avoid sprintf


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated: avoid sprintf
Date: Sun, 18 Nov 2018 12:21:05 +0100

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

grothoff pushed a commit to branch master
in repository libmicrohttpd.

The following commit(s) were added to refs/heads/master by this push:
     new 488615ce avoid sprintf
488615ce is described below

commit 488615cea6ccb5437ebde23c03a5e52fdbc95436
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Nov 18 12:21:02 2018 +0100

    avoid sprintf
---
 src/testcurl/perf_get.c                  | 26 +++++++---
 src/testcurl/perf_get_concurrent.c       |  6 ++-
 src/testcurl/test_concurrent_stop.c      |  5 +-
 src/testcurl/test_digestauth.c           | 81 +++++++++++++++++++++-----------
 src/testcurl/test_get_response_cleanup.c | 20 ++++++--
 src/testcurl/test_get_sendfile.c         | 11 +++--
 src/testcurl/test_post_loop.c            | 36 ++++++++++----
 src/testcurl/test_quiesce_stream.c       |  5 +-
 src/testcurl/test_termination.c          | 10 ++--
 9 files changed, 141 insertions(+), 59 deletions(-)

diff --git a/src/testcurl/perf_get.c b/src/testcurl/perf_get.c
index 98578173..ac6a23f3 100644
--- a/src/testcurl/perf_get.c
+++ b/src/testcurl/perf_get.c
@@ -207,7 +207,10 @@ testInternalGet (int port, int poll_flag)
         { MHD_stop_daemon (d); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(url, "http://127.0.0.1:%d/hello_world";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/hello_world";,
+            port);
   start_timer ();
   for (i=0;i<ROUNDS;i++)
     {
@@ -278,7 +281,10 @@ testMultithreadedGet (int port, int poll_flag)
         { MHD_stop_daemon (d); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(url, "http://127.0.0.1:%d/hello_world";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/hello_world";,
+            port);
   start_timer ();
   for (i=0;i<ROUNDS;i++)
     {
@@ -350,7 +356,10 @@ testMultithreadedPoolGet (int port, int poll_flag)
         { MHD_stop_daemon (d); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(url, "http://127.0.0.1:%d/hello_world";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/hello_world";,
+            port);
   start_timer ();
   for (i=0;i<ROUNDS;i++)
     {
@@ -424,8 +433,10 @@ testExternalGet (int port)
   cbc.buf = buf;
   cbc.size = 2048;
   d = MHD_start_daemon (MHD_USE_ERROR_LOG,
-                        port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
-  if (d == NULL)
+                        port, NULL, NULL,
+                        &ahc_echo, "GET",
+                        MHD_OPTION_END);
+  if (NULL == d)
     return 256;
   if (0 == port)
     {
@@ -435,7 +446,10 @@ testExternalGet (int port)
         { MHD_stop_daemon (d); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(url, "http://127.0.0.1:%d/hello_world";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/hello_world";,
+            port);
   start_timer ();
   multi = curl_multi_init ();
   if (multi == NULL)
diff --git a/src/testcurl/perf_get_concurrent.c 
b/src/testcurl/perf_get_concurrent.c
index 49ed1ba4..e1c2e997 100644
--- a/src/testcurl/perf_get_concurrent.c
+++ b/src/testcurl/perf_get_concurrent.c
@@ -218,8 +218,10 @@ do_gets (void * param)
   int port = (int)(intptr_t)param;
   char *err = NULL;
 
-  sprintf(url, "http://127.0.0.1:%d/hello_world";, port);
-
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/hello_world";,
+            port);
   for (j=0;j<PAR;j++)
     {
       if (0 != pthread_create(&par[j], NULL, &thread_gets, (void*)url))
diff --git a/src/testcurl/test_concurrent_stop.c 
b/src/testcurl/test_concurrent_stop.c
index 3409d472..263aaf0a 100644
--- a/src/testcurl/test_concurrent_stop.c
+++ b/src/testcurl/test_concurrent_stop.c
@@ -169,7 +169,10 @@ do_gets (void * param)
   char url[64];
   int port = (int)(intptr_t)param;
 
-  sprintf(url, "http://127.0.0.1:%d/hello_world";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/hello_world";,
+            port);
 
   for (j=0;j<PAR;j++)
     {
diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c
index 912efa11..b8b77674 100644
--- a/src/testcurl/test_digestauth.c
+++ b/src/testcurl/test_digestauth.c
@@ -57,8 +57,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;
 
@@ -69,6 +73,7 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
   return size * nmemb;
 }
 
+
 static int
 ahc_echo (void *cls,
           struct MHD_Connection *connection,
@@ -95,30 +100,33 @@ ahc_echo (void *cls,
       response = MHD_create_response_from_buffer (strlen (DENIED),
                                                   DENIED,
                                                   MHD_RESPMEM_PERSISTENT);
-      ret = MHD_queue_auth_fail_response(connection, realm,
-                                        MY_OPAQUE,
-                                        response,
-                                        MHD_NO);
+      ret = MHD_queue_auth_fail_response (connection,
+                                          realm,
+                                          MY_OPAQUE,
+                                          response,
+                                          MHD_NO);
       MHD_destroy_response(response);
       return ret;
     }
-  ret = MHD_digest_auth_check(connection, realm,
-                             username,
-                             password,
-                             300);
-  free(username);
+  ret = MHD_digest_auth_check (connection,
+                               realm,
+                              username,
+                               password,
+                               300);
+  free (username);
   if ( (ret == MHD_INVALID_NONCE) ||
        (ret == MHD_NO) )
     {
-      response = MHD_create_response_from_buffer(strlen (DENIED),
-                                                DENIED,
-                                                MHD_RESPMEM_PERSISTENT);
+      response = MHD_create_response_from_buffer (strlen (DENIED),
+                                                  DENIED,
+                                                  MHD_RESPMEM_PERSISTENT);
       if (NULL == response)
        return MHD_NO;
-      ret = MHD_queue_auth_fail_response(connection, realm,
-                                        MY_OPAQUE,
-                                        response,
-                                        (ret == MHD_INVALID_NONCE) ? MHD_YES : 
MHD_NO);
+      ret = MHD_queue_auth_fail_response (connection,
+                                          realm,
+                                          MY_OPAQUE,
+                                          response,
+                                          (MHD_INVALID_NONCE == ret) ? MHD_YES 
: MHD_NO);
       MHD_destroy_response(response);
       return ret;
     }
@@ -159,7 +167,8 @@ testDigestAuth ()
   cbc.size = 2048;
   cbc.pos = 0;
 #ifndef WINDOWS
-  fd = open("/dev/urandom", O_RDONLY);
+  fd = open ("/dev/urandom",
+             O_RDONLY);
   if (-1 == fd)
     {
       fprintf (stderr,
@@ -170,7 +179,9 @@ testDigestAuth ()
     }
   while (off < 8)
     {
-      len = read(fd, rnd, 8);
+      len = read (fd,
+                  rnd,
+                  8);
       if (len == (size_t)-1)
         {
           fprintf (stderr,
@@ -187,18 +198,25 @@ testDigestAuth ()
   {
     HCRYPTPROV cc;
     BOOL b;
-    b = CryptAcquireContext (&cc, NULL, NULL, PROV_RSA_FULL, 
CRYPT_VERIFYCONTEXT);
+
+    b = CryptAcquireContext (&cc,
+                             NULL,
+                             NULL,
+                             PROV_RSA_FULL,
+                             CRYPT_VERIFYCONTEXT);
     if (b == 0)
     {
-      fprintf (stderr, "Failed to acquire crypto provider context: %lu\n",
-          GetLastError ());
+      fprintf (stderr,
+               "Failed to acquire crypto provider context: %lu\n",
+               GetLastError ());
       return 1;
     }
     b = CryptGenRandom (cc, 8, (BYTE*)rnd);
     if (b == 0)
     {
-      fprintf (stderr, "Failed to generate 8 random bytes: %lu\n",
-          GetLastError ());
+      fprintf (stderr,
+               "Failed to generate 8 random bytes: %lu\n",
+               GetLastError ());
     }
     CryptReleaseContext (cc, 0);
     if (b == 0)
@@ -206,7 +224,8 @@ testDigestAuth ()
   }
 #endif
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
-                        port, NULL, NULL, &ahc_echo, PAGE,
+                        port, NULL, NULL,
+                        &ahc_echo, PAGE,
                        MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof (rnd), rnd,
                        MHD_OPTION_NONCE_NC_SIZE, 300,
                        MHD_OPTION_END);
@@ -215,9 +234,15 @@ testDigestAuth ()
   if (0 == port)
     {
       const union MHD_DaemonInfo *dinfo;
-      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
-      if (NULL == dinfo || 0 == dinfo->port)
-        { MHD_stop_daemon (d); return 32; }
+
+      dinfo = MHD_get_daemon_info (d,
+                                   MHD_DAEMON_INFO_BIND_PORT);
+      if ( (NULL == dinfo) ||
+           (0 == dinfo->port) )
+        {
+          MHD_stop_daemon (d);
+          return 32;
+        }
       port = (int)dinfo->port;
     }
   snprintf (url,
diff --git a/src/testcurl/test_get_response_cleanup.c 
b/src/testcurl/test_get_response_cleanup.c
index 8cb4f4a7..d3d45d2f 100644
--- a/src/testcurl/test_get_response_cleanup.c
+++ b/src/testcurl/test_get_response_cleanup.c
@@ -182,7 +182,10 @@ testInternalGet ()
         { MHD_stop_daemon (d); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(url, "http://127.0.0.1:%d/";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/";,
+            port);
   curl = fork_curl (url);
   (void)sleep (1);
   kill_curl (curl);
@@ -227,7 +230,10 @@ testMultithreadedGet ()
         { MHD_stop_daemon (d); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(url, "http://127.0.0.1:%d/";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/";,
+            port);
   //fprintf (stderr, "Forking cURL!\n");
   curl = fork_curl (url);
   (void)sleep (1);
@@ -283,7 +289,10 @@ testMultithreadedPoolGet ()
         { MHD_stop_daemon (d); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(url, "http://127.0.0.1:%d/";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/";,
+            port);
   curl = fork_curl (url);
   (void)sleep (1);
   kill_curl (curl);
@@ -332,7 +341,10 @@ testExternalGet ()
         { MHD_stop_daemon (d); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(url, "http://127.0.0.1:%d/";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d/";,
+            port);
   curl = fork_curl (url);
 
   start = time (NULL);
diff --git a/src/testcurl/test_get_sendfile.c b/src/testcurl/test_get_sendfile.c
index a312c205..c7e94945 100644
--- a/src/testcurl/test_get_sendfile.c
+++ b/src/testcurl/test_get_sendfile.c
@@ -584,11 +584,12 @@ main (int argc, char *const *argv)
        (NULL == (tmp = getenv ("TEMP"))) )
     tmp = "/tmp";
   sourcefile = malloc (strlen (tmp) + 32);
-  sprintf (sourcefile,
-          "%s/%s%s",
-          tmp,
-          "test-mhd-sendfile",
-          oneone ? "11" : "");
+  snprintf (sourcefile,
+            strlen (tmp) + 32,
+            "%s/%s%s",
+            tmp,
+            "test-mhd-sendfile",
+            oneone ? "11" : "");
   f = fopen (sourcefile, "w");
   if (NULL == f)
     {
diff --git a/src/testcurl/test_post_loop.c b/src/testcurl/test_post_loop.c
index 5ed57431..6da06b45 100644
--- a/src/testcurl/test_post_loop.c
+++ b/src/testcurl/test_post_loop.c
@@ -93,7 +93,7 @@ ahc_echo (void *cls,
     {
       if (*mptr != &marker)
         abort ();
-      response = MHD_create_response_from_buffer (2, "OK", 
+      response = MHD_create_response_from_buffer (2, "OK",
                                                  MHD_RESPMEM_PERSISTENT);
       ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
       MHD_destroy_response (response);
@@ -150,7 +150,11 @@ testInternalPost ()
       c = curl_easy_init ();
       cbc.pos = 0;
       buf[0] = '\0';
-      sprintf (url, "http://127.0.0.1:%d/hw%d";, port, i);
+      snprintf (url,
+                sizeof (url),
+                "http://127.0.0.1:%d/hw%d";,
+                port,
+                i);
       curl_easy_setopt (c, CURLOPT_URL, url);
       curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
       curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
@@ -214,7 +218,9 @@ testMultithreadedPost ()
   cbc.buf = buf;
   cbc.size = 2048;
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
-                        port, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
+                        port, NULL, NULL,
+                        &ahc_echo, NULL,
+                        MHD_OPTION_END);
   if (d == NULL)
     return 16;
   if (0 == port)
@@ -232,7 +238,11 @@ testMultithreadedPost ()
       c = curl_easy_init ();
       cbc.pos = 0;
       buf[0] = '\0';
-      sprintf (url, "http://127.0.0.1:%d/hw%d";, port, i);
+      snprintf (url,
+                sizeof (url),
+                "http://127.0.0.1:%d/hw%d";,
+                port,
+                i);
       curl_easy_setopt (c, CURLOPT_URL, url);
       curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
       curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
@@ -315,7 +325,11 @@ testMultithreadedPoolPost ()
       c = curl_easy_init ();
       cbc.pos = 0;
       buf[0] = '\0';
-      sprintf (url, "http://127.0.0.1:%d/hw%d";, port, i);
+      snprintf (url,
+                sizeof (url),
+                "http://127.0.0.1:%d/hw%d";,
+                port,
+                i);
       curl_easy_setopt (c, CURLOPT_URL, url);
       curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
       curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
@@ -421,7 +435,11 @@ testExternalPost ()
       c = curl_easy_init ();
       cbc.pos = 0;
       buf[0] = '\0';
-      sprintf (url, "http://127.0.0.1:%d/hw%d";, port, i);
+      snprintf (url,
+                sizeof (url),
+                "http://127.0.0.1:%d/hw%d";,
+                port,
+                i);
       curl_easy_setopt (c, CURLOPT_URL, url);
       curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
       curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
@@ -490,7 +508,7 @@ testExternalPost ()
              fprintf (stderr,
                       "select failed: %s\n",
                       strerror (errno));
-             break;          
+             break;
            }
           while (CURLM_CALL_MULTI_PERFORM ==
                  curl_multi_perform (multi, &running));
@@ -540,11 +558,11 @@ static unsigned long long start_time;
 
 
 /**
- * Get the current timestamp 
+ * Get the current timestamp
  *
  * @return current time in ms
  */
-static unsigned long long 
+static unsigned long long
 now ()
 {
   struct timeval tv;
diff --git a/src/testcurl/test_quiesce_stream.c 
b/src/testcurl/test_quiesce_stream.c
index 5d80ee70..bccb5890 100644
--- a/src/testcurl/test_quiesce_stream.c
+++ b/src/testcurl/test_quiesce_stream.c
@@ -220,7 +220,10 @@ main(void)
         { MHD_stop_daemon (daemon); return 32; }
       port = (int)dinfo->port;
     }
-  sprintf(command_line, "curl -s http://127.0.0.1:%d";, port);
+  snprintf (command_line,
+            sizeof (command_line),
+            "curl -s http://127.0.0.1:%d";,
+            port);
 
   if (0 != system (command_line))
     {
diff --git a/src/testcurl/test_termination.c b/src/testcurl/test_termination.c
index 6f633c84..5be74303 100644
--- a/src/testcurl/test_termination.c
+++ b/src/testcurl/test_termination.c
@@ -94,6 +94,8 @@ main (void)
 {
   struct MHD_Daemon *daemon;
   int port;
+  char url[255];
+  CURL *curl;
 
   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
     port = 0;
@@ -120,10 +122,12 @@ main (void)
       port = (int)dinfo->port;
     }
 
-  CURL *curl = curl_easy_init ();
+  curl = curl_easy_init ();
   /* curl_easy_setopt(curl, CURLOPT_POST, 1L); */
-  char url[255];
-  sprintf (url, "http://127.0.0.1:%d";, port);
+  snprintf (url,
+            sizeof (url),
+            "http://127.0.0.1:%d";,
+            port);
   curl_easy_setopt (curl, CURLOPT_URL, url);
   curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_data);
 

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



reply via email to

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