aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2023-06-14 13:46:54 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2023-06-20 23:22:56 +0300
commitc1b6751c11314d046c87ea83ef611d95c44e2be7 (patch)
treef7a4e5802d08544a7195bb67295af84001c0948f
parent5a9f64bc6a497a41f0cbcd80ee883e0747c08a98 (diff)
downloadlibmicrohttpd-c1b6751c11314d046c87ea83ef611d95c44e2be7.tar.gz
libmicrohttpd-c1b6751c11314d046c87ea83ef611d95c44e2be7.zip
Added checks for correct values specified for connection memory limits
-rw-r--r--src/include/microhttpd.h6
-rw-r--r--src/microhttpd/daemon.c31
2 files changed, 35 insertions, 2 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 4976b071..8745367c 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -96,7 +96,7 @@ extern "C"
96 * they are parsed as decimal numbers. 96 * they are parsed as decimal numbers.
97 * Example: 0x01093001 = 1.9.30-1. 97 * Example: 0x01093001 = 1.9.30-1.
98 */ 98 */
99#define MHD_VERSION 0x00097702 99#define MHD_VERSION 0x00097703
100 100
101/* If generic headers don't work on your platform, include headers 101/* If generic headers don't work on your platform, include headers
102 which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', 'off_t', 102 which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', 'off_t',
@@ -1626,6 +1626,7 @@ enum MHD_OPTION
1626 * Values above 128k are unlikely to result in much benefit, as half 1626 * Values above 128k are unlikely to result in much benefit, as half
1627 * of the memory will be typically used for IO, and TCP buffers are 1627 * of the memory will be typically used for IO, and TCP buffers are
1628 * unlikely to support window sizes above 64k on most systems. 1628 * unlikely to support window sizes above 64k on most systems.
1629 * Values below 64 bytes are completely unusable.
1629 */ 1630 */
1630 MHD_OPTION_CONNECTION_MEMORY_LIMIT = 1, 1631 MHD_OPTION_CONNECTION_MEMORY_LIMIT = 1,
1631 1632
@@ -1864,7 +1865,8 @@ enum MHD_OPTION
1864 1865
1865 /** 1866 /**
1866 * Increment to use for growing the read buffer (followed by a 1867 * Increment to use for growing the read buffer (followed by a
1867 * `size_t`). Must fit within #MHD_OPTION_CONNECTION_MEMORY_LIMIT. 1868 * `size_t`).
1869 * Must not be higher than 1/4 of #MHD_OPTION_CONNECTION_MEMORY_LIMIT.
1868 */ 1870 */
1869 MHD_OPTION_CONNECTION_MEMORY_INCREMENT = 21, 1871 MHD_OPTION_CONNECTION_MEMORY_INCREMENT = 21,
1870 1872
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index f310e1c7..c403d02b 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -6250,10 +6250,41 @@ parse_options_va (struct MHD_Daemon *daemon,
6250 case MHD_OPTION_CONNECTION_MEMORY_LIMIT: 6250 case MHD_OPTION_CONNECTION_MEMORY_LIMIT:
6251 daemon->pool_size = va_arg (ap, 6251 daemon->pool_size = va_arg (ap,
6252 size_t); 6252 size_t);
6253 if (64 > daemon->pool_size)
6254 {
6255#ifdef HAVE_MESSAGES
6256 MHD_DLOG (daemon,
6257 _ ("Warning: specified MHD_OPTION_CONNECTION_MEMORY_LIMIT " \
6258 "value is too small and rounded up to 64.\n"));
6259#endif /* HAVE_MESSAGES */
6260 daemon->pool_size = 64;
6261 }
6262 if (daemon->pool_size / 4 < daemon->pool_increment)
6263 daemon->pool_increment = daemon->pool_size / 4;
6253 break; 6264 break;
6254 case MHD_OPTION_CONNECTION_MEMORY_INCREMENT: 6265 case MHD_OPTION_CONNECTION_MEMORY_INCREMENT:
6255 daemon->pool_increment = va_arg (ap, 6266 daemon->pool_increment = va_arg (ap,
6256 size_t); 6267 size_t);
6268 if (0 == daemon->pool_increment)
6269 {
6270#ifdef HAVE_MESSAGES
6271 MHD_DLOG (daemon,
6272 _ ("The MHD_OPTION_CONNECTION_MEMORY_INCREMENT value " \
6273 "cannot be zero.\n"));
6274#endif /* HAVE_MESSAGES */
6275 return MHD_NO;
6276 }
6277 if (daemon->pool_size / 4 < daemon->pool_increment)
6278 {
6279#ifdef HAVE_MESSAGES
6280 MHD_DLOG (daemon,
6281 _ ("Warning: specified " \
6282 "MHD_OPTION_CONNECTION_MEMORY_INCREMENT value is too " \
6283 "large and rounded down to 1/4 of " \
6284 "MHD_OPTION_CONNECTION_MEMORY_LIMIT.\n"));
6285#endif /* HAVE_MESSAGES */
6286 daemon->pool_increment = daemon->pool_size / 4;
6287 }
6257 break; 6288 break;
6258 case MHD_OPTION_CONNECTION_LIMIT: 6289 case MHD_OPTION_CONNECTION_LIMIT:
6259 daemon->connection_limit = va_arg (ap, 6290 daemon->connection_limit = va_arg (ap,