Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a4e02b

Browse files
Pantheon Automationgreg-1-anderson
Pantheon Automation
authored andcommittedMar 20, 2019
Update to Drupal 7.65. For more information, see https://www.drupal.org/project/drupal/releases/7.65
1 parent d81f0b8 commit 1a4e02b

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
 

‎CHANGELOG.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Drupal 7.xx, xxxx-xx-xx (development version)
22
-----------------------
33

4+
Drupal 7.65, 2019-03-20
5+
-----------------------
6+
- Fixed security issues:
7+
- SA-CORE-2019-004
8+
49
Drupal 7.64, 2019-02-06
510
-----------------------
611
- [regression] Unset the 'host' header in drupal_http_request() during redirect

‎includes/bootstrap.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* The current system version.
1010
*/
11-
define('VERSION', '7.64');
11+
define('VERSION', '7.65');
1212

1313
/**
1414
* Core API compatibility.

‎includes/file.inc

+23-2
Original file line numberDiff line numberDiff line change
@@ -997,16 +997,22 @@ function file_build_uri($path) {
997997
* @return
998998
* The destination filepath, or FALSE if the file already exists
999999
* and FILE_EXISTS_ERROR is specified.
1000+
*
1001+
* @throws RuntimeException
1002+
* Thrown if the filename contains invalid UTF-8.
10001003
*/
10011004
function file_destination($destination, $replace) {
1005+
$basename = drupal_basename($destination);
1006+
if (!drupal_validate_utf8($basename)) {
1007+
throw new RuntimeException(sprintf("Invalid filename '%s'", $basename));
1008+
}
10021009
if (file_exists($destination)) {
10031010
switch ($replace) {
10041011
case FILE_EXISTS_REPLACE:
10051012
// Do nothing here, we want to overwrite the existing file.
10061013
break;
10071014

10081015
case FILE_EXISTS_RENAME:
1009-
$basename = drupal_basename($destination);
10101016
$directory = drupal_dirname($destination);
10111017
$destination = file_create_filename($basename, $directory);
10121018
break;
@@ -1222,11 +1228,20 @@ function file_unmunge_filename($filename) {
12221228
* @return
12231229
* File path consisting of $directory and a unique filename based off
12241230
* of $basename.
1231+
*
1232+
* @throws RuntimeException
1233+
* Thrown if the $basename is not valid UTF-8 or another error occurs
1234+
* stripping control characters.
12251235
*/
12261236
function file_create_filename($basename, $directory) {
1237+
$original = $basename;
12271238
// Strip control characters (ASCII value < 32). Though these are allowed in
12281239
// some filesystems, not many applications handle them well.
12291240
$basename = preg_replace('/[\x00-\x1F]/u', '_', $basename);
1241+
if (preg_last_error() !== PREG_NO_ERROR) {
1242+
throw new RuntimeException(sprintf("Invalid filename '%s'", $original));
1243+
}
1244+
12301245
if (substr(PHP_OS, 0, 3) == 'WIN') {
12311246
// These characters are not allowed in Windows filenames
12321247
$basename = str_replace(array(':', '*', '?', '"', '<', '>', '|'), '_', $basename);
@@ -1567,7 +1582,13 @@ function file_save_upload($form_field_name, $validators = array(), $destination
15671582
if (substr($destination, -1) != '/') {
15681583
$destination .= '/';
15691584
}
1570-
$file->destination = file_destination($destination . $file->filename, $replace);
1585+
try {
1586+
$file->destination = file_destination($destination . $file->filename, $replace);
1587+
}
1588+
catch (RuntimeException $e) {
1589+
drupal_set_message(t('The file %source could not be uploaded because the name is invalid.', array('%source' => $form_field_name)), 'error');
1590+
return FALSE;
1591+
}
15711592
// If file_destination() returns FALSE then $replace == FILE_EXISTS_ERROR and
15721593
// there's an existing file so we need to bail.
15731594
if ($file->destination === FALSE) {

‎modules/simpletest/tests/file.test

+17
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,15 @@ class FileDirectoryTest extends FileTestCase {
957957
$path = file_create_filename($basename, $directory);
958958
$this->assertEqual($path, $expected, format_string('Creating a new filepath from %original equals %new.', array('%new' => $path, '%original' => $original)), 'File');
959959

960+
try {
961+
$filename = "a\xFFtest\x80€.txt";
962+
file_create_filename($filename, $directory);
963+
$this->fail('Expected exception not thrown');
964+
}
965+
catch (RuntimeException $e) {
966+
$this->assertEqual("Invalid filename '$filename'", $e->getMessage());
967+
}
968+
960969
// @TODO: Finally we copy a file into a directory several times, to ensure a properly iterating filename suffix.
961970
}
962971

@@ -989,6 +998,14 @@ class FileDirectoryTest extends FileTestCase {
989998
$this->assertNotEqual($path, $destination, 'A new filepath destination is created when filepath destination already exists with FILE_EXISTS_RENAME.', 'File');
990999
$path = file_destination($destination, FILE_EXISTS_ERROR);
9911000
$this->assertEqual($path, FALSE, 'An error is returned when filepath destination already exists with FILE_EXISTS_ERROR.', 'File');
1001+
1002+
try {
1003+
file_destination("core/misc/a\xFFtest\x80€.txt", FILE_EXISTS_REPLACE);
1004+
$this->fail('Expected exception not thrown');
1005+
}
1006+
catch (RuntimeException $e) {
1007+
$this->assertEqual("Invalid filename 'a\xFFtest\x80€.txt'", $e->getMessage());
1008+
}
9921009
}
9931010

9941011
/**

0 commit comments

Comments
 (0)
Please sign in to comment.