From d4935786c6d94f92324df724f74baad3a3f3971a Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 27 Nov 2024 21:47:46 +0100 Subject: [PATCH 1/5] post.php: format post length checks --- post.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/post.php b/post.php index 62b929d1..e9a8e926 100644 --- a/post.php +++ b/post.php @@ -955,16 +955,21 @@ if (isset($_POST['delete'])) { if (!$dropped_post) { // Check string lengths - if (mb_strlen($post['name']) > 35) + if (mb_strlen($post['name']) > 35) { error(sprintf($config['error']['toolong'], 'name')); - if (mb_strlen($post['email']) > 40) + } + if (mb_strlen($post['email']) > 40) { error(sprintf($config['error']['toolong'], 'email')); - if (mb_strlen($post['subject']) > 100) + } + if (mb_strlen($post['subject']) > 100) { error(sprintf($config['error']['toolong'], 'subject')); - if (!$mod && mb_strlen($post['body']) > $config['max_body']) + } + if (!$mod && mb_strlen($post['body']) > $config['max_body']) { error($config['error']['toolong_body']); - if (!$mod && substr_count($post['body'], "\n") >= $config['maximum_lines']) + } + if (!$mod && substr_count($post['body'], "\n") >= $config['maximum_lines']) { error($config['error']['toomanylines']); + } } wordfilters($post['body']); From dcd43b71dc795731f32dcf6768eac0ae488614b3 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 27 Nov 2024 21:55:39 +0100 Subject: [PATCH 2/5] config.php: add minimum body length option --- inc/config.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inc/config.php b/inc/config.php index 454cae4f..de6a8e35 100644 --- a/inc/config.php +++ b/inc/config.php @@ -578,6 +578,8 @@ $config['max_threads_per_hour'] = 30; // Maximum post body length. $config['max_body'] = 1800; + // Minimum post body length. + $config['min_body'] = 0; // Maximum number of lines allowed in a post. $config['maximum_lines'] = 100; // Maximum number of post body lines to show on the index page. From d0de1d82d380484d7a0b911783d89dcb4f508362 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 27 Nov 2024 21:56:03 +0100 Subject: [PATCH 3/5] post.php: add minimum body length check --- post.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/post.php b/post.php index e9a8e926..29fe5b6f 100644 --- a/post.php +++ b/post.php @@ -967,6 +967,9 @@ if (isset($_POST['delete'])) { if (!$mod && mb_strlen($post['body']) > $config['max_body']) { error($config['error']['toolong_body']); } + if (!$mod && $config['force_body'] && mb_strlen($post['body']) < $config['min_body']) { + error($config['error']['tooshort_body']); + } if (!$mod && substr_count($post['body'], "\n") >= $config['maximum_lines']) { error($config['error']['toomanylines']); } From 8773fbb52b6efd4d0a6ba760bbc310ceaa1f0c9d Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 27 Nov 2024 21:28:04 +0100 Subject: [PATCH 4/5] config.php: add op min and max body configuration options --- inc/config.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inc/config.php b/inc/config.php index de6a8e35..43bd7f69 100644 --- a/inc/config.php +++ b/inc/config.php @@ -576,6 +576,10 @@ // Maximum numbers of threads that can be created every hour on a board. $config['max_threads_per_hour'] = 30; + // Maximum OP body length. + $config['max_body_op'] = 1800; + // Minimum OP body length. Ignored if force_body_op is set to false. + $config['min_body_op'] = 0; // Maximum post body length. $config['max_body'] = 1800; // Minimum post body length. From d9b983a3fbc55c89e1f84376f57f11baa0328b8d Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 27 Nov 2024 22:12:51 +0100 Subject: [PATCH 5/5] post.php: check post body min and max op characters --- post.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/post.php b/post.php index 29fe5b6f..6d05594b 100644 --- a/post.php +++ b/post.php @@ -964,14 +964,26 @@ if (isset($_POST['delete'])) { if (mb_strlen($post['subject']) > 100) { error(sprintf($config['error']['toolong'], 'subject')); } - if (!$mod && mb_strlen($post['body']) > $config['max_body']) { - error($config['error']['toolong_body']); - } - if (!$mod && $config['force_body'] && mb_strlen($post['body']) < $config['min_body']) { - error($config['error']['tooshort_body']); - } - if (!$mod && substr_count($post['body'], "\n") >= $config['maximum_lines']) { - error($config['error']['toomanylines']); + if (!$mod) { + $body_mb_len = mb_strlen($post['body']); + $is_op = $post['op']; + + if (($is_op && $config['force_body_op']) || (!$is_op && $config['force_body'])) { + $min_body = $is_op ? $config['min_body_op'] : $config['min_body']; + + if ($body_mb_len < $min_body) { + error($config['error']['tooshort_body']); + } + } + + $max_body = $is_op ? $config['max_body_op'] : $config['max_body']; + if ($body_mb_len > $max_body) { + error($config['error']['toolong_body']); + } + + if (substr_count($post['body'], '\n') >= $config['maximum_lines']) { + error($config['error']['toomanylines']); + } } } wordfilters($post['body']);