News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Trying to access array offset on value of type null in Subs-Post.php

Started by sah62, February 28, 2021, 06:35:42 AM

Previous topic - Next topic

sah62

I'm running PHP 2.0.18 with PHP 7.4. I'm seeing this error in my admin log when the mail queue is processed:


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


Here's the code:


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 }


Why would the global $txt variable be null and not an array? It's easy enough to check the value of $txt (if is_array($txt)...) to avoid the error, but what would be the right thing to do if it's null?

sah62

This error doesn't appear when I process the mail queue manually from the admin interface. It only happens when the mail queue is processed as a scheduled task.

shawnb61

It is trying (and failing) to tell you thrre is a problem with your mail configuration.

Double-check your mail settings.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

sah62

My mail configuration is fine. What's getting me here is an SMTP delivery failure due to a bad recipient email address in a private message notification. The reason for the error is that the value of the $txt variable is null.

Shambles

I'd try lowering your version of PHP to 7.3 and retry the mail test.

sah62

That would eliminate the notice, but the issue with the code will remain if running PHP 7.4 or later.

I'm going to mark this as solved. It's a bug associated with a backwards-incompatible change made by PHP 7.4. The only way to really address the issue is to change the code.

Shambles

^ agree with your comment.

My recommendation to lower to 7.3 was to prove the cause, not provide the solution ;)

shawnb61

Quote from: sah62 on February 28, 2021, 10:47:14 AM
My mail configuration is fine. What's getting me here is an SMTP delivery failure due to a bad recipient email address in a private message notification. The reason for the error is that the value of the $txt variable is null.

You are correct, it appears the $txt error string is not getting loaded.  And yes, prior to 7.4, those failures were silent & now they're not...  Internally logged as #216

I have never seen a bad email address result in a real-time kickback like that.  I have only seen credential problems or email server problems do so.   Bad emails normally result in email notifications to your inbox.  Something must be pretty bad for it to do that.

I would stick with 7.4 unless you're getting thousands of these.  And find/fix the bad email address.

Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Advertisement: