Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f50762c

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 6641edc commit f50762c

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
@@ -249,6 +249,7 @@ $MANTIS_ERROR[ERROR_CATEGORY_DUPLICATE] = 'A category with that name already exi
249249
$MANTIS_ERROR[ERROR_CATEGORY_NO_ACTION] = 'No copy action was specified.';
250250
$MANTIS_ERROR[ERROR_CATEGORY_NOT_FOUND] = 'Category not found.';
251251
$MANTIS_ERROR[ERROR_CATEGORY_NOT_FOUND_FOR_PROJECT] = 'Category "%1$s" not found for project "%2$s".';
252+
$MANTIS_ERROR[ERROR_CATEGORY_CANNOT_DELETE_DEFAULT] = 'This Category cannot be deleted, because it is defined as "Default Category For Moves".';
252253
$MANTIS_ERROR[ERROR_VERSION_DUPLICATE] = 'A version with that name already exists.';
253254
$MANTIS_ERROR[ERROR_VERSION_NOT_FOUND] = 'Version "%1$s" not found.';
254255
$MANTIS_ERROR[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
@@ -40,6 +40,16 @@
4040

4141
access_ensure_project_level( config_get( 'manage_project_threshold' ), $t_project_id );
4242

43+
# Protect the 'default category for moves' from deletion
44+
$t_default_cat = 'default_category_for_moves';
45+
$t_config_table = db_get_table( 'mantis_config_table' );
46+
$t_query = "SELECT count(config_id) FROM $t_config_table "
47+
. "WHERE config_id = " . db_param() . " AND value = " . db_param();
48+
$t_default_cat_count = db_result( db_query_bound( $t_query, array( $t_default_cat, $f_category_id ) ) );
49+
if( $t_default_cat_count > 0 || $f_category_id == config_get_global( $t_default_cat ) ) {
50+
trigger_error( ERROR_CATEGORY_CANNOT_DELETE_DEFAULT, ERROR );
51+
}
52+
4353
# Get a bug count
4454
$t_bug_table = db_get_table( 'mantis_bug_table' );
4555
$t_query = "SELECT COUNT(id) FROM $t_bug_table WHERE category_id=" . db_param();

0 commit comments

Comments
 (0)
Please sign in to comment.