Skip to content

Commit 6f76cf6

Browse files
committedAug 21, 2012
Protect $g_default_category_for_moves from deletion
When a category defined as default_category_for_moves is deleted and an issue is subsequently moved to another project where its current category does not exist, it gets assigned a non-existing category. This causes application error 1502 to be triggered whenever MantisBT tries to display the issue's Category, which can cause a system lock up. This commit reduces the risk of this situation from happening, by preventing users from deleting categories which are used as default (either defined in config_inc.php or in the config table). Fixes #14478
1 parent 79fc861 commit 6f76cf6

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
 

‎core/constant_inc.php

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@
317317
define( 'ERROR_CATEGORY_NO_ACTION', 1501 );
318318
define( 'ERROR_CATEGORY_NOT_FOUND', 1502 );
319319
define( 'ERROR_CATEGORY_NOT_FOUND_FOR_PROJECT', 1503 );
320+
define( 'ERROR_CATEGORY_CANNOT_DELETE_DEFAULT', 1504 );
320321

321322
# ERROR_VERSION_*
322323
define( 'ERROR_VERSION_DUPLICATE', 1600 );

‎lang/strings_english.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ If you requested this verification, visit the following URL to change your passw
15681568
ERROR_CATEGORY_NO_ACTION => 'No copy action was specified.',
15691569
ERROR_CATEGORY_NOT_FOUND => 'Category not found.',
15701570
ERROR_CATEGORY_NOT_FOUND_FOR_PROJECT => 'Category "%1$s" not found for project "%2$s".',
1571+
ERROR_CATEGORY_CANNOT_DELETE_DEFAULT => 'This Category cannot be deleted, because it is defined as "Default Category For Moves".',
15711572
ERROR_VERSION_DUPLICATE => 'A version with that name already exists.',
15721573
ERROR_VERSION_NOT_FOUND => 'Version "%1$s" not found.',
15731574
ERROR_USER_NAME_INVALID => 'The username is invalid. Usernames may only contain Latin letters, numbers, spaces, hyphens, dots, plus signs and underscores.',

‎manage_proj_cat_delete.php

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@
6666

6767
access_ensure_project_level( config_get( 'manage_project_threshold' ), $t_project_id );
6868

69+
# Protect the 'default category for moves' from deletion
70+
$t_default_cat = 'default_category_for_moves';
71+
$t_config_table = db_get_table( 'config' );
72+
$t_query = "SELECT count(config_id) FROM $t_config_table "
73+
. "WHERE config_id = " . db_param() . " AND value = " . db_param();
74+
$t_default_cat_count = db_result( db_query_bound( $t_query, array( $t_default_cat, $f_category_id ) ) );
75+
if( $t_default_cat_count > 0 || $f_category_id == config_get_global( $t_default_cat ) ) {
76+
trigger_error( ERROR_CATEGORY_CANNOT_DELETE_DEFAULT, ERROR );
77+
}
78+
6979
# Get a bug count
7080
$t_bug_table = db_get_table( 'bug' );
7181
$t_query = "SELECT COUNT(id) FROM $t_bug_table WHERE category_id=" . db_param();

0 commit comments

Comments
 (0)
Please sign in to comment.