WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 months ago

Last modified 3 months ago

#31215 closed defect (bug) (fixed)

wp_debug_backtrace_summary fails if args index isn't set

Reported by: paulschreiber Owned by: SergeyBiryukov
Milestone: 5.0 Priority: normal
Severity: normal Version: 3.4.1
Component: General Keywords:
Focuses: Cc:

Description

In wp-includes/functions.php, there's a function wp_debug_backtrace_summary().

If $call['args'] is undefined, it fails like so:

Notice:  Undefined index: args in /srv/www/wp/wp-includes/functions.php on line 4493
Stack trace:
 1. {main}() /srv/www/index.php:0
 2. require() /srv/www/index.php:4
 3. require_once() /srv/www/wp/wp-blog-header.php:16
 4. include() /srv/www/wp/wp-includes/template-loader.php:74
 5. Debug_Bar_PHP->error_handler() /srv/www/wp/wp-includes/template-loader.php:48
 6. wp_debug_backtrace_summary() /srv/www/wp-content/plugins/debug-bar/panels/class-debug-bar-php.php:35

Here's line 4493:

$caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')";

Change History (7)

#1 @DrewAPicture
3 years ago

  • Version changed from trunk to 3.4.1

#2 @SergeyBiryukov
4 months ago

  • Keywords reporter-feedback added

Hi @paulschreiber, thanks for the report! Sorry it took so long for someone to get back to you.

I could not reproduce the issue neither in PHP 7.2.2 (the latest version at the moment) nor in PHP 5.2.4 (the earliest supported version).

Looking at the code, $call is the value of debug_backtrace(). The affected line is only executed if $call['function'] is one of include, include_once, require, or require_once, and in all of those cases $call['args'] is defined. It's even defined if I replace debug_backtrace( false ) with debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) a few lines above.

Could you clarify when $call['args'] would be undefined? Looks like there are no other reports of this issue.

#3 @paulschreiber
3 months ago

I don't recall what code I wrote in 2015 caused this problem. It could be avoided with isset() checks.

#4 @SergeyBiryukov
3 months ago

  • Keywords reporter-feedback removed
  • Milestone changed from Awaiting Review to 5.0

Reproduced when calling the function after including a non-existing file (in which case PHP also throws a warning).

#5 @SergeyBiryukov
3 months ago

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

In 42824:

General: In wp_debug_backtrace_summary(), check if $call['args'] is defined to avoid a PHP notice.

Props paulschreiber.
Fixes #31215.

#6 follow-up: @paulschreiber
3 months ago

Do you need to check isset( $call['args'], $call['args'][0] )? Or will isset( $call['args'] ) work?

#7 in reply to: ↑ 6 @SergeyBiryukov
3 months ago

Replying to paulschreiber:

Do you need to check isset( $call['args'], $call['args'][0] )? Or will isset( $call['args'] ) work?

Both would work, isset() can check deeper array values without a notice. The commit actually checks for $call['args'][0].

Note: See TracTickets for help on using tickets.