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: 2021-02-09 16:16 UTC
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
 [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

Pull Requests

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
 [2021-02-09 16:00 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-02-09 16:00 UTC] cmb@php.net
I can only reproduce a segfault, if I call

    ssh2_disconnect($ssh_session);

If I call `closedir($folder)` before, I get another segfault, but
that one has already been reported as bug #79631.
 [2021-02-09 16:16 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC