When calling drupal_access_denied in the flow of a page callback, you can get "headers already sent" type errors.
This was flooding my watchdog table bigtime (because of unfriendly bots)
Similar issues have been fixed in core recently: http://drupalcode.org/project/drupal.git/commit/257fac8

note, this is not a duplicate for #1399636: Warning: Cannot modify header information - headers already sent em drupal_send_headers() ...

Patch will follow

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rv0’s picture

Status: Active » Needs review
FileSize
510 bytes

Patch seems to fix it, based on the similar fixes in core (see above)

rudiedirkx’s picture

Status: Needs review » Needs work

Almost, but not quite.

_print_generate_path() does the same. It checks for MENU_NOT_FOUND and MENU_ACCESS_DENIED, but doesn't handle it well:

  if (is_int($node->content)) {
    switch ($node->content) {
      case MENU_NOT_FOUND:
        drupal_not_found();
        return FALSE;
        break;
      case MENU_ACCESS_DENIED:
        drupal_access_denied();
        return FALSE;
        break;
    }
  }

I did the same there and that works: replace return FALSE with drupal_exit().

It's very strange that _print_generate_path() even calls drupal_not_found()... This is a helper function that should be callable from anywhere, it shouldn't alter the request. But since it does that anyway, I think this is the solution.

rudiedirkx’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Since 2.x is the active branch, and it's still a bug in 2.0.

rudiedirkx’s picture

FileSize
903 bytes

And the patch against 2.x-dev

rudiedirkx’s picture

Status: Needs work » Needs review
interdruper’s picture

Status: Needs review » Reviewed & tested by the community

#4 works for me. Thx!

alcroito’s picture

Providing a more complete patch for 1.x version of the module, in case anyone needs it.

SpadXIII’s picture

FileSize
1.26 KB

Added another set of drupal_exit()'s in _print_generate_node() where the same not_found/access_denied were triggered to the patch in #4.

Other than that, works as expected!

joewhitsitt’s picture

#8 works for me. thank you!

rudiedirkx’s picture

Priority: Normal » Critical

Anyone, please commit!

rjacobs’s picture

Priority: Critical » Major

I'm hiding all but the most recent patch in hopes that speeds-up the review.

Also, as annoying as the bug is I'm not sure it qualifies as "critical" as I don't think it leads to instability or data loss. So "major" may be most appropriate. That's probably splitting hairs though. Either way hopefully a maintainer can have a look here.

webservant316’s picture

#8 works for me. thanks! yes lets get this committed!

rv0’s picture

bump #8

Rob_Feature’s picture

yup, all good on my end with the patch in #8. I messaged the maintainer to see if we can get this committed.

  • jcnventura committed 37ab511 on 7.x-2.x authored by SpadXIII
    Issue #2257075 by rudiedirkx, Placinta, SpadXIII, rv0: Headers already...
jcnventura’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Anonymous’s picture

Will this be backported to 7.x-1.3?

jcnventura’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Fixed » Patch (to be ported)

It probably makes some sense to port it back to 7.x-1.x.. But you should really move away from that branch.

Anonymous’s picture

Here's a fix for 7.x-1.x. node/2012852

jcnventura’s picture

Status: Patch (to be ported) » Closed (won't fix)

I've deprecated the 7.x-1.x-dev branch.