Unverified Commit 65fb3829 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3224420 by andypost, longwave, daffie: [PHP 8.1] Exception codes should...

Issue #3224420 by andypost, longwave, daffie: [PHP 8.1] Exception codes should be numeric and not NULL
parent ee952325
Loading
Loading
Loading
Loading
+1 −1
Changes for core/lib/Drupal/Core/Config/DatabaseStorage.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ protected function ensureTableExists() {
      return TRUE;
    }
    catch (\Exception $e) {
      throw new StorageException($e->getMessage(), NULL, $e);
      throw new StorageException($e->getMessage(), 0, $e);
    }
    return FALSE;
  }
+6 −6
Changes for core/lib/Drupal/Core/FileTransfer/FTPExtension.php: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ public function connect() {
   */
  protected function copyFileJailed($source, $destination) {
    if (!@ftp_put($this->connection, $destination, $source, FTP_BINARY)) {
      throw new FileTransferException("Cannot move @source to @destination", NULL, ["@source" => $source, "@destination" => $destination]);
      throw new FileTransferException("Cannot move @source to @destination", 0, ["@source" => $source, "@destination" => $destination]);
    }
  }

@@ -35,7 +35,7 @@ protected function copyFileJailed($source, $destination) {
   */
  protected function createDirectoryJailed($directory) {
    if (!ftp_mkdir($this->connection, $directory)) {
      throw new FileTransferException("Cannot create directory @directory", NULL, ["@directory" => $directory]);
      throw new FileTransferException("Cannot create directory @directory", 0, ["@directory" => $directory]);
    }
  }

@@ -45,7 +45,7 @@ protected function createDirectoryJailed($directory) {
  protected function removeDirectoryJailed($directory) {
    $pwd = ftp_pwd($this->connection);
    if (!ftp_chdir($this->connection, $directory)) {
      throw new FileTransferException("Unable to change the current directory to @directory", NULL, ['@directory' => $directory]);
      throw new FileTransferException("Unable to change the current directory to @directory", 0, ['@directory' => $directory]);
    }
    $list = @ftp_nlist($this->connection, '.');
    if (!$list) {
@@ -65,7 +65,7 @@ protected function removeDirectoryJailed($directory) {
    }
    ftp_chdir($this->connection, $pwd);
    if (!ftp_rmdir($this->connection, $directory)) {
      throw new FileTransferException("Unable to remove the directory @directory", NULL, ['@directory' => $directory]);
      throw new FileTransferException("Unable to remove the directory @directory", 0, ['@directory' => $directory]);
    }
  }

@@ -74,7 +74,7 @@ protected function removeDirectoryJailed($directory) {
   */
  protected function removeFileJailed($destination) {
    if (!ftp_delete($this->connection, $destination)) {
      throw new FileTransferException("Unable to remove the file @file", NULL, ['@file' => $destination]);
      throw new FileTransferException("Unable to remove the file @file", 0, ['@file' => $destination]);
    }
  }

@@ -103,7 +103,7 @@ public function isFile($path) {
   */
  public function chmodJailed($path, $mode, $recursive) {
    if (!ftp_chmod($this->connection, $mode, $path)) {
      throw new FileTransferException("Unable to set permissions on %file", NULL, ['%file' => $path]);
      throw new FileTransferException("Unable to set permissions on %file", 0, ['%file' => $path]);
    }
    if ($this->isDirectory($path) && $recursive) {
      $filelist = @ftp_nlist($this->connection, $path);
+1 −1
Changes for core/lib/Drupal/Core/FileTransfer/FileTransfer.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ final protected function checkPath($path) {
      ->realpath(substr($this->chroot . $path, 0, strlen($full_jail)));
    $full_path = $this->fixRemotePath($full_path, FALSE);
    if ($full_jail !== $full_path) {
      throw new FileTransferException('@directory is outside of the @jail', NULL, ['@directory' => $path, '@jail' => $this->jail]);
      throw new FileTransferException('@directory is outside of the @jail', 0, ['@directory' => $path, '@jail' => $this->jail]);
    }
  }

+9 −9
Changes for core/lib/Drupal/Core/FileTransfer/Local.php: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public static function factory($jail, $settings) {
   */
  protected function copyFileJailed($source, $destination) {
    if (@!copy($source, $destination)) {
      throw new FileTransferException('Cannot copy %source to %destination.', NULL, ['%source' => $source, '%destination' => $destination]);
      throw new FileTransferException('Cannot copy %source to %destination.', 0, ['%source' => $source, '%destination' => $destination]);
    }
  }

@@ -55,7 +55,7 @@ protected function copyFileJailed($source, $destination) {
   */
  protected function createDirectoryJailed($directory) {
    if (!is_dir($directory) && @!mkdir($directory, 0777, TRUE)) {
      throw new FileTransferException('Cannot create directory %directory.', NULL, ['%directory' => $directory]);
      throw new FileTransferException('Cannot create directory %directory.', 0, ['%directory' => $directory]);
    }
  }

@@ -65,24 +65,24 @@ protected function createDirectoryJailed($directory) {
  protected function removeDirectoryJailed($directory) {
    if (!is_dir($directory)) {
      // Programmer error assertion, not something we expect users to see.
      throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', NULL, ['%directory' => $directory]);
      throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', 0, ['%directory' => $directory]);
    }
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) {
      if ($file->isDir()) {
        if (@!$file_system->rmdir($filename)) {
          throw new FileTransferException('Cannot remove directory %directory.', NULL, ['%directory' => $filename]);
          throw new FileTransferException('Cannot remove directory %directory.', 0, ['%directory' => $filename]);
        }
      }
      elseif ($file->isFile()) {
        if (@!$this->fileSystem->unlink($filename)) {
          throw new FileTransferException('Cannot remove file %file.', NULL, ['%file' => $filename]);
          throw new FileTransferException('Cannot remove file %file.', 0, ['%file' => $filename]);
        }
      }
    }
    if (@!$file_system->rmdir($directory)) {
      throw new FileTransferException('Cannot remove directory %directory.', NULL, ['%directory' => $directory]);
      throw new FileTransferException('Cannot remove directory %directory.', 0, ['%directory' => $directory]);
    }
  }

@@ -91,7 +91,7 @@ protected function removeDirectoryJailed($directory) {
   */
  protected function removeFileJailed($file) {
    if (@!$this->fileSystem->unlink($file)) {
      throw new FileTransferException('Cannot remove file %file.', NULL, ['%file' => $file]);
      throw new FileTransferException('Cannot remove file %file.', 0, ['%file' => $file]);
    }
  }

@@ -116,12 +116,12 @@ public function chmodJailed($path, $mode, $recursive) {
    if ($recursive && is_dir($path)) {
      foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
        if (@!chmod($filename, $mode)) {
          throw new FileTransferException('Cannot chmod %path.', NULL, ['%path' => $filename]);
          throw new FileTransferException('Cannot chmod %path.', 0, ['%path' => $filename]);
        }
      }
    }
    elseif (@!chmod($path, $mode)) {
      throw new FileTransferException('Cannot chmod %path.', NULL, ['%path' => $path]);
      throw new FileTransferException('Cannot chmod %path.', 0, ['%path' => $path]);
    }
  }

+9 −9
Changes for core/lib/Drupal/Core/FileTransfer/SSH.php: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ public function __construct($jail, $username, $password, $hostname = "localhost"
  public function connect() {
    $this->connection = @ssh2_connect($this->hostname, $this->port);
    if (!$this->connection) {
      throw new FileTransferException('SSH Connection failed to @host:@port', NULL, ['@host' => $this->hostname, '@port' => $this->port]);
      throw new FileTransferException('SSH Connection failed to @host:@port', 0, ['@host' => $this->hostname, '@port' => $this->port]);
    }
    if (!@ssh2_auth_password($this->connection, $this->username, $this->password)) {
      throw new FileTransferException('The supplied username/password combination was not accepted.');
@@ -47,7 +47,7 @@ public static function factory($jail, $settings) {
   */
  protected function copyFileJailed($source, $destination) {
    if (!@ssh2_scp_send($this->connection, $source, $destination)) {
      throw new FileTransferException('Cannot copy @source_file to @destination_file.', NULL, ['@source' => $source, '@destination' => $destination]);
      throw new FileTransferException('Cannot copy @source_file to @destination_file.', 0, ['@source' => $source, '@destination' => $destination]);
    }
  }

@@ -56,7 +56,7 @@ protected function copyFileJailed($source, $destination) {
   */
  protected function copyDirectoryJailed($source, $destination) {
    if (@!ssh2_exec($this->connection, 'cp -Rp ' . escapeshellarg($source) . ' ' . escapeshellarg($destination))) {
      throw new FileTransferException('Cannot copy directory @directory.', NULL, ['@directory' => $source]);
      throw new FileTransferException('Cannot copy directory @directory.', 0, ['@directory' => $source]);
    }
  }

@@ -65,7 +65,7 @@ protected function copyDirectoryJailed($source, $destination) {
   */
  protected function createDirectoryJailed($directory) {
    if (@!ssh2_exec($this->connection, 'mkdir ' . escapeshellarg($directory))) {
      throw new FileTransferException('Cannot create directory @directory.', NULL, ['@directory' => $directory]);
      throw new FileTransferException('Cannot create directory @directory.', 0, ['@directory' => $directory]);
    }
  }

@@ -74,7 +74,7 @@ protected function createDirectoryJailed($directory) {
   */
  protected function removeDirectoryJailed($directory) {
    if (@!ssh2_exec($this->connection, 'rm -Rf ' . escapeshellarg($directory))) {
      throw new FileTransferException('Cannot remove @directory.', NULL, ['@directory' => $directory]);
      throw new FileTransferException('Cannot remove @directory.', 0, ['@directory' => $directory]);
    }
  }

@@ -83,7 +83,7 @@ protected function removeDirectoryJailed($directory) {
   */
  protected function removeFileJailed($destination) {
    if (!@ssh2_exec($this->connection, 'rm ' . escapeshellarg($destination))) {
      throw new FileTransferException('Cannot remove @directory.', NULL, ['@directory' => $destination]);
      throw new FileTransferException('Cannot remove @directory.', 0, ['@directory' => $destination]);
    }
  }

@@ -103,7 +103,7 @@ public function isDirectory($path) {
      return FALSE;
    }
    else {
      throw new FileTransferException('Cannot check @path.', NULL, ['@path' => $path]);
      throw new FileTransferException('Cannot check @path.', 0, ['@path' => $path]);
    }
  }

@@ -120,7 +120,7 @@ public function isFile($path) {
      return FALSE;
    }
    else {
      throw new FileTransferException('Cannot check @path.', NULL, ['@path' => $path]);
      throw new FileTransferException('Cannot check @path.', 0, ['@path' => $path]);
    }
  }

@@ -130,7 +130,7 @@ public function isFile($path) {
  public function chmodJailed($path, $mode, $recursive) {
    $cmd = sprintf("chmod %s%o %s", $recursive ? '-R ' : '', $mode, escapeshellarg($path));
    if (@!ssh2_exec($this->connection, $cmd)) {
      throw new FileTransferException('Cannot change permissions of @path.', NULL, ['@path' => $path]);
      throw new FileTransferException('Cannot change permissions of @path.', 0, ['@path' => $path]);
    }
  }

Loading