[pecl-networking-ssh2] master: Fix SFTP path corruption for root-path URLs

From: Date: Wed, 14 Oct 2026 22:16:02 +0000
Subject: [pecl-networking-ssh2] master: Fix SFTP path corruption for root-path URLs
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-28702@lists.php.net to get a copy of this message
Author: transcendtient (transcendtient) Committer: Casper Langemeijer (langemeijer) Date: 2026-10-15T00:15:59+02:00 Commit: https://github.com/php/pecl-networking-ssh2/commit/20e3013a3d51aec885cdc9f11c85bd0cbaddce19 Raw diff: https://github.com/php/pecl-networking-ssh2/commit/20e3013a3d51aec885cdc9f11c85bd0cbaddce19.diff Fix SFTP path corruption for root-path URLs strstr() can match resource->path against the "://" scheme separator instead of the actual path when the path is short (e.g. "/"), corrupting ssh2.sftp://<id>/ URLs used for directory listings. Only run the search when # or ? is present, since that's the only case it's needed for. See https://github.com/php/pecl-networking-ssh2/issues/99 Changed paths: M ssh2_fopen_wrappers.c Diff: diff --git a/ssh2_fopen_wrappers.c b/ssh2_fopen_wrappers.c index 49d89e8..2bfc810 100644 --- a/ssh2_fopen_wrappers.c +++ b/ssh2_fopen_wrappers.c @@ -324,9 +324,15 @@ php_url *php_ssh2_fopen_wrapper_parse_path(const char *path, char *type, php_str Find resource->path in the original path string, then copy from that position to the end. This preserves ?query and #fragment (e.g. filenames containing '#') which php_url_parse() strips from resource->path. + Only search if # or ? is present, since a plain strstr() can otherwise + match resource->path against the "://" scheme separator (e.g. a root + path of "/" matching inside "ssh2.sftp://<id>/"). */ { - const char *path_in_original = strstr(path, ZSTR_VAL(resource->path)); + const char *path_in_original = NULL; + if (strpbrk(path, "#?") != NULL) { + path_in_original = strstr(path, ZSTR_VAL(resource->path)); + } if (path_in_original) { zend_string_release(resource->path); resource->path = zend_string_init(path_in_original, strlen(path_in_original), 0);

« previous php.pecl.cvs (#28702) next »