Reproducing:
1. Enable opensearch
2. Install a module like block404 or simply configure a custom 404 page in the error reporting menu
3. Visit any page that should cause a 404

Expected:
Normal page load

Result:
Fatal error

I've looked into it a bit and it is caused because you are running token_replace_multiple inside hook_init. This triggers the global 'current-page-title' token. The problem is arises because triggering this token caches the current menu trail, so when the 404 page attempts to render a different page, it crashes.

I'm not sure what the best solution, but looking through the code, I was wondering why you have all of these settings inside hook_init. Wouldn't it be better to have all of this inside of a preprocess_page, since you assigning feeds?

Comments

13rac1’s picture

Priority: Normal » Critical

Changing to critical, since this causes fatal errors site wide when custom 404 and 403 pages are specified. Many sites and modules rely on these features including 404 Blocks, Logintoboggan, and Private Downloads.

The specific error is:

Fatal error: Unsupported operand types in /var/www/includes/common.inc on line 1589

The fatal error occurs in the l() function when the $options value is passed as NULL. The value is NULL because the active menu trail is incorrect. This is the active trail for Private Downloads:

[0] => Array
    (
        [title] => Home
        [href] => <front> 
        [localized_options] => Array
            (
            )
        [type] => 0
    )
 
[1] => Array
    (
        [path] => system/files/%
        [load_functions] => Array
            (
                [2] => 
            )
        [access_callback] => user_access
        [access_arguments] => a:1:{i:0;s:33:"access private download directory";}
        [page_callback] => file_download
        [page_arguments] => a:1:{i:0;s:7:"private";}
        [number_parts] => 3
        [tab_parent] => 
        [tab_root] => system/files/%
        [title] => Private download
        [type] => 4
        [href] => system/files/private
        [options] => Array
            (
            )
        [access] => 
    )

$active_trail[1]['localized_options'] is not set, because menu_set_active_trail() is called in init() and caches the data before the Drupal access denied redirection runs. This is the backtrace for the early run of menu_set_active_trail(), ignore the page_title module:

#0  menu_set_active_trail() called at [/var/www/includes/menu.inc:1598]
#1  menu_get_active_trail() called at [/var/www/includes/menu.inc:1634]
#2  menu_get_active_title() called at [/var/www/includes/path.inc:233]
#3  drupal_get_title() called at [/var/www/sites/all/modules/contrib/page_title/page_title.module:367]
#4  page_title_get_title() called at [/var/www/sites/all/modules/contrib/page_title/page_title.module:530]
#5  page_title_token_values(global, , Array ())
#6  call_user_func_array(page_title_token_values, Array ([1] => global,[2] => ,[3] => Array ())) called at [/var/www/includes/module.inc:483]
#7  module_invoke_all(token_values, global, , Array ()) called at [/var/www/sites/all/modules/contrib/token/token.module:313]
#8  token_get_values(global, , , Array ()) called at [/var/www/sites/all/modules/contrib/token/token.module:239]
#9  token_replace_multiple([search-name] search for [site-name], Array ([global] => ,[search] => apachesolr_search)) called at [/var/www/sites/all/modules/contrib/opensearch/opensearch.module:290]
#10 _opensearch_check_plain([search-name] search for [site-name], apachesolr_search) called at [/var/www/sites/all/modules/contrib/opensearch/opensearch.module:261]
#11 opensearch_add_opensearch_link(stdClass Object ([type] => apachesolr_search,[settings] => Array ([adult_content] => 0,[attribution] => ,[contact] => [site-mail],[description] => [search-name] search for [site-name].,[image_type] => theme,[image_custom] => ,[longname] => [search-name] search for [site-name],[rss_description] => [search-name] search results for "[search-keywords]" at [site-name],[rss_title] => [site-name] [search-name] search: [search-keywords],[shortname] => [search-name] search,[syndication_right] => open,[tags] => ),[feed] => 1)) called at [/var/www/sites/all/modules/contrib/opensearch/opensearch.module:46]
#12 opensearch_init()
#13 call_user_func_array(opensearch_init, Array ()) called at [/var/www/includes/module.inc:483]
#14 module_invoke_all(init) called at [/var/www/includes/common.inc:2611]
#15 _drupal_bootstrap_full() called at [/var/www/includes/bootstrap.inc:1518]
#16 _drupal_bootstrap(8) called at [/var/www/includes/bootstrap.inc:1389]
#17 drupal_bootstrap(8) called at [/var/www/index.php:16]

A potential fix is to modify Open Search to not call token_replace_multiple() during init().

kmonty’s picture

sub

c960657’s picture

Anonymous’s picture

Status: Closed (fixed) » Fixed

I changed the code for hook_init(), which now checks the headers set by Drupal, and verifies if Drupal is returning an error 403 (or error 404) page; it also verifies if the site is off-line, and the user doesn't have the permission to administer the site configuration. In these cases, the function exits without doing anything.

I committed the code, and created a new release (version 6.x-1.4-beta1).

Status: Active » Closed (fixed)

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

szy’s picture

It still happens.

Custom Error 6.x-1.x-dev
Search 404 6.x-1.9
Search config 6.x-1.6
OpenSearch feed 6.x-1.4-beta1

*edit*

Now it's fine: 'Allow PHP code to be executed for 404' must be off.

Szy.

Status: Fixed » Closed (fixed)

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