Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Originally from https://www.drupal.org/node/2656742#comment-10795610
Comment | File | Size | Author |
---|---|---|---|
#7 | 2658836-null-entity-access-check.patch | 2.71 KB | Crell |
#6 | 2658836-null-entity-access-check.patch | 2.05 KB | Crell |
no-entity.patch | 995 bytes | timmillwood | |
Comments
Comment #2
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedThe linked comment(s) suggest this issue occurs when the links block is undefined in an entity. I... do not understand how that would happen, since if there's no links block the route shouldn't even be defined in the first place and this code should be unreachable.
I'd like to understand how that happens before committing this, as it may suggest a better alternative approach. (I generally assume that if you need to protect against null, it means there's a logic error elsewhere to begin with.)
Comment #3
timmillwoodI understand it's a bit of an edge case, but Multiversion has been working fine without all of the links defined, and I'm sure there will be other modules that think they're OK.
This patch is just a prevention.
Also it seems odd that the one method knowingly returns null and there is nothing preventing that being passed through to something that doesn't accept null.
Comment #4
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedBut how does links being empty result in this issue? That's what I don't understand. I don't get how that connection happens.
Comment #5
timmillwoodAh, it causes the parameters from RouteMatch to be empty
Comment #6
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedTim and I talked this through earlier today. The issue isn't links per se; it's that the current code in loadEntity() presumes an _entity_access requirement, which isn't guaranteed to be there in all cases. It then returns NULL rather than properly handling that error case, and things blow up.
This patch changes loadEntity() to use a hopefully more robust approach, and throws an exception in case it doesn't work. Because returning "something useful or null" is rude: http://www.garfieldtech.com/blog/empty-return-values
Let's see if the bot approves...
Comment #7
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedAnd now thanks to EclipseGc's input, here's an even better approach. (No interdiff as it would basically be the entire patch.)
Comment #8
EclipseGc CreditAttribution: EclipseGc at Acquia commentedLooks solidly better than what's there!
Eclipse
Comment #10
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedWent ahead and merged. Thanks, Tim and Kris!