0001-fix-php_url-fields-usage-for-PHP-7-3.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. From a8835aab2c15e794fce13bd927295719e384ad2d Mon Sep 17 00:00:00 2001
  2. From: Remi Collet <remi@php.net>
  3. Date: Thu, 28 Jun 2018 07:10:35 +0200
  4. Subject: [PATCH] fix php_url fields usage for PHP 7.3
  5. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  6. [Retrieved from:
  7. https://github.com/php/pecl-networking-ssh2/commit/a8835aab2c15e794fce13bd927295719e384ad2d]
  8. ---
  9. php_ssh2.h | 8 +++++++
  10. ssh2_fopen_wrappers.c | 55 +++++++++++++++++++++++++++----------------
  11. ssh2_sftp.c | 20 ++++++++--------
  12. 3 files changed, 53 insertions(+), 30 deletions(-)
  13. diff --git a/php_ssh2.h b/php_ssh2.h
  14. index 734b795..d010ff9 100644
  15. --- a/php_ssh2.h
  16. +++ b/php_ssh2.h
  17. @@ -166,6 +166,14 @@ extern php_stream_wrapper php_ssh2_sftp_wrapper;
  18. extern int le_ssh2_session;
  19. extern int le_ssh2_sftp;
  20. +#if PHP_VERSION_ID < 70300
  21. +#define SSH2_URL_STR(a) (a)
  22. +#define SSH2_URL_LEN(a) strlen(a)
  23. +#else
  24. +#define SSH2_URL_STR(a) ZSTR_VAL(a)
  25. +#define SSH2_URL_LEN(a) ZSTR_LEN(a)
  26. +#endif
  27. +
  28. #endif /* PHP_SSH2_H */
  29. /*
  30. diff --git a/ssh2_fopen_wrappers.c b/ssh2_fopen_wrappers.c
  31. index 2f96ca4..f2f3475 100644
  32. --- a/ssh2_fopen_wrappers.c
  33. +++ b/ssh2_fopen_wrappers.c
  34. @@ -215,7 +215,7 @@ php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stre
  35. php_url *resource;
  36. zval *methods = NULL, *callbacks = NULL, zsession, *tmpzval;
  37. zend_long resource_id;
  38. - char *h, *s, *username = NULL, *password = NULL, *pubkey_file = NULL, *privkey_file = NULL;
  39. + char *h, *username = NULL, *password = NULL, *pubkey_file = NULL, *privkey_file = NULL;
  40. int username_len = 0, password_len = 0;
  41. h = strstr(path, "Resource id #");
  42. @@ -233,13 +233,13 @@ php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stre
  43. return NULL;
  44. }
  45. - if (strncmp(resource->scheme, "ssh2.", sizeof("ssh2.") - 1)) {
  46. + if (strncmp(SSH2_URL_STR(resource->scheme), "ssh2.", sizeof("ssh2.") - 1)) {
  47. /* Not an ssh wrapper */
  48. php_url_free(resource);
  49. return NULL;
  50. }
  51. - if (strcmp(resource->scheme + sizeof("ssh2.") - 1, type)) {
  52. + if (strcmp(SSH2_URL_STR(resource->scheme) + sizeof("ssh2.") - 1, type)) {
  53. /* Wrong ssh2. wrapper type */
  54. php_url_free(resource);
  55. return NULL;
  56. @@ -253,13 +253,27 @@ php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stre
  57. Find resource->path in the path string, then copy the entire string from the original path.
  58. This includes ?query#fragment in the path string
  59. */
  60. +// TODO copy seems uneeded
  61. +#if PHP_VERSION_ID < 70300
  62. + {
  63. + char * s;
  64. +
  65. s = resource->path;
  66. resource->path = estrdup(strstr(path, resource->path));
  67. efree(s);
  68. + }
  69. +#else
  70. + {
  71. + zend_string *tmp;
  72. +
  73. + tmp = resource->path;
  74. + resource->path = zend_string_init(ZSTR_VAL(resource->path), ZSTR_LEN(resource->path), 0);
  75. + zend_string_release(tmp);
  76. + }
  77. +#endif
  78. /* Look for a resource ID to reuse a session */
  79. - s = resource->host;
  80. - if (is_numeric_string(s, strlen(s), &resource_id, NULL, 0) == IS_LONG) {
  81. + if (is_numeric_string(SSH2_URL_STR(resource->host), SSH2_URL_LEN(resource->host), &resource_id, NULL, 0) == IS_LONG) {
  82. php_ssh2_sftp_data *sftp_data;
  83. zval *zresource;
  84. @@ -309,7 +323,7 @@ php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stre
  85. }
  86. /* Fallback on finding it in the context */
  87. - if (resource->host[0] == 0 && context && psftp &&
  88. + if (SSH2_URL_STR(resource->host)[0] == 0 && context && psftp &&
  89. (tmpzval = php_stream_context_get_option(context, "ssh2", "sftp")) != NULL &&
  90. Z_TYPE_P(tmpzval) == IS_RESOURCE) {
  91. php_ssh2_sftp_data *sftp_data;
  92. @@ -323,7 +337,7 @@ php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stre
  93. return resource;
  94. }
  95. }
  96. - if (resource->host[0] == 0 && context &&
  97. + if (SSH2_URL_STR(resource->host)[0] == 0 && context &&
  98. (tmpzval = php_stream_context_get_option(context, "ssh2", "session")) != NULL &&
  99. Z_TYPE_P(tmpzval) == IS_RESOURCE) {
  100. session = (LIBSSH2_SESSION *)zend_fetch_resource(Z_RES_P(tmpzval), PHP_SSH2_SESSION_RES_NAME, le_ssh2_session);
  101. @@ -399,19 +413,19 @@ php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stre
  102. }
  103. if (resource->user) {
  104. - int len = strlen(resource->user);
  105. + int len = SSH2_URL_LEN(resource->user);
  106. if (len) {
  107. - username = resource->user;
  108. + username = SSH2_URL_STR(resource->user);
  109. username_len = len;
  110. }
  111. }
  112. if (resource->pass) {
  113. - int len = strlen(resource->pass);
  114. + int len = SSH2_URL_LEN(resource->pass);
  115. if (len) {
  116. - password = resource->pass;
  117. + password = SSH2_URL_STR(resource->pass);
  118. password_len = len;
  119. }
  120. }
  121. @@ -422,7 +436,7 @@ php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stre
  122. return NULL;
  123. }
  124. - session = php_ssh2_session_connect(resource->host, resource->port, methods, callbacks);
  125. + session = php_ssh2_session_connect(SSH2_URL_STR(resource->host), resource->port, methods, callbacks);
  126. if (!session) {
  127. /* Unable to connect! */
  128. php_url_free(resource);
  129. @@ -482,6 +496,7 @@ php_url *php_ssh2_fopen_wraper_parse_path(const char *path, char *type, php_stre
  130. *psftp = sftp;
  131. }
  132. + //TODO may be undefined
  133. *presource_id = Z_LVAL(zsession);
  134. *psession = session;
  135. @@ -527,7 +542,7 @@ static php_stream *php_ssh2_shell_open(LIBSSH2_SESSION *session, int resource_id
  136. zval_copy_ctor(&copyval);
  137. convert_to_string(&copyval);
  138. if (libssh2_channel_setenv_ex(channel, key->val, key->len, Z_STRVAL(copyval), Z_STRLEN(copyval))) {
  139. - php_error_docref(NULL, E_WARNING, "Failed setting %s=%s on remote end", key, Z_STRVAL(copyval));
  140. + php_error_docref(NULL, E_WARNING, "Failed setting %s=%s on remote end", ZSTR_VAL(key), Z_STRVAL(copyval));
  141. }
  142. zval_dtor(&copyval);
  143. }
  144. @@ -631,7 +646,7 @@ static php_stream *php_ssh2_fopen_wrapper_shell(php_stream_wrapper *wrapper, con
  145. zval_ptr_dtor(&copyval);
  146. }
  147. - s = resource->path ? resource->path : NULL;
  148. + s = resource->path ? SSH2_URL_STR(resource->path) : NULL;
  149. if (s && s[0] == '/') {
  150. /* Terminal type encoded into URL overrides context terminal type */
  151. @@ -766,7 +781,7 @@ static php_stream *php_ssh2_exec_command(LIBSSH2_SESSION *session, int resource_
  152. zval_copy_ctor(&copyval);
  153. convert_to_string(&copyval);
  154. if (libssh2_channel_setenv_ex(channel, key->val, key->len, Z_STRVAL(copyval), Z_STRLEN(copyval))) {
  155. - php_error_docref(NULL, E_WARNING, "Failed setting %s=%s on remote end", key, Z_STRVAL(copyval));
  156. + php_error_docref(NULL, E_WARNING, "Failed setting %s=%s on remote end", ZSTR_VAL(key), Z_STRVAL(copyval));
  157. }
  158. zval_dtor(&copyval);
  159. }
  160. @@ -878,7 +893,7 @@ static php_stream *php_ssh2_fopen_wrapper_exec(php_stream_wrapper *wrapper, cons
  161. zval_ptr_dtor(copyval);
  162. }
  163. - stream = php_ssh2_exec_command(session, resource_id, resource->path + 1, terminal, terminal_len, environment, width, height, type);
  164. + stream = php_ssh2_exec_command(session, resource_id, SSH2_URL_STR(resource->path) + 1, terminal, terminal_len, environment, width, height, type);
  165. if (!stream) {
  166. // TODO Sean-Der
  167. //zend_list_delete(resource_id);
  168. @@ -1021,7 +1036,7 @@ static php_stream *php_ssh2_fopen_wrapper_scp(php_stream_wrapper *wrapper, const
  169. return NULL;
  170. }
  171. - stream = php_ssh2_scp_xfer(session, resource_id, resource->path);
  172. + stream = php_ssh2_scp_xfer(session, resource_id, SSH2_URL_STR(resource->path));
  173. if (!stream) {
  174. //TODO Sean-Der
  175. //zend_list_delete(resource_id);
  176. @@ -1147,7 +1162,7 @@ PHP_FUNCTION(ssh2_scp_send)
  177. char *error_msg = NULL;
  178. last_error = libssh2_session_last_error(session, &error_msg, NULL, 0);
  179. - php_error_docref(NULL, E_WARNING, "Failure creating remote file: %s", error_msg);
  180. + php_error_docref(NULL, E_WARNING, "Failure creating remote file: %s (%d)", error_msg, last_error);
  181. php_stream_close(local_file);
  182. RETURN_FALSE;
  183. }
  184. @@ -1262,10 +1277,10 @@ static php_stream *php_ssh2_fopen_wrapper_tunnel(php_stream_wrapper *wrapper, co
  185. return NULL;
  186. }
  187. - if (resource->path && resource->path[0] == '/') {
  188. + if (resource->path && SSH2_URL_STR(resource->path)[0] == '/') {
  189. char *colon;
  190. - host = resource->path + 1;
  191. + host = SSH2_URL_STR(resource->path) + 1;
  192. if (*host == '[') {
  193. /* IPv6 Encapsulated Format */
  194. host++;
  195. diff --git a/ssh2_sftp.c b/ssh2_sftp.c
  196. index 13f89f0..6332be8 100644
  197. --- a/ssh2_sftp.c
  198. +++ b/ssh2_sftp.c
  199. @@ -238,7 +238,7 @@ static php_stream *php_ssh2_sftp_stream_opener(php_stream_wrapper *wrapper, cons
  200. flags = php_ssh2_parse_fopen_modes((char *)mode);
  201. - handle = libssh2_sftp_open(sftp, resource->path, flags, perms);
  202. + handle = libssh2_sftp_open(sftp, SSH2_URL_STR(resource->path), flags, perms);
  203. if (!handle) {
  204. php_error_docref(NULL, E_WARNING, "Unable to open %s on remote host", filename);
  205. php_url_free(resource);
  206. @@ -341,7 +341,7 @@ static php_stream *php_ssh2_sftp_dirstream_opener(php_stream_wrapper *wrapper, c
  207. return NULL;
  208. }
  209. - handle = libssh2_sftp_opendir(sftp, resource->path);
  210. + handle = libssh2_sftp_opendir(sftp, SSH2_URL_STR(resource->path));
  211. if (!handle) {
  212. php_error_docref(NULL, E_WARNING, "Unable to open %s on remote host", filename);
  213. php_url_free(resource);
  214. @@ -386,7 +386,7 @@ static int php_ssh2_sftp_urlstat(php_stream_wrapper *wrapper, const char *url, i
  215. return -1;
  216. }
  217. - if (libssh2_sftp_stat_ex(sftp, resource->path, strlen(resource->path),
  218. + if (libssh2_sftp_stat_ex(sftp, SSH2_URL_STR(resource->path), SSH2_URL_LEN(resource->path),
  219. (flags & PHP_STREAM_URL_STAT_LINK) ? LIBSSH2_SFTP_LSTAT : LIBSSH2_SFTP_STAT, &attrs)) {
  220. php_url_free(resource);
  221. //zend_list_delete(sftp_rsrcid);
  222. @@ -420,7 +420,7 @@ static int php_ssh2_sftp_unlink(php_stream_wrapper *wrapper, const char *url, in
  223. return 0;
  224. }
  225. - result = libssh2_sftp_unlink(sftp, resource->path);
  226. + result = libssh2_sftp_unlink(sftp, SSH2_URL_STR(resource->path));
  227. php_url_free(resource);
  228. //zend_list_delete(sftp_rsrcid);
  229. @@ -462,7 +462,7 @@ static int php_ssh2_sftp_rename(php_stream_wrapper *wrapper, const char *url_fro
  230. return 0;
  231. }
  232. - result = libssh2_sftp_rename(sftp, resource->path, resource_to->path);
  233. + result = libssh2_sftp_rename(sftp, SSH2_URL_STR(resource->path), SSH2_URL_STR(resource_to->path));
  234. php_url_free(resource);
  235. php_url_free(resource_to);
  236. @@ -493,13 +493,13 @@ static int php_ssh2_sftp_mkdir(php_stream_wrapper *wrapper, const char *url, int
  237. if (options & PHP_STREAM_MKDIR_RECURSIVE) {
  238. /* Just attempt to make every directory, some will fail, but we only care about the last success/failure */
  239. - char *p = resource->path;
  240. + char *p = SSH2_URL_STR(resource->path);
  241. while ((p = strchr(p + 1, '/'))) {
  242. - libssh2_sftp_mkdir_ex(sftp, resource->path, p - resource->path, mode);
  243. + libssh2_sftp_mkdir_ex(sftp, SSH2_URL_STR(resource->path), p - SSH2_URL_STR(resource->path), mode);
  244. }
  245. }
  246. - result = libssh2_sftp_mkdir(sftp, resource->path, mode);
  247. + result = libssh2_sftp_mkdir(sftp, SSH2_URL_STR(resource->path), mode);
  248. php_url_free(resource);
  249. //zend_list_delete(sftp_rsrcid);
  250. @@ -527,7 +527,7 @@ static int php_ssh2_sftp_rmdir(php_stream_wrapper *wrapper, const char *url, int
  251. return 0;
  252. }
  253. - result = libssh2_sftp_rmdir(sftp, resource->path);
  254. + result = libssh2_sftp_rmdir(sftp, SSH2_URL_STR(resource->path));
  255. php_url_free(resource);
  256. //zend_list_delete(sftp_rsrcid);
  257. @@ -836,7 +836,7 @@ PHP_FUNCTION(ssh2_sftp_readlink)
  258. }
  259. if ((targ_len = libssh2_sftp_symlink_ex(data->sftp, link->val, link->len, targ, 8192, LIBSSH2_SFTP_READLINK)) < 0) {
  260. - php_error_docref(NULL, E_WARNING, "Unable to read link '%s'", link);
  261. + php_error_docref(NULL, E_WARNING, "Unable to read link '%s'", ZSTR_VAL(link));
  262. RETURN_FALSE;
  263. }