|
36 | 36 | #include "ftp.h" |
37 | 37 | #include "ftp_arginfo.h" |
38 | 38 |
|
| 39 | +#define PHP_FTP_TIMEOUT_SEC_MAX ((uint64_t)((double) PHP_TIMEOUT_ULL_MAX / 1000000.0)) |
| 40 | + |
39 | 41 | static zend_class_entry *php_ftp_ce = NULL; |
40 | 42 | static zend_object_handlers ftp_object_handlers; |
41 | 43 |
|
@@ -147,15 +149,13 @@ PHP_FUNCTION(ftp_connect) |
147 | 149 | RETURN_THROWS(); |
148 | 150 | } |
149 | 151 |
|
150 | | - const uint64_t timeoutmax = (uint64_t)((double) PHP_TIMEOUT_ULL_MAX / 1000000.0); |
151 | | - |
152 | 152 | if (timeout_sec <= 0) { |
153 | 153 | zend_argument_value_error(3, "must be greater than 0"); |
154 | 154 | RETURN_THROWS(); |
155 | 155 | } |
156 | 156 |
|
157 | | - if (timeout_sec >= timeoutmax) { |
158 | | - zend_argument_value_error(3, "must be less than " ZEND_ULONG_FMT, timeoutmax); |
| 157 | + if (timeout_sec >= PHP_FTP_TIMEOUT_SEC_MAX) { |
| 158 | + zend_argument_value_error(3, "must be less than " ZEND_ULONG_FMT, PHP_FTP_TIMEOUT_SEC_MAX); |
159 | 159 | RETURN_THROWS(); |
160 | 160 | } |
161 | 161 |
|
@@ -196,6 +196,11 @@ PHP_FUNCTION(ftp_ssl_connect) |
196 | 196 | RETURN_THROWS(); |
197 | 197 | } |
198 | 198 |
|
| 199 | + if (timeout_sec >= PHP_FTP_TIMEOUT_SEC_MAX) { |
| 200 | + zend_argument_value_error(3, "must be less than " ZEND_ULONG_FMT, PHP_FTP_TIMEOUT_SEC_MAX); |
| 201 | + RETURN_THROWS(); |
| 202 | + } |
| 203 | + |
199 | 204 | /* connect */ |
200 | 205 | if (!(ftp = ftp_open(host, (short)port, timeout_sec))) { |
201 | 206 | RETURN_FALSE; |
@@ -1291,6 +1296,10 @@ PHP_FUNCTION(ftp_set_option) |
1291 | 1296 | zend_argument_value_error(3, "must be greater than 0 for the FTP_TIMEOUT_SEC option"); |
1292 | 1297 | RETURN_THROWS(); |
1293 | 1298 | } |
| 1299 | + if ((uint64_t) Z_LVAL_P(z_value) >= PHP_FTP_TIMEOUT_SEC_MAX) { |
| 1300 | + zend_argument_value_error(3, "must be less than " ZEND_ULONG_FMT " for the FTP_TIMEOUT_SEC option", PHP_FTP_TIMEOUT_SEC_MAX); |
| 1301 | + RETURN_THROWS(); |
| 1302 | + } |
1294 | 1303 | ftp->timeout_sec = Z_LVAL_P(z_value); |
1295 | 1304 | RETURN_TRUE; |
1296 | 1305 | break; |
|
0 commit comments