drupal_get_filename() should check if $name is empty

Created on 28 November 2014, over 9 years ago
Updated 1 November 2023, 8 months ago

I have found a situation where menu.inc keeps trying to find the file path for the parent module see http://cgit.drupalcode.org/drupal/tree/includes/menu.inc?h=7.x#n3691

if (empty($item['file path']) && isset($item['module']) && isset($parent['module']) && $item['module'] != $parent['module']) {
  $item['file path'] = drupal_get_path('module', $parent['module']);
}

I debugged this and found that drupal_get_path() will return Null every tme $parent['module'] is empty.
drupal_get_path() calls drupal_get_filename() passing the empty $name as parameter.

drupal_get_filename() does not check if the value of $name is empty which means it will do all the logic, including this:

// Fallback to searching the filesystem if the database could not find the
// file or the file returned by the database is not found.
if (!isset($files[$type][$name])) {
  // We have a consistent directory naming: modules, themes...
  $dir = $type . 's';
  if ($type == 'theme_engine') {
    $dir = 'themes/engines';
    $extension = 'engine';
  }
  elseif ($type == 'theme') {
    $extension = 'info';
  }
  else {
    $extension = $type;
  }

  if (!isset($dirs[$dir][$extension])) {
    $dirs[$dir][$extension] = TRUE;
    if (!function_exists('drupal_system_listing')) {
      require_once DRUPAL_ROOT . '/includes/common.inc';
    }
    // Scan the appropriate directories for all files with the requested
    // extension, not just the file we are currently looking for. This
    // prevents unnecessary scans from being repeated when this function is
    // called more than once in the same page request.
    $matches = drupal_system_listing("/^" . DRUPAL_PHP_FUNCTION_PATTERN . "\.$extension$/", $dir, 'name', 0);
    foreach ($matches as $matched_name => $file) {
      $files[$type][$matched_name] = $file->uri;
    }
  }
}

see http://cgit.drupalcode.org/drupal/tree/includes/bootstrap.inc?h=7.x#n876

I am proposing we add a check on the very top of drupal_get_filename() and return NULL when $name is empty.
This will fix the problem cause by menu.inc and also any problem caused by other functions that call drupal_get_filename() without $name.

πŸ› Bug report
Status

Needs work

Version

7.0 ⚰️

Component
BootstrapΒ  β†’

Last updated 9 days ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom marcelovani London

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024