[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 02/07: src/examples: muted compiler warnings
From: |
gnunet |
Subject: |
[libmicrohttpd] 02/07: src/examples: muted compiler warnings |
Date: |
Wed, 01 Jun 2022 21:13:30 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 93dcf8ea912ceb2eb83b73a7e5165a08c4db9312
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Jun 1 16:15:08 2022 +0300
src/examples: muted compiler warnings
---
doc/examples/sessions.c | 4 ++--
src/examples/authorization_example.c | 4 ++--
src/examples/benchmark.c | 10 +++++++-
src/examples/benchmark_https.c | 10 +++++++-
src/examples/chunked_example.c | 6 ++++-
src/examples/digest_auth_example.c | 18 ++++++++++-----
src/examples/dual_stack_example.c | 10 +++++++-
src/examples/fileserver_example.c | 13 +++++++++--
src/examples/fileserver_example_dirs.c | 13 +++++++++--
src/examples/fileserver_example_external_select.c | 28 +++++++++++++++++++----
src/examples/http_compression.c | 13 +++++++----
src/examples/https_fileserver_example.c | 3 ++-
src/examples/minimal_example.c | 10 +++++++-
src/examples/minimal_example_comet.c | 12 +++++++++-
src/examples/minimal_example_empty.c | 12 +++++++++-
src/examples/minimal_example_empty_tls.c | 14 ++++++++++--
src/examples/post_example.c | 20 ++++++++++++----
src/examples/querystring_example.c | 12 ++++++----
src/examples/refuse_post_example.c | 24 ++++++++++++-------
src/examples/suspend_resume_epoll.c | 10 +++++++-
src/examples/upgrade_example.c | 17 ++++++++++----
21 files changed, 209 insertions(+), 54 deletions(-)
diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c
index 121cf2e0..7f62e73b 100644
--- a/doc/examples/sessions.c
+++ b/doc/examples/sessions.c
@@ -778,8 +778,8 @@ main (int argc, char *const *argv)
break; /* fatal internal error */
if (MHD_get_timeout64 (d, &mhd_timeout) == MHD_YES)
{
- tv.tv_sec = mhd_timeout / 1000;
- tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
+ tv.tv_sec = (time_t) mhd_timeout / 1000;
+ tv.tv_usec = ((long) (mhd_timeout % 1000)) * 1000;
tvp = &tv;
}
else
diff --git a/src/examples/authorization_example.c
b/src/examples/authorization_example.c
index d5011e5d..8d26869a 100644
--- a/src/examples/authorization_example.c
+++ b/src/examples/authorization_example.c
@@ -109,7 +109,7 @@ main (int argc, char *const *argv)
if ( (argc != 2) ||
(1 != sscanf (argv[1], "%u", &port)) ||
- (UINT16_MAX < port) )
+ (65535 < port) )
{
fprintf (stderr,
"%s PORT\n", argv[0]);
@@ -118,7 +118,7 @@ main (int argc, char *const *argv)
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
diff --git a/src/examples/benchmark.c b/src/examples/benchmark.c
index 37e1b4f8..b5598b1b 100644
--- a/src/examples/benchmark.c
+++ b/src/examples/benchmark.c
@@ -141,12 +141,20 @@ main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
unsigned int i;
+ int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
+ port = atoi (argv[1]);
+ if ( (1 > port) || (port > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
response = MHD_create_response_from_buffer_static (strlen (PAGE),
(const void *) PAGE);
#if 0
@@ -160,7 +168,7 @@ main (int argc, char *const *argv)
| MHD_USE_EPOLL | MHD_USE_TURBO
#endif
,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_THREAD_POOL_SIZE, (unsigned
diff --git a/src/examples/benchmark_https.c b/src/examples/benchmark_https.c
index 9553d434..ea091e90 100644
--- a/src/examples/benchmark_https.c
+++ b/src/examples/benchmark_https.c
@@ -207,12 +207,20 @@ main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
unsigned int i;
+ int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
+ port = atoi (argv[1]);
+ if ( (1 > port) || (port > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
response = MHD_create_response_from_buffer_static (strlen (PAGE),
(const void *) PAGE);
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
@@ -220,7 +228,7 @@ main (int argc, char *const *argv)
| MHD_USE_EPOLL | MHD_USE_TURBO
#endif
,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_THREAD_POOL_SIZE, (unsigned
diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c
index 5a4c0ced..12d07d90 100644
--- a/src/examples/chunked_example.c
+++ b/src/examples/chunked_example.c
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2015 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -73,7 +74,10 @@ callback (void *cls,
}
* End of pseudo code. */
/* Return amount of data copied to buffer. */
- return size_to_copy;
+ /* The 'buf_size' is always smaller than SSIZE_MAX therefore it's safe
+ * to cast 'size_to_copy' to 'ssize_t'. */
+ /* assert (size_to_copy <= buf_size); */
+ return (ssize_t) size_to_copy;
}
diff --git a/src/examples/digest_auth_example.c
b/src/examples/digest_auth_example.c
index b3741bc5..4f576bf0 100644
--- a/src/examples/digest_auth_example.c
+++ b/src/examples/digest_auth_example.c
@@ -29,10 +29,12 @@
#include <stdlib.h>
#define PAGE \
- "<html><head><title>libmicrohttpd demo</title></head><body>Access
granted</body></html>"
+ "<html><head><title>libmicrohttpd demo</title></head>" \
+ "<body>Access granted</body></html>"
#define DENIED \
- "<html><head><title>libmicrohttpd demo</title></head><body>Access
denied</body></html>"
+ "<html><head><title>libmicrohttpd demo</title></head>" \
+ "<body>Access denied</body></html>"
#define MY_OPAQUE_STR "11733b200778ce33060f31c9af70a870ba96ddd4"
@@ -116,12 +118,16 @@ main (int argc, char *const *argv)
ssize_t len;
size_t off;
struct MHD_Daemon *d;
+ unsigned int port;
- if (argc != 2)
+ if ( (argc != 2) ||
+ (1 != sscanf (argv[1], "%u", &port)) ||
+ (65535 < port) )
{
printf ("%s PORT\n", argv[0]);
return 1;
}
+
fd = open ("/dev/urandom", O_RDONLY);
if (-1 == fd)
{
@@ -134,7 +140,7 @@ main (int argc, char *const *argv)
while (off < 8)
{
len = read (fd, rnd, 8);
- if (len == -1)
+ if (0 > len)
{
fprintf (stderr, "Failed to read `%s': %s\n",
"/dev/urandom",
@@ -142,12 +148,12 @@ main (int argc, char *const *argv)
(void) close (fd);
return 1;
}
- off += len;
+ off += (size_t) len;
}
(void) close (fd);
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof(rnd), rnd,
MHD_OPTION_NONCE_NC_SIZE, 300,
diff --git a/src/examples/dual_stack_example.c
b/src/examples/dual_stack_example.c
index 957daf07..57a3b558 100644
--- a/src/examples/dual_stack_example.c
+++ b/src/examples/dual_stack_example.c
@@ -75,16 +75,24 @@ main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
struct handler_param data_for_handler;
+ int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
+ port = atoi (argv[1]);
+ if ( (1 > port) || (port > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
data_for_handler.response_page = PAGE;
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
| MHD_USE_DUAL_STACK,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, &data_for_handler,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_END);
diff --git a/src/examples/fileserver_example.c
b/src/examples/fileserver_example.c
index e300f6ed..ee80d632 100644
--- a/src/examples/fileserver_example.c
+++ b/src/examples/fileserver_example.c
@@ -100,7 +100,7 @@ ahc_echo (void *cls,
}
else
{
- response = MHD_create_response_from_fd64 (buf.st_size, fd);
+ response = MHD_create_response_from_fd64 ((uint64_t) buf.st_size, fd);
if (NULL == response)
{
if (0 != close (fd))
@@ -118,15 +118,24 @@ 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 > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
+
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
diff --git a/src/examples/fileserver_example_dirs.c
b/src/examples/fileserver_example_dirs.c
index 0a977ddf..26086251 100644
--- a/src/examples/fileserver_example_dirs.c
+++ b/src/examples/fileserver_example_dirs.c
@@ -169,7 +169,8 @@ ahc_echo (void *cls,
}
else
{
- response = MHD_create_response_from_callback (buf.st_size, 32 * 1024,
/* 32k page size */
+ response = MHD_create_response_from_callback ((size_t) buf.st_size,
+ 32 * 1024, /* 32k page size
*/
&file_reader,
file,
&file_free_callback);
@@ -189,15 +190,23 @@ 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 > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (NULL == d)
return 1;
diff --git a/src/examples/fileserver_example_external_select.c
b/src/examples/fileserver_example_external_select.c
index 3c077413..c2208170 100644
--- a/src/examples/fileserver_example_external_select.c
+++ b/src/examples/fileserver_example_external_select.c
@@ -107,7 +107,8 @@ ahc_echo (void *cls,
}
else
{
- response = MHD_create_response_from_callback (buf.st_size, 32 * 1024,
/* 32k page size */
+ response = MHD_create_response_from_callback ((size_t) buf.st_size,
+ 32 * 1024, /* 32k page size
*/
&file_reader,
file,
&free_callback);
@@ -135,21 +136,34 @@ main (int argc, char *const *argv)
fd_set es;
MHD_socket max;
uint64_t mhd_timeout;
+ int port;
if (argc != 3)
{
printf ("%s PORT SECONDS-TO-RUN\n", argv[0]);
return 1;
}
+ port = atoi (argv[1]);
+ if ( (1 > port) || (port > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
+
d = MHD_start_daemon (MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
end = time (NULL) + atoi (argv[2]);
while ((t = time (NULL)) < end)
{
+#if ! defined(_WIN32) || defined(__CYGWIN__)
tv.tv_sec = end - t;
+#else /* Native W32 */
+ tv.tv_sec = (long) (end - t);
+#endif /* Native W32 */
tv.tv_usec = 0;
max = 0;
FD_ZERO (&rs);
@@ -161,11 +175,15 @@ main (int argc, char *const *argv)
{
if (((uint64_t) tv.tv_sec) < mhd_timeout / 1000LL)
{
- tv.tv_sec = mhd_timeout / 1000LL;
- tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000LL)) * 1000LL;
+#if ! defined(_WIN32) || defined(__CYGWIN__)
+ tv.tv_sec = (time_t) (mhd_timeout / 1000LL);
+#else /* Native W32 */
+ tv.tv_sec = (long) (mhd_timeout / 1000LL);
+#endif /* Native W32 */
+ tv.tv_usec = ((long) (mhd_timeout % 1000)) * 1000;
}
}
- if (-1 == select (max + 1, &rs, &ws, &es, &tv))
+ if (-1 == select ((int) max + 1, &rs, &ws, &es, &tv))
{
if (EINTR != errno)
abort ();
diff --git a/src/examples/http_compression.c b/src/examples/http_compression.c
index 0f532cf0..244266ef 100644
--- a/src/examples/http_compression.c
+++ b/src/examples/http_compression.c
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2019 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2019-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
* @file http_compression.c
* @brief minimal example for how to compress HTTP response
* @author Silvio Clecio (silvioprog)
+ * @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -68,14 +70,14 @@ body_compress (void **buf,
uLongf cbuf_size;
int ret;
- cbuf_size = compressBound (*buf_size);
+ cbuf_size = compressBound ((uLong) * buf_size);
cbuf = malloc (cbuf_size);
if (NULL == cbuf)
return MHD_NO;
ret = compress (cbuf,
&cbuf_size,
(const Bytef *) *buf,
- *buf_size);
+ (uLong) * buf_size);
if ((Z_OK != ret) ||
(cbuf_size >= *buf_size))
{
@@ -165,15 +167,18 @@ int
main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
+ unsigned int port;
- if (argc != 2)
+ if ( (argc != 2) ||
+ (1 != sscanf (argv[1], "%u", &port)) ||
+ (65535 < port) )
{
printf ("%s PORT\n", argv[0]);
return 1;
}
d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
| MHD_USE_ERROR_LOG,
- atoi (argv[1]), NULL, NULL,
+ (uint16_t) port, NULL, NULL,
&ahc_echo, NULL,
MHD_OPTION_END);
if (NULL == d)
diff --git a/src/examples/https_fileserver_example.c
b/src/examples/https_fileserver_example.c
index bbfbf2db..ae304f72 100644
--- a/src/examples/https_fileserver_example.c
+++ b/src/examples/https_fileserver_example.c
@@ -186,7 +186,8 @@ http_ahc (void *cls,
}
else
{
- response = MHD_create_response_from_callback (buf.st_size, 32 * 1024,
/* 32k PAGE_NOT_FOUND size */
+ response = MHD_create_response_from_callback ((size_t) buf.st_size,
+ 32 * 1024, /* 32k page
size */
&file_reader, file,
&file_free_callback);
if (NULL == response)
diff --git a/src/examples/minimal_example.c b/src/examples/minimal_example.c
index 1e3f63f7..f7a0e64c 100644
--- a/src/examples/minimal_example.c
+++ b/src/examples/minimal_example.c
@@ -82,19 +82,27 @@ main (int argc,
{
struct MHD_Daemon *d;
struct handler_param data_for_handler;
+ int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
+ port = atoi (argv[1]);
+ if ( (1 > port) || (port > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
data_for_handler.response_page = PAGE;
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]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, &data_for_handler,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
diff --git a/src/examples/minimal_example_comet.c
b/src/examples/minimal_example_comet.c
index a8864d89..193c6051 100644
--- a/src/examples/minimal_example_comet.c
+++ b/src/examples/minimal_example_comet.c
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007, 2008 Christian Grothoff (and other contributing
authors)
+ Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
* @file minimal_example.c
* @brief minimal example for how to generate an infinite stream with
libmicrohttpd
* @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -77,15 +79,23 @@ 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 > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
diff --git a/src/examples/minimal_example_empty.c
b/src/examples/minimal_example_empty.c
index 84837f08..3556d753 100644
--- a/src/examples/minimal_example_empty.c
+++ b/src/examples/minimal_example_empty.c
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
* @file minimal_example.c
* @brief minimal example for how to use libmicrohttpd
* @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -69,18 +71,26 @@ 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 > 65535) )
+ {
+ 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]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
diff --git a/src/examples/minimal_example_empty_tls.c
b/src/examples/minimal_example_empty_tls.c
index c8c3763f..e01dc008 100644
--- a/src/examples/minimal_example_empty_tls.c
+++ b/src/examples/minimal_example_empty_tls.c
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2021-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -17,9 +18,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
/**
- * @file minimal_example_empty_ssl.c
+ * @file minimal_example_empty_tls.c
* @brief minimal example for how to use libmicrohttpd
* @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -135,19 +137,27 @@ 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 > 65535) )
+ {
+ 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_TLS,
/* 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]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
diff --git a/src/examples/post_example.c b/src/examples/post_example.c
index 1b6a5a03..6b10afc0 100644
--- a/src/examples/post_example.c
+++ b/src/examples/post_example.c
@@ -736,16 +736,24 @@ main (int argc, char *const *argv)
fd_set es;
MHD_socket max;
uint64_t mhd_timeout;
+ int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
+ port = atoi (argv[1]);
+ if ( (1 > port) || (port > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
/* initialize PRNG */
srand ((unsigned int) time (NULL));
d = MHD_start_daemon (MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL,
&create_response, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15,
@@ -765,13 +773,17 @@ main (int argc, char *const *argv)
break; /* fatal internal error */
if (MHD_get_timeout64 (d, &mhd_timeout) == MHD_YES)
{
- tv.tv_sec = mhd_timeout / 1000;
- tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
+#if ! defined(_WIN32) || defined(__CYGWIN__)
+ tv.tv_sec = (time_t) (mhd_timeout / 1000LL);
+#else /* Native W32 */
+ tv.tv_sec = (long) (mhd_timeout / 1000LL);
+#endif /* Native W32 */
+ tv.tv_usec = ((long) (mhd_timeout % 1000)) * 1000;
tvp = &tv;
}
else
tvp = NULL;
- if (-1 == select (max + 1, &rs, &ws, &es, tvp))
+ if (-1 == select ((int) max + 1, &rs, &ws, &es, tvp))
{
if (EINTR != errno)
abort ();
diff --git a/src/examples/querystring_example.c
b/src/examples/querystring_example.c
index 97a92ae2..50b62939 100644
--- a/src/examples/querystring_example.c
+++ b/src/examples/querystring_example.c
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007, 2008 Christian Grothoff (and other contributing
authors)
+ Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -21,6 +22,7 @@
* @brief example for how to get the query string from libmicrohttpd
* Call with an URI ending with something like "?q=QUERY"
* @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -43,6 +45,7 @@ ahc_echo (void *cls,
struct MHD_Response *response;
enum MHD_Result ret;
int resp_len;
+ size_t buf_size;
(void) cls; /* Unused. Silent compiler warning. */
(void) url; /* Unused. Silent compiler warning. */
(void) version; /* Unused. Silent compiler warning. */
@@ -62,18 +65,19 @@ ahc_echo (void *cls,
if (NULL == val)
return MHD_NO; /* No "q" argument was found */
resp_len = snprintf (NULL, 0, PAGE, "q", val);
- if (0 > resp_len)
+ if (0 >= resp_len)
return MHD_NO; /* Error calculating response size */
- me = malloc (resp_len + 1);
+ buf_size = (size_t) resp_len + 1; /* Add one byte for zero-termination */
+ me = malloc (buf_size);
if (me == NULL)
return MHD_NO; /* Error allocating memory */
- if (resp_len != snprintf (me, resp_len + 1, PAGE, "q", val))
+ if (resp_len != snprintf (me, buf_size, PAGE, "q", val))
{
free (me);
return MHD_NO; /* Error forming the response body */
}
response =
- MHD_create_response_from_buffer_with_free_callback (resp_len,
+ MHD_create_response_from_buffer_with_free_callback (buf_size - 1,
(void *) me,
&free);
if (response == NULL)
diff --git a/src/examples/refuse_post_example.c
b/src/examples/refuse_post_example.c
index 70cfe4b3..8a8eac37 100644
--- a/src/examples/refuse_post_example.c
+++ b/src/examples/refuse_post_example.c
@@ -33,14 +33,15 @@ struct handler_param
const char *askpage =
"<html><body>\n\
- Upload a file, please!<br>\n\
- <form action=\"/filepost\" method=\"post\"
enctype=\"multipart/form-data\">\n\
- <input name=\"file\" type=\"file\">\n\
- <input type=\"submit\" value=\" Send \"></form>\n\
- </body></html>";
+ Upload a file, please!<br>\n\
+ <form action=\"/filepost\" method=\"post\" enctype=\"multipart/form-data\">\n\
+ <input name=\"file\" type=\"file\">\n\
+ <input type=\"submit\" value=\" Send \"></form>\n\
+ </body></html>";
#define BUSYPAGE \
- "<html><head><title>Webserver busy</title></head><body>We are too busy to
process POSTs right now.</body></html>"
+ "<html><head><title>Webserver busy</title></head>" \
+ "<body>We are too busy to process POSTs right now.</body></html>"
static enum MHD_Result
ahc_echo (void *cls,
@@ -96,18 +97,25 @@ int
main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
-
struct handler_param data_for_handler;
+ int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
+ port = atoi (argv[1]);
+ if ( (1 > port) || (port > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
data_for_handler.response_page = askpage;
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, &data_for_handler,
MHD_OPTION_END);
if (d == NULL)
diff --git a/src/examples/suspend_resume_epoll.c
b/src/examples/suspend_resume_epoll.c
index 87ec6521..c85d9b7c 100644
--- a/src/examples/suspend_resume_epoll.c
+++ b/src/examples/suspend_resume_epoll.c
@@ -145,14 +145,22 @@ main (int argc,
struct epoll_event events_list[1];
struct Request *req;
uint64_t timer_expirations;
+ int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
+ port = atoi (argv[1]);
+ if ( (1 > port) || (port > 65535) )
+ {
+ fprintf (stderr,
+ "Port must be a number between 1 and 65535.\n");
+ return 1;
+ }
d = MHD_start_daemon (MHD_USE_EPOLL | MHD_ALLOW_SUSPEND_RESUME,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_NOTIFY_COMPLETED, &connection_done, NULL,
MHD_OPTION_END);
diff --git a/src/examples/upgrade_example.c b/src/examples/upgrade_example.c
index 547f1b6c..5b57d24e 100644
--- a/src/examples/upgrade_example.c
+++ b/src/examples/upgrade_example.c
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2016 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
* @file upgrade_example.c
* @brief example for how to use libmicrohttpd upgrade
* @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
*
* Telnet to the HTTP server, use this in the request:
* GET / http/1.1
@@ -71,11 +73,15 @@ send_all (MHD_socket sock,
size_t off;
make_blocking (sock);
- for (off = 0; off < len; off += ret)
+ for (off = 0; off < len; off += (size_t) ret)
{
ret = send (sock,
&buf[off],
+#if ! defined(_WIN32) || defined(__CYGWIN__)
len - off,
+#else /* Native W32 */
+ (int) (len - off),
+#endif /* Native W32 */
0);
if (0 > ret)
{
@@ -135,7 +141,7 @@ run_usock (void *cls)
break;
send_all (md->sock,
buf,
- got);
+ (size_t) got);
}
free (md);
MHD_upgrade_action (urh,
@@ -286,15 +292,18 @@ main (int argc,
char *const *argv)
{
struct MHD_Daemon *d;
+ unsigned int port;
- if (argc != 2)
+ if ( (argc != 2) ||
+ (1 != sscanf (argv[1], "%u", &port)) ||
+ (65535 < port) )
{
printf ("%s PORT\n", argv[0]);
return 1;
}
d = MHD_start_daemon (MHD_ALLOW_UPGRADE | MHD_USE_AUTO
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
- atoi (argv[1]),
+ (uint16_t) port,
NULL, NULL,
&ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (1b8c52f1 -> badf7560), gnunet, 2022/06/01
- [libmicrohttpd] 03/07: microhttpd.h: fixed doxy, gnunet, 2022/06/01
- [libmicrohttpd] 01/07: connection: muted compiler warning, gnunet, 2022/06/01
- [libmicrohttpd] 04/07: src/examples/*fileserver*.c: added error checking, gnunet, 2022/06/01
- [libmicrohttpd] 07/07: http_chunked_compression: fixed errors, gnunet, 2022/06/01
- [libmicrohttpd] 06/07: src/examples/demo{,_https}: added some error checking, fixed compiler warnings, gnunet, 2022/06/01
- [libmicrohttpd] 05/07: src/examples/benchmark{,_https}: simplified time calculation, gnunet, 2022/06/01
- [libmicrohttpd] 02/07: src/examples: muted compiler warnings,
gnunet <=