@@ -188,9 +188,9 @@ ftp_close(ftpbuf_t *ftp)
188
188
SSL_shutdown (ftp -> ssl_handle );
189
189
SSL_free (ftp -> ssl_handle );
190
190
}
191
- #endif
191
+ #endif
192
192
closesocket (ftp -> fd );
193
- }
193
+ }
194
194
ftp_gc (ftp );
195
195
efree (ftp );
196
196
return NULL ;
@@ -262,23 +262,23 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass TSRMLS_DC)
262
262
if (!ftp_getresp (ftp )) {
263
263
return 0 ;
264
264
}
265
-
265
+
266
266
if (ftp -> resp != 234 ) {
267
267
if (!ftp_putcmd (ftp , "AUTH" , "SSL" )) {
268
268
return 0 ;
269
269
}
270
270
if (!ftp_getresp (ftp )) {
271
271
return 0 ;
272
272
}
273
-
273
+
274
274
if (ftp -> resp != 334 ) {
275
275
return 0 ;
276
276
} else {
277
277
ftp -> old_ssl = 1 ;
278
278
ftp -> use_ssl_for_data = 1 ;
279
279
}
280
280
}
281
-
281
+
282
282
ctx = SSL_CTX_new (SSLv23_client_method ());
283
283
if (ctx == NULL ) {
284
284
php_error_docref (NULL TSRMLS_CC , E_WARNING , "failed to create the SSL context" );
@@ -325,8 +325,8 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass TSRMLS_DC)
325
325
if (!ftp_getresp (ftp )) {
326
326
return 0 ;
327
327
}
328
-
329
- ftp -> use_ssl_for_data = (ftp -> resp >= 200 && ftp -> resp <=299 );
328
+
329
+ ftp -> use_ssl_for_data = (ftp -> resp >= 200 && ftp -> resp <=299 );
330
330
}
331
331
}
332
332
#endif
@@ -360,7 +360,7 @@ ftp_reinit(ftpbuf_t *ftp)
360
360
{
361
361
if (ftp == NULL ) {
362
362
return 0 ;
363
- }
363
+ }
364
364
365
365
ftp_gc (ftp );
366
366
@@ -395,7 +395,7 @@ ftp_syst(ftpbuf_t *ftp)
395
395
if (!ftp_putcmd (ftp , "SYST" , NULL )) {
396
396
return NULL ;
397
397
}
398
- if (!ftp_getresp (ftp ) || ftp -> resp != 215 ) {
398
+ if (!ftp_getresp (ftp ) || ftp -> resp != 215 ) {
399
399
return NULL ;
400
400
}
401
401
syst = ftp -> inbuf ;
@@ -431,14 +431,14 @@ ftp_pwd(ftpbuf_t *ftp)
431
431
if (!ftp_putcmd (ftp , "PWD" , NULL )) {
432
432
return NULL ;
433
433
}
434
- if (!ftp_getresp (ftp ) || ftp -> resp != 257 ) {
434
+ if (!ftp_getresp (ftp ) || ftp -> resp != 257 ) {
435
435
return NULL ;
436
436
}
437
437
/* copy out the pwd from response */
438
- if ((pwd = strchr (ftp -> inbuf , '"' )) == NULL ) {
438
+ if ((pwd = strchr (ftp -> inbuf , '"' )) == NULL ) {
439
439
return NULL ;
440
440
}
441
- if ((end = strrchr (++ pwd , '"' )) == NULL ) {
441
+ if ((end = strrchr (++ pwd , '"' )) == NULL ) {
442
442
return NULL ;
443
443
}
444
444
ftp -> pwd = estrndup (pwd , end - pwd );
@@ -608,7 +608,7 @@ ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filenam
608
608
if (!ftp_getresp (ftp ) || ftp -> resp != 200 ) {
609
609
return 0 ;
610
610
}
611
-
611
+
612
612
return 1 ;
613
613
}
614
614
/* }}} */
@@ -625,7 +625,7 @@ ftp_alloc(ftpbuf_t *ftp, const long size, char **response)
625
625
}
626
626
627
627
snprintf (buffer , sizeof (buffer ) - 1 , "%ld" , size );
628
-
628
+
629
629
if (!ftp_putcmd (ftp , "ALLO" , buffer )) {
630
630
return 0 ;
631
631
}
@@ -642,7 +642,7 @@ ftp_alloc(ftpbuf_t *ftp, const long size, char **response)
642
642
return 0 ;
643
643
}
644
644
645
- return 1 ;
645
+ return 1 ;
646
646
}
647
647
/* }}} */
648
648
@@ -674,7 +674,7 @@ ftp_type(ftpbuf_t *ftp, ftptype_t type)
674
674
if (ftp == NULL ) {
675
675
return 0 ;
676
676
}
677
- if (type == ftp -> type ) {
677
+ if (type == ftp -> type ) {
678
678
return 1 ;
679
679
}
680
680
if (type == FTPTYPE_ASCII ) {
@@ -765,7 +765,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv)
765
765
if (!ftp_putcmd (ftp , "PASV" , NULL )) {
766
766
return 0 ;
767
767
}
768
- if (!ftp_getresp (ftp ) || ftp -> resp != 227 ) {
768
+ if (!ftp_getresp (ftp ) || ftp -> resp != 227 ) {
769
769
return 0 ;
770
770
}
771
771
/* parse out the IP and port */
@@ -808,7 +808,7 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type,
808
808
if ((data = ftp_getdata (ftp TSRMLS_CC )) == NULL ) {
809
809
goto bail ;
810
810
}
811
-
811
+
812
812
ftp -> data = data ;
813
813
814
814
if (resumepos > 0 ) {
@@ -902,7 +902,7 @@ ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, l
902
902
if ((data = ftp_getdata (ftp TSRMLS_CC )) == NULL ) {
903
903
goto bail ;
904
904
}
905
- ftp -> data = data ;
905
+ ftp -> data = data ;
906
906
907
907
if (startpos > 0 ) {
908
908
snprintf (arg , sizeof (arg ), "%ld" , startpos );
@@ -1103,7 +1103,7 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args)
1103
1103
1104
1104
if (strpbrk (cmd , "\r\n" )) {
1105
1105
return 0 ;
1106
- }
1106
+ }
1107
1107
/* build the output buffer */
1108
1108
if (args && args [0 ]) {
1109
1109
/* "cmd args\r\n\0" */
@@ -1252,7 +1252,7 @@ my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
1252
1252
#if HAVE_OPENSSL_EXT
1253
1253
if (ftp -> use_ssl && ftp -> fd == s && ftp -> ssl_active ) {
1254
1254
sent = SSL_write (ftp -> ssl_handle , buf , size );
1255
- } else if (ftp -> use_ssl && ftp -> fd != s && ftp -> use_ssl_for_data && ftp -> data -> ssl_active ) {
1255
+ } else if (ftp -> use_ssl && ftp -> fd != s && ftp -> use_ssl_for_data && ftp -> data -> ssl_active ) {
1256
1256
sent = SSL_write (ftp -> data -> ssl_handle , buf , size );
1257
1257
} else {
1258
1258
#endif
@@ -1292,14 +1292,14 @@ my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
1292
1292
#if HAVE_OPENSSL_EXT
1293
1293
if (ftp -> use_ssl && ftp -> fd == s && ftp -> ssl_active ) {
1294
1294
nr_bytes = SSL_read (ftp -> ssl_handle , buf , len );
1295
- } else if (ftp -> use_ssl && ftp -> fd != s && ftp -> use_ssl_for_data && ftp -> data -> ssl_active ) {
1295
+ } else if (ftp -> use_ssl && ftp -> fd != s && ftp -> use_ssl_for_data && ftp -> data -> ssl_active ) {
1296
1296
nr_bytes = SSL_read (ftp -> data -> ssl_handle , buf , len );
1297
1297
} else {
1298
1298
#endif
1299
1299
nr_bytes = recv (s , buf , len , 0 );
1300
1300
#if HAVE_OPENSSL_EXT
1301
1301
}
1302
- #endif
1302
+ #endif
1303
1303
return (nr_bytes );
1304
1304
}
1305
1305
/* }}} */
@@ -1516,7 +1516,7 @@ data_accept(databuf_t *data, ftpbuf_t *ftp TSRMLS_DC)
1516
1516
1517
1517
data_accepted :
1518
1518
#if HAVE_OPENSSL_EXT
1519
-
1519
+
1520
1520
/* now enable ssl if we need to */
1521
1521
if (ftp -> use_ssl && ftp -> use_ssl_for_data ) {
1522
1522
ctx = SSL_CTX_new (SSLv23_client_method ());
@@ -1536,23 +1536,23 @@ data_accept(databuf_t *data, ftpbuf_t *ftp TSRMLS_DC)
1536
1536
SSL_CTX_free (ctx );
1537
1537
return 0 ;
1538
1538
}
1539
-
1540
-
1539
+
1540
+
1541
1541
SSL_set_fd (data -> ssl_handle , data -> fd );
1542
1542
1543
1543
if (ftp -> old_ssl ) {
1544
1544
SSL_copy_session_id (data -> ssl_handle , ftp -> ssl_handle );
1545
1545
}
1546
-
1546
+
1547
1547
if (SSL_connect (data -> ssl_handle ) <= 0 ) {
1548
1548
php_error_docref (NULL TSRMLS_CC , E_WARNING , "data_accept: SSL/TLS handshake failed" );
1549
1549
SSL_shutdown (data -> ssl_handle );
1550
1550
SSL_free (data -> ssl_handle );
1551
1551
return 0 ;
1552
1552
}
1553
-
1553
+
1554
1554
data -> ssl_active = 1 ;
1555
- }
1555
+ }
1556
1556
1557
1557
#endif
1558
1558
@@ -1567,24 +1567,24 @@ data_close(ftpbuf_t *ftp, databuf_t *data)
1567
1567
{
1568
1568
#if HAVE_OPENSSL_EXT
1569
1569
SSL_CTX * ctx ;
1570
- #endif
1570
+ #endif
1571
1571
if (data == NULL ) {
1572
1572
return NULL ;
1573
1573
}
1574
1574
if (data -> listener != -1 ) {
1575
1575
#if HAVE_OPENSSL_EXT
1576
1576
if (data -> ssl_active ) {
1577
-
1577
+
1578
1578
ctx = SSL_get_SSL_CTX (data -> ssl_handle );
1579
1579
SSL_CTX_free (ctx );
1580
1580
1581
1581
SSL_shutdown (data -> ssl_handle );
1582
1582
SSL_free (data -> ssl_handle );
1583
1583
data -> ssl_active = 0 ;
1584
1584
}
1585
- #endif
1585
+ #endif
1586
1586
closesocket (data -> listener );
1587
- }
1587
+ }
1588
1588
if (data -> fd != -1 ) {
1589
1589
#if HAVE_OPENSSL_EXT
1590
1590
if (data -> ssl_active ) {
@@ -1595,9 +1595,9 @@ data_close(ftpbuf_t *ftp, databuf_t *data)
1595
1595
SSL_free (data -> ssl_handle );
1596
1596
data -> ssl_active = 0 ;
1597
1597
}
1598
- #endif
1598
+ #endif
1599
1599
closesocket (data -> fd );
1600
- }
1600
+ }
1601
1601
if (ftp ) {
1602
1602
ftp -> data = NULL ;
1603
1603
}
@@ -1615,8 +1615,8 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
1615
1615
databuf_t * data = NULL ;
1616
1616
char * ptr ;
1617
1617
int ch , lastch ;
1618
- int size , rcvd ;
1619
- int lines ;
1618
+ size_t size , rcvd ;
1619
+ size_t lines ;
1620
1620
char * * ret = NULL ;
1621
1621
char * * entry ;
1622
1622
char * text ;
@@ -1634,7 +1634,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
1634
1634
if ((data = ftp_getdata (ftp TSRMLS_CC )) == NULL ) {
1635
1635
goto bail ;
1636
1636
}
1637
- ftp -> data = data ;
1637
+ ftp -> data = data ;
1638
1638
1639
1639
if (!ftp_putcmd (ftp , cmd , path )) {
1640
1640
goto bail ;
@@ -1658,7 +1658,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
1658
1658
lines = 0 ;
1659
1659
lastch = 0 ;
1660
1660
while ((rcvd = my_recv (ftp , data -> fd , data -> buf , FTP_BUFSIZE ))) {
1661
- if (rcvd == -1 ) {
1661
+ if (rcvd == -1 || rcvd > (( size_t )( -1 )) - size ) {
1662
1662
goto bail ;
1663
1663
}
1664
1664
@@ -1863,7 +1863,7 @@ ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type
1863
1863
if (!ftp_getresp (ftp ) || (ftp -> resp != 150 && ftp -> resp != 125 )) {
1864
1864
goto bail ;
1865
1865
}
1866
- if ((data = data_accept (data , ftp TSRMLS_CC )) == NULL ) {
1866
+ if ((data = data_accept (data , ftp TSRMLS_CC )) == NULL ) {
1867
1867
goto bail ;
1868
1868
}
1869
1869
ftp -> data = data ;
@@ -1919,7 +1919,7 @@ ftp_nb_continue_write(ftpbuf_t *ftp TSRMLS_DC)
1919
1919
goto bail ;
1920
1920
}
1921
1921
ftp -> data = data_close (ftp , ftp -> data );
1922
-
1922
+
1923
1923
if (!ftp_getresp (ftp ) || (ftp -> resp != 226 && ftp -> resp != 250 )) {
1924
1924
goto bail ;
1925
1925
}
0 commit comments