Skip to content

Commit 79fc861

Browse files
committedAug 17, 2012
Bugnote '~' processing may produce error if bug does not exist
This error case is a bit far-fetched, and should normally not occur unless there is some data corruption. If referencing an existing bugnote whose parent bug is not in the database, the callback function cannot retrieve the project_id, so error 403 is triggered. The callback functions have also been reformatted for better readability Fixes #12580
1 parent 86abb9c commit 79fc861

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed
 

‎core/string_api.php

+47-28
Original file line numberDiff line numberDiff line change
@@ -401,35 +401,54 @@ function string_process_bugnote_link( $p_string, $p_include_anchor = true, $p_de
401401

402402
if( !isset( $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] ) ) {
403403
if( $p_include_anchor ) {
404-
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function( '$p_array', '
405-
if ( bugnote_exists( (int)$p_array[2] ) ) {
406-
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
407-
$g_project_override = bug_get_field( $t_bug_id, \'project_id\' );
408-
if ( bug_exists( $t_bug_id ) && ( access_compare_level( user_get_access_level( auth_get_current_user_id(), bug_get_field( $t_bug_id, \'project_id\' ) ), config_get( \'private_bugnote_threshold\' ) ) || ( bugnote_get_field( (int)$p_array[2], \'reporter_id\' ) == auth_get_current_user_id() ) || bugnote_get_field( (int)$p_array[2], \'view_state\' ) == VS_PUBLIC ) ) {
409-
$g_project_override = null;
410-
return $p_array[1] . string_get_bugnote_view_link( $t_bug_id, (int)$p_array[2], null, ' . ( $p_detail_info ? 'true' : 'false' ) . ', ' . ( $p_fqdn ? 'true' : 'false' ) . ' );
411-
} else {
412-
$g_project_override = null;
413-
return $p_array[0];
414-
}
415-
} else {
416-
return $p_array[0];
417-
}
418-
' );
404+
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] =
405+
create_function( '$p_array',
406+
'
407+
if ( bugnote_exists( (int)$p_array[2] ) ) {
408+
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
409+
if ( bug_exists( $t_bug_id ) ) {
410+
$g_project_override = bug_get_field( $t_bug_id, \'project_id\' );
411+
if ( access_compare_level(
412+
user_get_access_level( auth_get_current_user_id(),
413+
bug_get_field( $t_bug_id, \'project_id\' ) ),
414+
config_get( \'private_bugnote_threshold\' )
415+
)
416+
|| bugnote_get_field( (int)$p_array[2], \'reporter_id\' ) == auth_get_current_user_id()
417+
|| bugnote_get_field( (int)$p_array[2], \'view_state\' ) == VS_PUBLIC
418+
) {
419+
$g_project_override = null;
420+
return $p_array[1] .
421+
string_get_bugnote_view_link(
422+
$t_bug_id,
423+
(int)$p_array[2],
424+
null,
425+
' . ( $p_detail_info ? 'true' : 'false' ) . ', ' . ( $p_fqdn ? 'true' : 'false' ) . '
426+
);
427+
}
428+
$g_project_override = null;
429+
}
430+
}
431+
return $p_array[0];
432+
'
433+
);
419434
} else {
420-
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = create_function( '$p_array', '
421-
# We might as well create the link here even if the bug
422-
# doesnt exist. In the case above we dont want to do
423-
# the summary lookup on a non-existant bug. But here, we
424-
# can create the link and by the time it is clicked on, the
425-
# bug may exist.
426-
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
427-
if ( bug_exists( $t_bug_id ) ) {
428-
return $p_array[1] . string_get_bugnote_view_url_with_fqdn( $t_bug_id, (int)$p_array[2], null );
429-
} else {
430-
return $p_array[0];
431-
}
432-
' );
435+
$string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] =
436+
create_function(
437+
'$p_array',
438+
'
439+
# We might as well create the link here even if the bug
440+
# doesnt exist. In the case above we dont want to do
441+
# the summary lookup on a non-existant bug. But here, we
442+
# can create the link and by the time it is clicked on, the
443+
# bug may exist.
444+
$t_bug_id = bugnote_get_field( (int)$p_array[2], \'bug_id\' );
445+
if ( bug_exists( $t_bug_id ) ) {
446+
return $p_array[1] . string_get_bugnote_view_url_with_fqdn( $t_bug_id, (int)$p_array[2], null );
447+
} else {
448+
return $p_array[0];
449+
}
450+
'
451+
);
433452
}
434453
}
435454
$p_string = preg_replace_callback( '/(^|[^\w])' . preg_quote( $t_tag, '/' ) . '(\d+)\b/', $string_process_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn], $p_string );

0 commit comments

Comments
 (0)
Please sign in to comment.