Opened 4 years ago
Closed 4 years ago
#10896 closed defect (bug) (fixed)
preg_replace with eval modifier used in _fix_attachment_links
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | high | Milestone: | 2.9 |
| Component: | Security | Version: | 2.8.4 |
| Severity: | major | Keywords: | needs-patch |
| Cc: |
Description
Reported by BenBE1987 on #8689
This code:
$post_search[$i] = $anchor; $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor ); ++$i;
Change History (5)
comment:2
BenBE1987
— 4 years ago
- Milestone changed from 2.9 to 2.8.5
- Priority changed from normal to high
- Severity changed from normal to major
comment:3
westi
— 4 years ago
- Milestone changed from 2.8.5 to 2.9
Could you create a patch file for that.
Instructions can be found from here:
http://markjaquith.wordpress.com/2005/11/02/my-wordpress-toolbox/
http://blog.ftwr.co.uk/archives/2005/11/03/windows-wordpress-toolbox/
Note: See
TracTickets for help on using
tickets.
Patched locally for me as:
// // Private // global $_fix_attachment_link_id; function _fix_attachment_links_replaceCB($match) { global $_fix_attachment_link_id; return stripslashes( 'href='.$m[1] ).get_attachment_link( $_fix_attachment_link_id ).stripslashes( $m[1] ); } /** * Replace hrefs of attachment anchors with up-to-date permalinks. * * @since unknown * @access private * * @param unknown_type $post_ID * @return unknown */ function _fix_attachment_links( $post_ID ) { global $_fix_attachment_link_id; $post = & get_post( $post_ID, ARRAY_A ); $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; // See if we have any rel="attachment" links if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) ) return; $i = 0; $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i"; foreach ( $anchor_matches[0] as $anchor ) { if ( 0 == preg_match( $search, $anchor, $id_matches ) ) continue; $id = (int) $id_matches[3]; // While we have the attachment ID, let's adopt any orphans. $attachment = & get_post( $id, ARRAY_A ); if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) { $attachment['post_parent'] = $post_ID; // Escape data pulled from DB. $attachment = add_magic_quotes( $attachment); wp_update_post( $attachment); } $post_search[$i] = $anchor; $_fix_attachment_link_id = $id; $post_replace[$i] = preg_replace_callback( "#href=(\"|')[^'\"]*\\1#", '_fix_attachment_links_replaceCB', $anchor ); ++$i; } $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] ); // Escape data pulled from DB. $post = add_magic_quotes( $post); return wp_update_post( $post); }Not sure if this fully works.