Current time: 05-24-2012, 11:01 AM Hello There, Guest! (LoginRegister)


 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[F] Moderators cache - array_merge() reindex bug
09-15-2008, 09:54 AM (This post was last modified: 09-18-2008 01:16 PM by Ryan Gordon.)
Post: #1
[F] Moderators cache - array_merge() reindex bug
MyBB 1.4.1, PHP 5.2.4

I have found that logged regular user is made a moderator while accessing forums main page (he can see reported posts). In inc/functions.php I have added a debug message to is_moderator() function:
PHP Code:
            $modcache $cache->read('moderators');
            if(!empty(
$modcache))
            {
                foreach(
$modcache as $modusers)
                {
                    if(isset(
$modusers[$uid]) && $modusers[$uid]['mid'])
                    {
                        
print_r($modusers[$uid]) ;
                        return 
true;
                    }
                }
            }
            return 
false
and it printed:
Code:
Array
(
    [mid] => 89
    [fid] => 32
    [uid] => 30
    [caneditposts] => 1
    [candeleteposts] => 1
    [canviewips] => 1
    [canopenclosethreads] => 1
    [canmanagethreads] => 1
    [canmovetononmodforum] => 1
    [username] => Amandi
    [usergroup] => 6
    [displaygroup] => 15
)


The problem is that this users UID is 2 (not 30) and his username - koziolek (not "Amandi"). It seems that problem lies in array_merge which reindex the keys. Look at file inc/class_datacache.php in function build_moderators():
PHP Code:
                    // Append - local settings override that of a parent - array_merge works here
                    
if($this->moderators[$forum['fid']])
                    {
                        if(
is_array($forum_mods))
                        {
                            
print_r($forum_mods) ; // DEBUG
                            
print_r($this->moderators[$forum['fid']]) ; // DEBUG
                            
$forum_mods array_merge($forum_mods$this->moderators[$forum['fid']]);
                            
print_r($forum_mods) ; // DEBUG
                        
}
                        else
                        {
                            
$forum_mods $this->moderators[$forum['fid']];
                        }
                    } 

Debug print_r() shows:
Code:
$forum_mods - before array_merge():
Array
(
    [1] => Array
        (
            [mid] => 1
            [fid] => 1
            [uid] => 1
            [caneditposts] => 1
            [candeleteposts] => 1
            [canviewips] => 1
            [canopenclosethreads] => 1
            [canmanagethreads] => 1
            [canmovetononmodforum] => 1
            [username] => admin
            [usergroup] => 4
            [displaygroup] => 0
        )

)
$this->moderators[$forum['fid']] - before array_merge():
Array
(
    [12780] => Array
        (
            [mid] => 151
            [fid] => 35
            [uid] => 12780
            [caneditposts] => 1
            [candeleteposts] => 1
            [canviewips] => 1
            [canopenclosethreads] => 1
            [canmanagethreads] => 1
            [canmovetononmodforum] => 1
            [username] => m.pÅ‚ochocki
            [usergroup] => 8
            [displaygroup] => 0
        )

    [11377] => Array
        (
            [mid] => 149
            [fid] => 35
            [uid] => 11377
            [caneditposts] => 1
            [candeleteposts] => 1
            [canviewips] => 1
            [canopenclosethreads] => 1
            [canmanagethreads] => 1
            [canmovetononmodforum] => 1
            [username] => p.bijata
            [usergroup] => 8
            [displaygroup] => 0
        )

)

$forum_mods - after array_merge() - look at array keys:
Array
(
    [0] => Array
        (
            [mid] => 1
            [fid] => 1
            [uid] => 1
            [caneditposts] => 1
            [candeleteposts] => 1
            [canviewips] => 1
            [canopenclosethreads] => 1
            [canmanagethreads] => 1
            [canmovetononmodforum] => 1
            [username] => admin
            [usergroup] => 4
            [displaygroup] => 0
        )

    [1] => Array
        (
            [mid] => 151
            [fid] => 35
            [uid] => 12780
            [caneditposts] => 1
            [candeleteposts] => 1
            [canviewips] => 1
            [canopenclosethreads] => 1
            [canmanagethreads] => 1
            [canmovetononmodforum] => 1
            [username] => m.pÅ‚ochocki
            [usergroup] => 8
            [displaygroup] => 0
        )

    [2] => Array
        (
            [mid] => 149
            [fid] => 35
            [uid] => 11377
            [caneditposts] => 1
            [candeleteposts] => 1
            [canviewips] => 1
            [canopenclosethreads] => 1
            [canmanagethreads] => 1
            [canmovetononmodforum] => 1
            [username] => p.bijata
            [usergroup] => 8
            [displaygroup] => 0
        )

)

www.kozik.net.pl
- So... Maybe you shouldn't have hacked it.
- And why don't you try not breathing. Hurts, dunnit. (userfriendly.org)
Visit this user's website Find all posts by this user
09-15-2008, 11:45 PM
Post: #2
RE: Moderators cache - array_merge() reindex bug
Reproduction instructions? I can't seem to reproduce.
Visit this user's website Find all posts by this user
09-16-2008, 07:25 AM
Post: #3
RE: Moderators cache - array_merge() reindex bug
It was just an upgrade from 1.2 to 1.4.1. I tested it on two different regular users (which existed before upgrade) and both has the same problem.

You can add debug instructions to build_moderators() and rebuild moderators cache.

www.kozik.net.pl
- So... Maybe you shouldn't have hacked it.
- And why don't you try not breathing. Hurts, dunnit. (userfriendly.org)
Visit this user's website Find all posts by this user
09-16-2008, 04:22 PM
Post: #4
RE: Moderators cache - array_merge() reindex bug
I can't reproduce - that's why I asked.
Visit this user's website Find all posts by this user
09-17-2008, 01:34 PM
Post: #5
RE: Moderators cache - array_merge() reindex bug
array_merge() (tested in PHP 5.2.4 and PHP 5.2.6-pl6-gentoo) reindex numeric keys in resulting array. Simple test for command line:
PHP Code:
<?php
$a 
= array(=> 'a') ;
$b = array(=> 'b'30 => 'c') ;

print_r(array_merge($a$b)) ;
?>
Result:
Code:
Array
(
    [0] => a
    [1] => b
    [2] => c
)
So in function build_moderators() array $forum_mods is reindexed by array_merge().

I do not know how to give a reproduction instructions if the code above does not work Smile... Anyway a fix is:
PHP Code:
$forum_mods $forum_mods $this->moderators[$forum['fid']]; 
Arrays are added without key reindex - this fixes moderators cache. At least mine Wink .

www.kozik.net.pl
- So... Maybe you shouldn't have hacked it.
- And why don't you try not breathing. Hurts, dunnit. (userfriendly.org)
Visit this user's website Find all posts by this user
09-18-2008, 01:18 PM
Post: #6
RE: [F] Moderators cache - array_merge() reindex bug
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.

With regards,
MyBB Group
Visit this user's website Find all posts by this user


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication