mailwatch / MailWatch

MailWatch for MailScanner is a web-based front-end to MailScanner
http://mailwatch.org/
GNU General Public License v2.0
115 stars 66 forks source link

"Illegal argument to regular expression" Error in file 'rep_message_listing.php' (if MySql 8.x is used) #1295

Closed jensd0e closed 6 months ago

jensd0e commented 6 months ago

Issue summary

On the page detail.php: clicking the 'Spam' checkbox to open rep_message_listing.php, a fatal error is thrown that stops the page from loading anything after the call to db_colorised_table().

Steps to reproduce

  1. Open details for a message to get to details.php
  2. Click the 'Spam' checkbox.
  3. rep_messages_listing.php loads the header information but displays no result.

Expected result

Show a table with information.

Actual result

HTTP Error log: [Wed Jan 10 10:18:41.494527 2024] [php7:error] [pid 1133123] [client :19041] PHP Fatal error: Uncaught mysqlisql exception: Illegal argument to a regular expression. in /var/www/html/mailscanner/functions.php:1051Stack trace:\n#0 /var/www/ht ml/mailscanner/functions.php(1051): mysqli->query('SELECT COUNT()...')\n#1 /var/www/html/mailscanner/functions.php(2019): dbquery ('SELECT COUNT()...')\n#2 /var/www/html/mailscanner/functions.php(2088): generatePager('\n SELECT\n id A...')\n#3 /var/www/htm l/mailscanner/rep_message_listing.php(125): db_colorised_table('\n SELECT\n id A...', 'Message Listing', true, true)\n#4 {main} \n thrown in /var/www/html/mailscanner/functions.php on line 1051, referer: https://redacted.com/mailscanner/detail.php?token=&id=

Installation

I'm using MailWatch & MailScanner latest Versions on Debian 11 with PHP 7.3 & MySQL 8.0.33

Proposed Fix

In MySQL 8.0.4 and above, regex implementation changed. See https://dev.mysql.com/doc/refman/8.0/en/regexp.html#regexp-compatibility In my case, I simply changed '[[:<:]]' and '[[:>:]]' with '\b'. rep_message_listing.php, line 102 before: $relay_regex = '[[:<:]]' . str_replace('.', '.', deepSanitizeInput($_GET['relay'], 'url')) . '[[:>:]]'; Line 102 fixed: $relay_regex = '\b' . str_replace('.', '.', deepSanitizeInput($_GET['relay'], 'url')) . '\b';