Problem/Motivation

entity_metadata_taxonomy_access() sets NULL as the default argument value for $entity; however, the function doesn't actually handle situations where $entity = NULL.

E.g.

    case "delete":
      if ($entity_type == 'taxonomy_term') {
        return user_access("delete terms in $entity->vid", $account);
      }
      break;

The above code will result in the following notice if $entity = NULL:

Notice: Trying to get property of non-object in entity_metadata_taxonomy_access() (line 827 of /var/www/rovdev/sites/all/modules/entity/modules/callbacks.inc).

Proposed resolution

Check for $entity before trying to access its properties.

E.g.

    case "delete":
      if ($entity_type == 'taxonomy_term' && $entity) {
        return user_access("delete terms in $entity->vid", $account);
      }
      break;

Remaining tasks

  • Submit patch
  • Community review

User interface changes

None

API changes

Noe

Data model changes

None

Release notes snippet

None

Original report by sano

#2160355-20: Trying to get property of non-object in entity_metadata_user_access()

Comments

Chris Burge created an issue. See original summary.

chris burge’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.13 KB

Patch attached.

shaunole’s picture

StatusFileSize
new1.21 KB

Reroll of patch for Drupal 7.83 and Entity 7.x-1.10.

shaunole’s picture

StatusFileSize
new1.16 KB

The previous patch had incorrect paths to the callbacks.inc file. This one should work.

shaunole’s picture

StatusFileSize
new1.16 KB

Renaming the patch file and re-uploading.

shaunole’s picture

StatusFileSize
new1.12 KB

Correcting syntax error in patch file. No substantial changes were made. Apologize for all of the posts as this should have been caught on the first one.

shaunole’s picture