summaryrefslogtreecommitdiff
path: root/ext/ftp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-04-12 15:54:29 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-04-12 15:54:29 +0200
commit91d59b122aa6e05e1b92d6ae5b84807eeff572f5 (patch)
tree07d17685462254c3d4b5fbd99744a2e35f98f20e /ext/ftp
parent4b1491a7b1cb334f9d1f552d21ea1a4448fb3c40 (diff)
downloadphp-git-91d59b122aa6e05e1b92d6ae5b84807eeff572f5.tar.gz
Avoid uninit warning in ftp
Diffstat (limited to 'ext/ftp')
-rw-r--r--ext/ftp/ftp.c116
1 files changed, 59 insertions, 57 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 0196ef207d..b1343976b6 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -1391,20 +1391,71 @@ ftp_getresp(ftpbuf_t *ftp)
}
/* }}} */
-/* {{{ my_send
- */
-int
-my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
-{
- zend_long size, sent;
- int n;
+int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) {
#ifdef HAVE_FTP_SSL
int err;
zend_bool retry = 0;
SSL *handle = NULL;
php_socket_t fd;
+ size_t sent;
+
+ if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) {
+ handle = ftp->ssl_handle;
+ fd = ftp->fd;
+ } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
+ handle = ftp->data->ssl_handle;
+ fd = ftp->data->fd;
+ } else {
+ return send(s, buf, size, 0);
+ }
+
+ do {
+ sent = SSL_write(handle, buf, size);
+ err = SSL_get_error(handle, sent);
+
+ switch (err) {
+ case SSL_ERROR_NONE:
+ retry = 0;
+ break;
+
+ case SSL_ERROR_ZERO_RETURN:
+ retry = 0;
+ SSL_shutdown(handle);
+ break;
+
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_CONNECT: {
+ php_pollfd p;
+ int i;
+
+ p.fd = fd;
+ p.events = POLLOUT;
+ p.revents = 0;
+
+ i = php_poll2(&p, 1, 300);
+
+ retry = i > 0;
+ }
+ break;
+
+ default:
+ php_error_docref(NULL, E_WARNING, "SSL write failed");
+ return -1;
+ }
+ } while (retry);
+ return sent;
+#else
+ return send(s, buf, size, 0);
#endif
+}
+/* {{{ my_send
+ */
+int
+my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
+{
+ zend_long size, sent;
+ int n;
size = len;
while (size) {
@@ -1423,56 +1474,7 @@ my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
return -1;
}
-#ifdef HAVE_FTP_SSL
- if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) {
- handle = ftp->ssl_handle;
- fd = ftp->fd;
- } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
- handle = ftp->data->ssl_handle;
- fd = ftp->data->fd;
- }
-
- if (handle) {
- do {
- sent = SSL_write(handle, buf, size);
- err = SSL_get_error(handle, sent);
-
- switch (err) {
- case SSL_ERROR_NONE:
- retry = 0;
- break;
-
- case SSL_ERROR_ZERO_RETURN:
- retry = 0;
- SSL_shutdown(handle);
- break;
-
- case SSL_ERROR_WANT_READ:
- case SSL_ERROR_WANT_CONNECT: {
- php_pollfd p;
- int i;
-
- p.fd = fd;
- p.events = POLLOUT;
- p.revents = 0;
-
- i = php_poll2(&p, 1, 300);
-
- retry = i > 0;
- }
- break;
-
- default:
- php_error_docref(NULL, E_WARNING, "SSL write failed");
- return -1;
- }
- } while (retry);
- } else {
-#endif
- sent = send(s, buf, size, 0);
-#ifdef HAVE_FTP_SSL
- }
-#endif
+ sent = single_send(ftp, s, buf, size);
if (sent == -1) {
return -1;
}