Skip to content

Commit 957b3c0

Browse files
committedFeb 25, 2013
Fix crash when report_bug_threshold=array in access_has_bug_level
When displaying a bug for which the user is not the reporter, $g_limit_reporters=ON and the workflow is set so report_bug_threshold is an array, MantisBT crashes with "PHP Fatal error: Unsupported operand types". This is due to use of '+ 1' to indicate that user should have the next higher access level to view the issue. We now use the same logic but within a foreach loop to check against each array element. Fixes #15538
1 parent b41b528 commit 957b3c0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎core/access_api.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,20 @@ function access_has_bug_level( $p_access_level, $p_bug_id, $p_user_id = null ) {
417417
# reporters can view just issues they reported
418418
$t_limit_reporters = config_get( 'limit_reporters', null, $p_user_id, $t_project_id );
419419
$t_report_bug_threshold = config_get( 'report_bug_threshold', null, $p_user_id, $t_project_id );
420-
if ( $t_limit_reporters && !bug_is_user_reporter( $p_bug_id, $p_user_id ) && !access_has_project_level( $t_report_bug_threshold + 1, $t_project_id, $p_user_id ) ) {
421-
return false;
420+
if( !is_array( $t_report_bug_threshold ) ) {
421+
$t_report_bug_threshold = array( $t_report_bug_threshold );
422+
}
423+
if( $t_limit_reporters && !bug_is_user_reporter( $p_bug_id, $p_user_id ) ) {
424+
$t_has_access = false;
425+
foreach( $t_report_bug_threshold as $t_threshold ) {
426+
if( access_has_project_level( $t_threshold + 1, $t_project_id, $p_user_id ) ) {
427+
$t_has_access = true;
428+
break;
429+
}
430+
}
431+
if( !$t_has_access ) {
432+
return false;
433+
}
422434
}
423435

424436
# If the bug is private and the user is not the reporter, then

2 commit comments

Comments
 (2)

atrol commented on Feb 25, 2013

@atrol
Member

Proposal for better performance in standard configuration ($g_limit_reporters = OFF;)

The following code must not always be executed:

    $t_report_bug_threshold = config_get( 'report_bug_threshold', null, $p_user_id, $t_project_id );
    if( !is_array( $t_report_bug_threshold ) ) {
        $t_report_bug_threshold = array( $t_report_bug_threshold );
    }

Placing the code after line

if( $t_limit_reporters && !bug_is_user_reporter( $p_bug_id, $p_user_id ) ) {

should work

dregad commented on Feb 26, 2013

@dregad
MemberAuthor

Thanks, I was actually thinking about optimizing this on the way back home yesterday, and also a way to avoid looping on all array elements which is not always necessary if we know the access level. I'll do a follow-up commit later on.

Please sign in to comment.