Skip to content

Commit

Permalink
Use query parameters in install helper function
Browse files Browse the repository at this point in the history
install_correct_multiselect_custom_fields_db_format() injected actual
field values in the update SQL queries, which is a potential source for
SQL injection, and causes the upgrade from MantisBT < 1.2.0 to fail when
custom_field_table contains an apostrophe.

Fixes #26636
  • Loading branch information
dregad committed Feb 2, 2020
1 parent d454e23 commit 88cefc7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/install_helper_functions_api.php
Expand Up @@ -409,10 +409,11 @@ function install_correct_multiselect_custom_fields_db_format() {
$c_bug_id = (int)$t_row['bug_id'];
$c_value = '|' . rtrim( ltrim( $t_row['value'], '|' ), '|' ) . '|';
$t_update_query = 'UPDATE {custom_field_string}
SET value = \'' . $c_value . '\'
WHERE field_id = ' . $c_field_id . '
AND bug_id = ' . $c_bug_id;
db_query( $t_update_query );
SET value = ' . db_param() . '
WHERE field_id = ' . db_param() . '
AND bug_id = ' . db_param();
$t_param = array( $c_value, $c_field_id, $c_bug_id );
db_query( $t_update_query, $t_param );
}

# Remove vertical pipe | prefix and suffix from radio custom field values.
Expand All @@ -429,10 +430,11 @@ function install_correct_multiselect_custom_fields_db_format() {
$c_bug_id = (int)$t_row['bug_id'];
$c_value = rtrim( ltrim( $t_row['value'], '|' ), '|' );
$t_update_query = 'UPDATE {custom_field_string}
SET value = \'' . $c_value . '\'
WHERE field_id = ' . $c_field_id . '
AND bug_id = ' . $c_bug_id;
db_query( $t_update_query );
SET value = ' . db_param() . '
WHERE field_id = ' . db_param() . '
] AND bug_id = ' . db_param();
$t_param = array( $c_value, $c_field_id, $c_bug_id );
db_query( $t_update_query, $t_param );
}

# Re-enable query logging if we disabled it
Expand Down

0 comments on commit 88cefc7

Please sign in to comment.