Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Uncaught TypeError in viewforum_shortcodes.php #4929

Closed
theBlbDan opened this issue Dec 21, 2022 · 7 comments · Fixed by #4931
Closed

Fatal error: Uncaught TypeError in viewforum_shortcodes.php #4929

theBlbDan opened this issue Dec 21, 2022 · 7 comments · Fixed by #4931
Labels
plugin: forum type: bug A problem that should not be happening

Comments

@theBlbDan
Copy link

Bug Description

When I apply a custom user class, i.e. a non fixed class, to a forum, it generates a Fatal error: Uncaught TypeError

Fatal error: Uncaught TypeError: Illegal offset type in isset or empty in /usr/www/public_html/e107_handlers/userclass_class.php:108 Stack trace: #0 /usr/www/public_html/e107_plugins/forum/shortcodes/batch/viewforum_shortcodes.php(245): user_class->getFixedClassDescription() #1 /usr/www/public_html/e107_handlers/shortcode_handler.php(1154): plugin_forum_viewforum_shortcodes->sc_viewable_by() #2 [internal function]: e_parse_shortcode->doCode() #3 /usr/www/public_html/e107_handlers/shortcode_handler.php(1020): preg_replace_callback() #4 /usr/www/public_html/e107_handlers/e_parse_class.php(848): e_parse_shortcode->parseCodes() #5 /usr/www/public_html/e107_plugins/forum/forum_viewforum.php(445): e_parse->parseTemplate() #6 /usr/www/public_html/e107_plugins/forum/forum_viewforum.php(56): forum_viewforum_front->init() #7 /usr/www/public_html/e107_plugins/forum/forum_viewforum.php(565): forum_viewforum_front->__construct() #8 /usr/www/public_html/index.php(69): include_once('...') #9 {main} thrown in /usr/www/public_html/e107_handlers/userclass_class.php on line 108

How to Reproduce

Steps to reproduce the behavior:

  1. Create a standard user class
  2. Add this class to a user
  3. Apply this class to the 'Visibility' of a forum and then visit this forum as above mentioned user
  4. You should get a similar stack trace as shown above.

Expected Behavior

Well, I kinda expect to apply custom user classes to forums to limit their visibility. It appears that in ./e107_plugins/forum/shortcodes/batch/viewforum_shortcodes.php(), it is passing an array which clearly won't work.

Server Information

PHP Operating System

Linux hosted5 5.15.82 #1 SMP Sat Dec 10 23:29:08 PST 2022 x86_64

PHP Version

PHP Version 8.1.12

PHP Modules

apache2handler
apcu
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imagick
imap
intl
ionCube Loader
json
ldap
libxml
mbstring
mcrypt
mysqli
mysqlnd
odbc
openssl
pcre
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
pspell
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
ssh2
standard
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

@theBlbDan theBlbDan added the type: bug A problem that should not be happening label Dec 21, 2022
@Jimmi08
Copy link
Contributor

Jimmi08 commented Dec 23, 2022

I can't confirm. PHP 8.1.4, latest e107 (2,3,3git), no issue.

@Moc
Copy link
Member

Moc commented Dec 24, 2022

@theBlbDan which version of e107 are you using?

It may very well be that this issue is already resolved in the latest update. Please try updating from Github before we look into this issue more closely.

Please always make a backup of you website (files and database) before updating.

There is an easy way to sync with Github:

  • Enable developer mode in Admin Area > Preferences > Advanced features
  • Go to Admin Area > Tools > Database > Sync with Github
  • Press the Overwrite files button and wait until the process has finished.

Alternatively you can download the ZIP file with all the latest files included by hitting the green 'Clone or download' button at the top of this page: https://github.com/e107inc/e107

@Deltik Deltik added the status: pending This issue is being worked on or is in the backlog to be fixed. label Dec 24, 2022
@Deltik
Copy link
Member

Deltik commented Dec 24, 2022

I was able to reproduce the bug on the latest revision of e107 (ec68c8891 at the time of writing) using the provided instructions. Here's my stack trace, which is basically the same:

[Sat Dec 24 15:52:34.954293 2022] [php:error] [pid 152691] [client 10.64.229.1:55854] PHP Fatal error:  Uncaught TypeError: Illegal offset type in isset or empty in /var/www/html/e107/e107_handlers/userclass_class.php:108
Stack trace:
#0 /var/www/html/e107/e107_plugins/forum/shortcodes/batch/viewforum_shortcodes.php(245): user_class->getFixedClassDescription()
#1 /var/www/html/e107/e107_handlers/shortcode_handler.php(1154): plugin_forum_viewforum_shortcodes->sc_viewable_by()
#2 [internal function]: e_parse_shortcode->doCode()
#3 /var/www/html/e107/e107_handlers/shortcode_handler.php(1020): preg_replace_callback()
#4 /var/www/html/e107/e107_handlers/e_parse_class.php(848): e_parse_shortcode->parseCodes()
#5 /var/www/html/e107/e107_plugins/forum/forum_viewforum.php(445): e_parse->parseTemplate()
#6 /var/www/html/e107/e107_plugins/forum/forum_viewforum.php(56): forum_viewforum_front->init()
#7 /var/www/html/e107/e107_plugins/forum/forum_viewforum.php(565): forum_viewforum_front->__construct()
#8 /var/www/html/e107/index.php(69): include_once('...')
#9 {main}
  thrown in /var/www/html/e107/e107_handlers/userclass_class.php on line 108, referer: http://10.64.229.116/e107/forum

@Deltik
Copy link
Member

Deltik commented Dec 24, 2022

In ./e107_handlers/userclass_class.php at this line, my $id is the following value:

array (
  0 => 
  array (
    'user_id' => '4',
    'user_name' => 'newuser',
    'user_class' => '248,3,6',
  ),
)

But $this->fixed_classes only has these:

array (
  0 => 'Everyone (public)',
  252 => 'Guests',
  255 => 'No One (inactive)',
  253 => 'Members',
  254 => 'Admin',
  250 => 'Main Admin',
  251 => 'Read Only',
  247 => 'New Users',
  246 => 'Search Bots',
)

Judging from the name user_class::getFixedClassDescription(), the client usage in plugin_forum_viewforum_shortcodes::sc_viewable_by() is passing in the wrong data.

@theBlbDan
Copy link
Author

theBlbDan commented Dec 25, 2022

@Moc

theBlbDan which version of e107 are you using?
I'm sorry, I don't know why I didn't provide this already.
Full download fresh install from the e107 site. Version 2.3.2

It may very well be that this issue is already resolved in the latest update. Please try updating from Github before we look into this issue more closely.

Please always make a backup of you website (files and database) before updating.

There is an easy way to sync with Github:

  • Enable developer mode in Admin Area > Preferences > Advanced features
  • Go to Admin Area > Tools > Database > Sync with Github
  • Press the Overwrite files button and wait until the process has finished.

I will give this a try when I get back from Christmas break.

Thanks.

@Moc
Copy link
Member

Moc commented Dec 25, 2022

@theBlbDan No worries! Enjoy the Christmas break.

It looks like the bug can be reproduced anyhow. So it still has to be fixed.

@Deltik
Copy link
Member

Deltik commented Dec 25, 2022

The bug comes from 2dedb86b#diff-d8b2fba5d26ab6acc066765263788bb9005d4d98e7de39b04d888dce1781603dR151-R154, where there's a different return type (string) in the same method that returns an array of structures like this:

array (
  0 => 
  array (
    'user_id' => '4',
    'user_name' => 'newuser',
    'user_class' => '248,3,6',
  ),
)

Deltik added a commit to Deltik/e107 that referenced this issue Dec 25, 2022
…Members()`

Also, `e107forum::getForumClassMembers()` is now documented and
deprecated because it has unintuitive return values.

Fixes: e107inc#4929
CaMer0n added a commit that referenced this issue Dec 26, 2022
Fixes #4929: Fix type mismatch in usage of `e107forum::getForumClassMembers()`
@Deltik Deltik removed the status: pending This issue is being worked on or is in the backlog to be fixed. label Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: forum type: bug A problem that should not be happening
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants