php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74831 opendir() over ssh2 works but triggers a segfault anyway (SFTP)
Submitted: 2017-06-29 15:09 UTC Modified: -
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: grossolini@php.net Assigned:
Status: Open Package: ssh2 (PECL)
PHP Version: 7.1.6 OS: Debian 8.8
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-06-29 15:09 UTC] grossolini@php.net
Description:
------------
When executing scripts, they work but the script ends with a "Segmentation fault".
This happens with php-7.1.6 as well as php-7.0.20, both using the ssh2-1.1.1.tgz release from pecl.php.net.
This does not happen when using php-5.6 with ssh2-0.13.tgz.

Test script:
---------------
<?php
$cfg_host = '';
$cfg_user = '';
$cfg_passwd = '';
$remote_folder = '';

$ssh_session = ssh2_connect($cfg_host);
if($ssh_session === FALSE) {
  exit(1);
}
elseif(!ssh2_auth_password($ssh_session, $cfg_user, $cfg_passwd)) {
  exit(1);
}
else {
  // ok
}

$sftp = ssh2_sftp($ssh_session);

if(ssh2_sftp_stat($sftp, $remote_folder) === FALSE) {
  // creating the folder is not in the scope of this script
  exit(0);
}

$remote_path = sprintf('ssh2.sftp://%s/%s', $sftp, ltrim($remote_folder, '/'));
$folder = opendir($remote_path);

return; // segmentation fault

Expected result:
----------------
not a segfault

Actual result:
--------------
"Segmentation fault" is written to STDERR when the script ends. You can do a bunch of work after calling opendir() without any problems, though.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-29 19:32 UTC] grossolini@php.net
Calling closedir($folder) makes the problem go away.

See Elizabeth M. Smith's comment here:
https://twitter.com/auroraeosrose/status/880502786483474433
 [2018-03-06 18:08 UTC] kweber at tccrocks dot com
Confirming that closedir($folder) solves this issue with PHP 7.1.15
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon May 27 01:01:25 2019 UTC