If drupal_get_title is called during module initialization and an invalid path is requested leading to drupal_not_found being called, if the site_404 variable is set and points to a valid path then a WSOD is observed due to a PHP fatal error.

PHP Stack trace:
PHP 1. {main}() drupal/index.php:0
PHP 2. drupal_not_found() drupal/index.php:24
PHP 3. theme() drupal/includes/common.inc:391
PHP 4. call_user_func_array() drupal/includes/theme.inc:697
PHP 5. template_preprocess_page() drupal/includes/theme.inc:0
PHP 6. drupal_get_breadcrumb() drupal/includes/theme.inc:1856
PHP 7. menu_get_active_breadcrumb() drupal/includes/common.inc:100

This is due to a null $item being returned and added to the active menu trail in menu.inc.

Attached is a simple module that sets the site_404 variable and calls drupal_get_title in an init_hook. Note that the path set for the site_404 variable is coded for node/1 and needs to be adjusted to point to an existing path.

Comments

tekante’s picture

StatusFileSize
new2.08 KB

Attached is a patch that prevents the described issue. It simply prevents the null item from being tacked on to the trail in menu_set_active_trail.

I believe a better patch would involve regeneration of the active trail using the site_404 path. This would allow the breadcrumbs to display properly on the not found page. Seeking feedback on desired behavior of breadcrumbs/trail during a 404.

tekante’s picture

I noticed the first and last line of the stack trace is missing in my report, here is the full trace:

PHP Fatal error: Unsupported operand types in drupal/includes/common.inc on line 1592
PHP Stack trace:
PHP 1. {main}() drupal/index.php:0
PHP 2. drupal_not_found() drupal/index.php:24
PHP 3. theme() drupal/includes/common.inc:391
PHP 4. call_user_func_array() drupal/includes/theme.inc:697
PHP 5. template_preprocess_page() drupal/includes/theme.inc:0
PHP 6. drupal_get_breadcrumb() drupal/includes/theme.inc:1856
PHP 7. menu_get_active_breadcrumb() drupal/includes/common.inc:100
PHP 8. l() drupal/includes/menu.inc:1612

The third parameter is being passed as NULL in this case and attempting to be merged with an array() using the += operand.

dstol’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 918356.patch, failed testing.

dstol’s picture

Status: Needs work » Needs review
StatusFileSize
new2.28 KB

Reroll, this should apply cleanly now.

Status: Needs review » Needs work

The last submitted patch, 918356-6.patch, failed testing.

boombatower’s picture

Status: Needs work » Needs review

#6: 918356-6.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 918356-6.patch, failed testing.

dstol’s picture

Version: 6.19 » 6.x-dev
Status: Needs work » Needs review
dstol’s picture

#6: 918356-6.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 918356-6.patch, failed testing.

dstol’s picture

Status: Needs work » Needs review

#6: 918356-6.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 918356-6.patch, failed testing.

dstol’s picture

Status: Needs work » Needs review

#6: 918356-6.patch queued for re-testing.

dstol’s picture

Sigh, I have no idea why this keeps failing.

Status: Needs review » Needs work

The last submitted patch, 918356-6.patch, failed testing.

dstol’s picture

Status: Needs work » Needs review
dstol’s picture

#6: 918356-6.patch queued for re-testing.

carinadigital’s picture

This bug seem related to these issue in solr and search404:
#342192 "Unsupported operands" thrown in drupal_get_breadcrumb when search404's page is rendered
#775236 Unsupported operand types error with Apache Solr
#550534 Search 404 incompatibility

The breadcrumb generation uses menu_set_active_trail() and so suffers from the same problem on site_404 redirection of NULL being returned, and causing a wsod.

alexjarvis’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

damien tournoud’s picture

Version: 6.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs work

Not sure exactly what this issue is about, but this needs to be examined in Drupal 8 first, then eventually backported.

David_Rothstein’s picture

Title: WSOD when drupal_get_title called during hook_init and drupal_not_found executed » WSOD when drupal_get_title called during hook_init and custom 403 or 404 pages are being used
Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new432 bytes

This bug exists in Drupal 8, and to clarify, the steps to reproduce are this:
1. Install a module that calls drupal_get_title() in hook_init().
2. Configure your site to use a custom 404 page (or a custom 403 page - same error happens there).
3. Visit a page that doesn't exist (or for the 403 example, a page you don't have access to).
4. WSOD.

The root cause of the bug is that menu_set_active_trail() is returning cached results for the path that doesn't exist, rather than the actual trail for the custom 403/404 page. The attached patch fixes the issue. We should probably add a test for this; I might have time to do this later, but not right now.

The approach in the earlier patches in this issue (don't add a menu item to the trail that doesn't exist) makes sense also. However, it only works for the custom 404 case, not for the custom 403, and it doesn't really address the root cause. Nonetheless, it's sensible enough code that maybe we should merge it into this patch also (and it also may be the only solution that will work for Drupal 6 backport). I haven't done that in the attached patch yet, though.

effulgentsia’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

#24 seems sensible to me.

We should probably add a test for this

Indeed. Setting status and tagging accordingly.

effulgentsia’s picture

Issue tags: +Needs backport to D7

.

chx’s picture

No, that solution is putting bandaid on cancer. There's another issue open for this just can't find it right now -- there are too many "active" things in the menu and they need clean up.

David_Rothstein’s picture

Status: Needs work » Needs review
StatusFileSize
new8.12 KB

As long as those functions exist and one of them has a static variable (which I assume will not change in Drupal 7...) then we need to clear that static when it's out of date. It's really just a garden-variety static caching bug in the end. I looked for another related issue but couldn't find one.

Here's a new version that contains tests. The tests I wrote actually do require something similar to both approaches from above (#6 and #24) in order to pass, which is nice, so this patch combines them.

mstef’s picture

StatusFileSize
new8.06 KB

Rerolled #29 to apply to drupal root (7.x) - needed for drush make.

Status: Needs review » Needs work
Issue tags: -Needs tests, -Needs backport to D7

The last submitted patch, menu-set-active-trail-918356-30.patch, failed testing.

David_Rothstein’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests, +Needs backport to D7
xjm’s picture

Issue tags: -Needs tests

Has tests, so untagging.

thebuckst0p’s picture

Subscribe. Seeing something like this on a D6 site.

franz’s picture

Re-rolled this properly. I'm also submitting the tests separate to demonstrate it.

franz’s picture

Status: Needs review » Reviewed & tested by the community

Funny, both test results are as expected, but not updated here. I think it's RTBC, was just re-rolled really.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Looks good, thanks for the detailed test coverage. Committed/pushed to 8.x, moving to 7.x for backport.

franz’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new8.06 KB
new7.21 KB
catch’s picture

Status: Needs review » Reviewed & tested by the community

Straight backport, looks good to me.

akamouri’s picture

#6: 918356-6.patch queued for re-testing.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Great. Thanks a lot, all!

Committed and pushed to 7.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

crimsondryad’s picture

Version: 7.x-dev » 6.x-dev
Status: Closed (fixed) » Active

Moving this back to D6, we can confirm this bug exists.

effulgentsia’s picture

Status: Active » Patch (to be ported)
Issue tags: -Needs backport to D7
sime’s picture

If you have control of the hook_init() that is triggering the drupal_get_title(), (and assuming this patch hasn't been ported to D6 yet) you can put something like the following inside the hook_init()

  // Avoid WSOD On 404 pages http://drupal.org/node/918356
  if (!menu_get_item()) {
    return;
  }

Status: Patch (to be ported) » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.