|
34 | 34 | #include "ftp.h" |
35 | 35 | #include "ftp_arginfo.h" |
36 | 36 |
|
| 37 | +#define PHP_FTP_TIMEOUT_SEC_MAX ((uint64_t)((double) PHP_TIMEOUT_ULL_MAX / 1000000.0)) |
| 38 | + |
37 | 39 | static zend_class_entry *php_ftp_ce = NULL; |
38 | 40 | static zend_object_handlers ftp_object_handlers; |
39 | 41 |
|
@@ -143,15 +145,13 @@ PHP_FUNCTION(ftp_connect) |
143 | 145 | RETURN_THROWS(); |
144 | 146 | } |
145 | 147 |
|
146 | | - const uint64_t timeoutmax = (uint64_t)((double) PHP_TIMEOUT_ULL_MAX / 1000000.0); |
147 | | - |
148 | 148 | if (timeout_sec <= 0) { |
149 | 149 | zend_argument_value_error(3, "must be greater than 0"); |
150 | 150 | RETURN_THROWS(); |
151 | 151 | } |
152 | 152 |
|
153 | | - if (timeout_sec >= timeoutmax) { |
154 | | - zend_argument_value_error(3, "must be less than " ZEND_ULONG_FMT, timeoutmax); |
| 153 | + if (timeout_sec >= PHP_FTP_TIMEOUT_SEC_MAX) { |
| 154 | + zend_argument_value_error(3, "must be less than " ZEND_ULONG_FMT, PHP_FTP_TIMEOUT_SEC_MAX); |
155 | 155 | RETURN_THROWS(); |
156 | 156 | } |
157 | 157 |
|
@@ -192,6 +192,11 @@ PHP_FUNCTION(ftp_ssl_connect) |
192 | 192 | RETURN_THROWS(); |
193 | 193 | } |
194 | 194 |
|
| 195 | + if (timeout_sec >= PHP_FTP_TIMEOUT_SEC_MAX) { |
| 196 | + zend_argument_value_error(3, "must be less than " ZEND_ULONG_FMT, PHP_FTP_TIMEOUT_SEC_MAX); |
| 197 | + RETURN_THROWS(); |
| 198 | + } |
| 199 | + |
195 | 200 | /* connect */ |
196 | 201 | if (!(ftp = ftp_open(host, (short)port, timeout_sec))) { |
197 | 202 | RETURN_FALSE; |
@@ -1284,6 +1289,10 @@ PHP_FUNCTION(ftp_set_option) |
1284 | 1289 | zend_argument_value_error(3, "must be greater than 0 for the FTP_TIMEOUT_SEC option"); |
1285 | 1290 | RETURN_THROWS(); |
1286 | 1291 | } |
| 1292 | + if ((uint64_t) Z_LVAL_P(z_value) >= PHP_FTP_TIMEOUT_SEC_MAX) { |
| 1293 | + zend_argument_value_error(3, "must be less than " ZEND_ULONG_FMT " for the FTP_TIMEOUT_SEC option", PHP_FTP_TIMEOUT_SEC_MAX); |
| 1294 | + RETURN_THROWS(); |
| 1295 | + } |
1287 | 1296 | ftp->timeout_sec = Z_LVAL_P(z_value); |
1288 | 1297 | RETURN_TRUE; |
1289 | 1298 | case PHP_FTP_OPT_AUTOSEEK: |
|
0 commit comments