Summary
In drupal_deliver_html_page() in some circumstances menu_execute_active_handler() is called and its return value is directly passed to drupal_render_page() even if it is an integer
Steps to reproduce
Start with a clean site (ie. minimal profile), then:
- Switch on maintenance_mode
drush vset maintenance_mode 1 - Set a custom access denied page
drush vset site_403 'non-empty' - Access the cron.php of your site
curl https://example.com/cron.php
The result is this set of errors:
Cannot use a scalar value as an array block.module:271
Invalid argument supplied for foreach() common.inc:6594
Cannot use a scalar value as an array common.inc:6051
Cannot use a scalar value as an array common.inc:6106
Depending on what othen modules you have activated there might be even more errors.
Analysis
drupal_deliver_html_page() checks only for MENU_NOT_FOUND and MENU_ACCESS_DENIED before passing the value to drupal_render_page(). This is not sufficent.
Proposed solution
Check for is_int($return) instead of just specific integers.