Skip to content

Commit 91d59b1

Browse files
committed
Avoid uninit warning in ftp
1 parent 4b1491a commit 91d59b1

File tree

1 file changed

+59
-57
lines changed

1 file changed

+59
-57
lines changed

ext/ftp/ftp.c

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,20 +1391,71 @@ ftp_getresp(ftpbuf_t *ftp)
13911391
}
13921392
/* }}} */
13931393

1394-
/* {{{ my_send
1395-
*/
1396-
int
1397-
my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
1398-
{
1399-
zend_long size, sent;
1400-
int n;
1394+
int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) {
14011395
#ifdef HAVE_FTP_SSL
14021396
int err;
14031397
zend_bool retry = 0;
14041398
SSL *handle = NULL;
14051399
php_socket_t fd;
1400+
size_t sent;
1401+
1402+
if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) {
1403+
handle = ftp->ssl_handle;
1404+
fd = ftp->fd;
1405+
} else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
1406+
handle = ftp->data->ssl_handle;
1407+
fd = ftp->data->fd;
1408+
} else {
1409+
return send(s, buf, size, 0);
1410+
}
1411+
1412+
do {
1413+
sent = SSL_write(handle, buf, size);
1414+
err = SSL_get_error(handle, sent);
1415+
1416+
switch (err) {
1417+
case SSL_ERROR_NONE:
1418+
retry = 0;
1419+
break;
1420+
1421+
case SSL_ERROR_ZERO_RETURN:
1422+
retry = 0;
1423+
SSL_shutdown(handle);
1424+
break;
1425+
1426+
case SSL_ERROR_WANT_READ:
1427+
case SSL_ERROR_WANT_CONNECT: {
1428+
php_pollfd p;
1429+
int i;
1430+
1431+
p.fd = fd;
1432+
p.events = POLLOUT;
1433+
p.revents = 0;
1434+
1435+
i = php_poll2(&p, 1, 300);
1436+
1437+
retry = i > 0;
1438+
}
1439+
break;
1440+
1441+
default:
1442+
php_error_docref(NULL, E_WARNING, "SSL write failed");
1443+
return -1;
1444+
}
1445+
} while (retry);
1446+
return sent;
1447+
#else
1448+
return send(s, buf, size, 0);
14061449
#endif
1450+
}
14071451

1452+
/* {{{ my_send
1453+
*/
1454+
int
1455+
my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
1456+
{
1457+
zend_long size, sent;
1458+
int n;
14081459

14091460
size = len;
14101461
while (size) {
@@ -1423,56 +1474,7 @@ my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
14231474
return -1;
14241475
}
14251476

1426-
#ifdef HAVE_FTP_SSL
1427-
if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) {
1428-
handle = ftp->ssl_handle;
1429-
fd = ftp->fd;
1430-
} else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
1431-
handle = ftp->data->ssl_handle;
1432-
fd = ftp->data->fd;
1433-
}
1434-
1435-
if (handle) {
1436-
do {
1437-
sent = SSL_write(handle, buf, size);
1438-
err = SSL_get_error(handle, sent);
1439-
1440-
switch (err) {
1441-
case SSL_ERROR_NONE:
1442-
retry = 0;
1443-
break;
1444-
1445-
case SSL_ERROR_ZERO_RETURN:
1446-
retry = 0;
1447-
SSL_shutdown(handle);
1448-
break;
1449-
1450-
case SSL_ERROR_WANT_READ:
1451-
case SSL_ERROR_WANT_CONNECT: {
1452-
php_pollfd p;
1453-
int i;
1454-
1455-
p.fd = fd;
1456-
p.events = POLLOUT;
1457-
p.revents = 0;
1458-
1459-
i = php_poll2(&p, 1, 300);
1460-
1461-
retry = i > 0;
1462-
}
1463-
break;
1464-
1465-
default:
1466-
php_error_docref(NULL, E_WARNING, "SSL write failed");
1467-
return -1;
1468-
}
1469-
} while (retry);
1470-
} else {
1471-
#endif
1472-
sent = send(s, buf, size, 0);
1473-
#ifdef HAVE_FTP_SSL
1474-
}
1475-
#endif
1477+
sent = single_send(ftp, s, buf, size);
14761478
if (sent == -1) {
14771479
return -1;
14781480
}

0 commit comments

Comments
 (0)