Simple Machines Community Forum

SMF Development => Bug Reports => Fixed or Bogus Bugs => Topic started by: sah62 on February 28, 2021, 02:14:49 PM

Title: [2.0.18] Trying to access array offset on value of type null in Subs-Post.php
Post by: sah62 on February 28, 2021, 02:14:49 PM
I'm running SMF 2.0.18, PHP 7.4, and nginx/1.18.0 (Ubuntu) . I'm seeing these two errors in my error log when the mail queue is processed as part of a scheduled task:

Quote
https://www.mysite.org/forum/index.php?scheduled=mailq;ts=1614539134
450 4.1.2 <user_name@example.com>: Recipient address rejected: Domain not found

Quote
https://www.mysite.org/forum/index.php?scheduled=mailq;ts=1614539134
8: Trying to access array offset on value of type null
File: /var/www/mysite/web/forum/Sources/Subs-Post.php
Line: 1452

The SMTP error is produced because the forum user's email address is invalid and the email can't be delivered. It's a legitimate error that the user needs to address by updating the email address associated with their forum profile.

Here's the code from Subs-Post.php:


1428 // Parse a message to the SMTP server.
1429 function server_parse($message, $socket, $response)
1430 {
1431         global $txt;
1432
1433         if ($message !== null)
1434                 fputs($socket, $message . "\r\n");
1435
1436         // No response yet.
1437         $server_response = '';
1438
1439         while (substr($server_response, 3, 1) != ' ')
1440                 if (!($server_response = fgets($socket, 256)))
1441                 {
1442                         // !!! Change this message to reflect that it may mean bad user/password/server issues/etc.
1443                         log_error($txt['smtp_bad_response']);
1444                         return false;
1445                 }
1446
1447         if ($response === null)
1448                 return substr($server_response, 0, 3);
1449
1450         if (substr($server_response, 0, 3) != $response)
1451         {
1452                 log_error($txt['smtp_error'] . $server_response);
1453                 return false;
1454         }
1455
1456         return true;
1457 }


I'm using the default theme with English language text. To reproduce this error, enqueue a message and process the queue as part of a scheduled task. The error does not occur when the queue is processed manually as part of a logged-in administrator session.

PHP 7.4 includes a backwards-incompatible change associated with trying to use values of type null, bool, int, float or resource as an array as described here:

https://www.php.net/manual/en/migration74.incompatible.php

Is it correct to assume that the index.english.php file doesn't get loaded as part of running a scheduled task and the $txt array is never initialized with values? If so, that would explain the error. $txt is null, and the attempt to reference $txt['smtp_error'] causes the error to be raised and the notice logged. It seems to be harmless beyond the failure to include the value of $txt['smtp_error'] in the logged error message and the extra notice being logged.
Title: Re: [2.0.18] Trying to access array offset on value of type null in Subs-Post.php
Post by: live627 on March 01, 2021, 01:40:29 PM
QuoteIs it correct to assume that the index.english.php file doesn't get loaded as part of running a scheduled task and the $txt array is never initialized with values?
yeah, seems like it. I think that whoever wrote the task scheduler thought teat tasks would never need any languages. Actually the  task runner doesn't load much and thus produces random errors that we had to duct-tape fix.
Title: Re: [2.0.18] Trying to access array offset on value of type null in Subs-Post.php
Post by: shawnb61 on March 01, 2021, 01:49:27 PM
#216