Add more DDoS prevention. - bitreich-httpd - Bitreich HTTPD service
(HTM) git clone git://bitreich.org/bitreich-httpd git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/bitreich-httpd
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit bf9101e0e7efc8918d6122efef1339ac12b25b63
(DIR) parent e5dfc5fbfe93266da5edb1bb2e903734738296cf
(HTM) Author: Christoph Lohmann <20h@r-36.net>
Date: Tue, 22 Aug 2023 07:11:56 +0200
Add more DDoS prevention.
Diffstat:
M bitreich-httpd.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/bitreich-httpd.c b/bitreich-httpd.c
@@ -138,7 +138,7 @@ main(int argc, char *argv[])
char *wwwbase, *wwwindex, *request, *ctype, *path, *le_file,
*le_base, clienth[NI_MAXHOST], clientp[NI_MAXSERV], *zuccbase,
*requested, *header, *headerval, *hosthdr;
- int rlen;
+ int rlen, i;
struct sockaddr_storage clt;
socklen_t cltlen = sizeof(clt);
time_t tim;
@@ -170,9 +170,10 @@ main(int argc, char *argv[])
request[rlen-1] = '\0';
/* Header parsing. */
- for (;;) {
+ /* At max read 16 headers. Do not allow DDoS. */
+ for (i = 0; i < 16; i++) {
header = read_line(0, &rlen, 512);
- if (header == NULL)
+ if (header == NULL || rlen == 0)
break;
if (header[rlen-1] == '\r') {
header[rlen-1] = '\0';