Skip to content

Commit 08f0f15

Browse files
committed
Parameterize primary key values in DELETE query construction
The DELETE path selects primary key values and then uses them in a DELETE ... WHERE pk IN (...) query. Previously, the values were interpolated directly via implode(). While the values come from the database (not user input), they could be non-integer types (e.g., VARCHAR primary keys), which would produce broken SQL. Use bound parameters instead.
1 parent 84f2455 commit 08f0f15

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

wp-includes/sqlite/class-wp-sqlite-translator.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,12 +1494,13 @@ private function execute_delete() {
14941494

14951495
$quoted_table = $this->quote_identifier( $this->table_name );
14961496
$quoted_pk = $this->quote_identifier( $pk_name );
1497-
$query = (
1498-
count( $ids_to_delete )
1499-
? "DELETE FROM {$quoted_table} WHERE {$quoted_pk} IN (" . implode( ',', $ids_to_delete ) . ')'
1500-
: "DELETE FROM {$quoted_table} WHERE 0=1"
1501-
);
1502-
$this->execute_sqlite_query( $query );
1497+
if ( count( $ids_to_delete ) ) {
1498+
$placeholders = implode( ',', array_fill( 0, count( $ids_to_delete ), '?' ) );
1499+
$stmt = $this->execute_sqlite_query( "DELETE FROM {$quoted_table} WHERE {$quoted_pk} IN ({$placeholders})" );
1500+
$stmt->execute( $ids_to_delete );
1501+
} else {
1502+
$this->execute_sqlite_query( "DELETE FROM {$quoted_table} WHERE 0=1" );
1503+
}
15031504
$this->set_result_from_affected_rows(
15041505
count( $ids_to_delete )
15051506
);

0 commit comments

Comments
 (0)