file_check_location

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 file_check_location($source, $directory = '')

Check if a file is really located inside $directory. Should be used to make sure a file specified is really located within the directory to prevent exploits.

<?php
  // Returns FALSE:
  file_check_location('/www/example.com/files/../../../etc/passwd', '/www/example.com/files');
?>

Übergabeparameter

$source A string set to the file to check.

$directory A string where the file should be located.

Rückgabewert

0 for invalid path or the real path of the source.

Verwandte Themen

▾ 1 function calls file_check_location()

file_create_path in includes/file.inc
Make sure the destination is a complete path and resides in the file system directory, if it is not prepend the file system directory.

Code

includes/file.inc, line 181

<?php
function file_check_location($source, $directory = '') {
  $check = realpath($source);
  if ($check) {
    $source = $check;
  }
  else {
    // This file does not yet exist
    $source = realpath(dirname($source)) . '/' . basename($source);
  }
  $directory = realpath($directory);
  if ($directory && strpos($source, $directory) !== 0) {
    return 0;
  }
  return $source;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen