Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#30339 closed defect (bug) (fixed)

Infinite loop while checking for post slug uniqueness

Reported by: julien731's profile julien731 Owned by: johnbillion's profile johnbillion
Milestone: 4.1 Priority: normal
Severity: major Version: 4.1
Component: Posts, Post Types Keywords: has-patch needs-unit-tests
Focuses: Cc:

Description

When inserting a new hierarchical post of any type using wp_insert_post(), the wp_unique_post_slug() function creates an infinite loop when checking for already existing posts with the same slug.

In wp_unique_post_slug(), when entering the case of is_post_type_hierarchical() (line 3698 in the trunk as of today), the query is missing the $post_type variable when being prepared. The query set in $check_sql contains 4 parameters but only 3 are given in $wpdb->prepare() (line 3723) while looping in the post slugs.

As a result, $wpdb->prepare() returns false because of the last argument (post_parent) not being given, and no SQL query is run at all. $wpdb->get_var() then returns the last cached result.

Attachments (1)

post.diff (602 bytes) - added by julien731 10 years ago.
Patched version of post.php with $post_type added to the query

Download all attachments as: .zip

Change History (9)

@julien731
10 years ago

Patched version of post.php with $post_type added to the query

This ticket was mentioned in Slack in #core by julien731. View the logs.


10 years ago

#2 @julien731
10 years ago

  • Keywords needs-testing added

It looks like the issue was created with revision r30158.

Last edited 10 years ago by ocean90 (previous) (diff)

#3 @ocean90
10 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.1

#4 @johnbillion
10 years ago

  • Keywords needs-unit-tests added; needs-testing removed

We need a unit test which covers the situation where some-slug and some-slug-2 already exist, so the code steps into the while loop.

#5 @dd32
10 years ago

I've re-opened the original ticket #18962 with another issue, I've uploaded patch which also contains the fix for this ticket from @julien731 and a unit test for it.

#6 @johnbillion
10 years ago

  • Severity changed from normal to major

This ticket was mentioned in Slack in #core by johnbillion. View the logs.


10 years ago

#8 @johnbillion
10 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 30480:

Correct an SQL syntax error introduced in r30158. Adds tests.

Fixes #30339
See #18962
Props julien731

Note: See TracTickets for help on using tickets.