From a38245a657283d26a3da141f715a057e98c53cd4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 8 Jan 2024 22:44:17 +0000 Subject: [PATCH] Taxonomy: Check for empty term after DB sanitization in `wp_insert_term()`. When inserting a new term in the database, `wp_insert_term()` will check if the term is empty and return a corresponding error. Afterwards the term is sanitized and inserted in the database. However, there is a chance the term is empty after the DB sanitization. This commit adds a check for an empty term name after the term is sanitized, returning an error in that case. Follow-up to [5726], [8393]. Props fgiannar, kraftbj. Fixes #59995. Built from https://develop.svn.wordpress.org/trunk@57251 git-svn-id: http://core.svn.wordpress.org/trunk@56757 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 5 +++++ wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index eaadaad65c..b64a2f08db 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2434,6 +2434,11 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { $description = wp_unslash( $args['description'] ); $parent = (int) $args['parent']; + // Sanitization could clean the name to an empty string that must be checked again. + if ( '' === $name ) { + return new WP_Error( 'invalid_term_name', __( 'Invalid term name.' ) ); + } + $slug_provided = ! empty( $args['slug'] ); if ( ! $slug_provided ) { $slug = sanitize_title( $name ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 7baf73dcc2..3c0c55ab54 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-alpha-57250'; +$wp_version = '6.5-alpha-57251'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.