]> granicus.if.org Git - php/commitdiff
Avoid uninit warning in ftp
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 13:54:29 +0000 (15:54 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 13:54:29 +0000 (15:54 +0200)
ext/ftp/ftp.c

index 0196ef207d24d63109ce0d45b492418ba63ee796..b1343976b668c9dc9cec0d3ef5ec788704d52fa4 100644 (file)
@@ -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;
                }