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.
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | 918356-custom404_hook_init_tests_seven.patch | 7.21 KB | franz |
| #38 | 918356-custom404_hook_init_seven.patch | 8.06 KB | franz |
| #35 | 918356-custom404_hook_init_tests.patch | 7.25 KB | franz |
| #35 | 918356-custom404_hook_init.patch | 8.12 KB | franz |
| #30 | menu-set-active-trail-918356-30.patch | 8.06 KB | mstef |
Comments
Comment #1
tekante commentedAttached 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.
Comment #2
tekante commentedI 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.
Comment #4
dstolComment #6
dstolReroll, this should apply cleanly now.
Comment #8
boombatower commented#6: 918356-6.patch queued for re-testing.
Comment #10
dstolComment #11
dstol#6: 918356-6.patch queued for re-testing.
Comment #13
dstol#6: 918356-6.patch queued for re-testing.
Comment #16
dstol#6: 918356-6.patch queued for re-testing.
Comment #17
dstolSigh, I have no idea why this keeps failing.
Comment #19
dstolComment #20
dstol#6: 918356-6.patch queued for re-testing.
Comment #21
carinadigital commentedThis 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.
Comment #22
alexjarvis commentedLooks good.
Comment #23
damien tournoud commentedNot sure exactly what this issue is about, but this needs to be examined in Drupal 8 first, then eventually backported.
Comment #24
David_Rothstein commentedThis 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.
Comment #25
David_Rothstein commentedClosely related issue (and possible duplicate): #588158: Occasional fatal error on custom 403 pages due to missing menu item 'localized_options' when generating breadcrumbs
Comment #26
effulgentsia commented#24 seems sensible to me.
Indeed. Setting status and tagging accordingly.
Comment #27
effulgentsia commented.
Comment #28
chx commentedNo, 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.
Comment #29
David_Rothstein commentedAs 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.
Comment #30
mstef commentedRerolled #29 to apply to drupal root (7.x) - needed for drush make.
Comment #32
David_Rothstein commented#29: menu-set-active-trail-918356-29.patch queued for re-testing.
Comment #33
xjmHas tests, so untagging.
Comment #34
thebuckst0p commentedSubscribe. Seeing something like this on a D6 site.
Comment #35
franzRe-rolled this properly. I'm also submitting the tests separate to demonstrate it.
Comment #36
franzFunny, both test results are as expected, but not updated here. I think it's RTBC, was just re-rolled really.
Comment #37
catchLooks good, thanks for the detailed test coverage. Committed/pushed to 8.x, moving to 7.x for backport.
Comment #38
franzComment #39
catchStraight backport, looks good to me.
Comment #40
akamouri commented#6: 918356-6.patch queued for re-testing.
Comment #41
webchickGreat. Thanks a lot, all!
Committed and pushed to 7.x.
Comment #43
crimsondryad commentedMoving this back to D6, we can confirm this bug exists.
Comment #44
effulgentsia commentedComment #45
simeIf 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()