Skip to content

Commit d81f2e5

Browse files
author
Ilia Alshanetsky
committed
Added missing safe_mode checks.
Added support for additional libcurl options. Set CURLOPT_NOSIGNAL by default for ZTS, for signal free operation.
1 parent 7ef01f0 commit d81f2e5

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

ext/curl/interface.c

+53-5
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,26 @@ PHP_MINIT_FUNCTION(curl)
201201
REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD);
202202
REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE);
203203
REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT);
204+
REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE);
204205
REGISTER_CURL_CONSTANT(CURLOPT_CRLF);
205206
REGISTER_CURL_CONSTANT(CURLOPT_ENCODING);
207+
REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT);
208+
REGISTER_CURL_CONSTANT(CURLPROXY_HTTP);
209+
REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5);
210+
REGISTER_CURL_CONSTANT(CURLOPT_UNRESTRICTED_AUTH);
211+
REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT);
212+
REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES);
213+
214+
#ifdef CURLOPT_HTTPAUTH /* only in curl 7.10.6 */
215+
REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH);
216+
/* http authentication options */
217+
REGISTER_CURL_CONSTANT(CURLHTTP_BASIC);
218+
REGISTER_CURL_CONSTANT(CURLHTTP_DIGEST);
219+
REGISTER_CURL_CONSTANT(CURLHTTP_GSSNEGOTIATE);
220+
REGISTER_CURL_CONSTANT(CURLHTTP_NTLM);
221+
REGISTER_CURL_CONSTANT(CURLHTTP_ANY);
222+
REGISTER_CURL_CONSTANT(CURLHTTP_ANYSAFE);
223+
#endif
206224

207225
/* Constants effecting the way CURLOPT_CLOSEPOLICY works */
208226
REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
@@ -699,6 +717,9 @@ PHP_FUNCTION(curl_init)
699717
curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
700718
curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
701719
curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
720+
#if defined(ZTS)
721+
curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1);
722+
#endif
702723

703724
if (argc > 0) {
704725
char *urlcopy;
@@ -773,6 +794,13 @@ PHP_FUNCTION(curl_setopt)
773794
case CURLOPT_HTTPGET:
774795
case CURLOPT_HTTP_VERSION:
775796
case CURLOPT_CRLF:
797+
case CURLOPT_DNS_CACHE_TIMEOUT:
798+
case CURLOPT_PROXYPORT:
799+
case CURLOPT_FTP_USE_EPRT:
800+
#ifdef CURLOPT_HTTPAUTH /* only in curl 7.10.6 */
801+
case CURLOPT_HTTPAUTH:
802+
#endif
803+
case CURLOPT_UNRESTRICTED_AUTH:
776804
case CURLOPT_PORT:
777805
convert_to_long_ex(zvalue);
778806
error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
@@ -786,22 +814,19 @@ PHP_FUNCTION(curl_setopt)
786814
case CURLOPT_USERAGENT:
787815
case CURLOPT_FTPPORT:
788816
case CURLOPT_COOKIE:
789-
case CURLOPT_COOKIEFILE:
790817
case CURLOPT_REFERER:
791818
case CURLOPT_INTERFACE:
792819
case CURLOPT_KRB4LEVEL:
793-
case CURLOPT_RANDOM_FILE:
794820
case CURLOPT_EGDSOCKET:
795821
case CURLOPT_CAINFO:
796822
case CURLOPT_CAPATH:
797-
case CURLOPT_COOKIEJAR:
798823
case CURLOPT_SSL_CIPHER_LIST:
799824
case CURLOPT_SSLKEY:
800-
case CURLOPT_SSLCERT:
801825
case CURLOPT_SSLKEYTYPE:
802826
case CURLOPT_SSLKEYPASSWD:
803827
case CURLOPT_SSLENGINE:
804828
case CURLOPT_SSLENGINE_DEFAULT:
829+
case CURLOPT_SSLCERTTYPE:
805830
case CURLOPT_ENCODING: {
806831
char *copystr = NULL;
807832

@@ -969,14 +994,15 @@ PHP_FUNCTION(curl_setopt)
969994
break;
970995
case CURLOPT_HTTPHEADER:
971996
case CURLOPT_QUOTE:
997+
case CURLOPT_HTTP200ALIASES:
972998
case CURLOPT_POSTQUOTE: {
973999
zval **current;
9741000
HashTable *ph;
9751001
struct curl_slist *slist = NULL;
9761002

9771003
ph = HASH_OF(*zvalue);
9781004
if (!ph) {
979-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must pass either an object or an array with the CURLOPT_HTTPHEADER, CURLOPT_QUOTE and CURLOPT_POSTQUOTE arguments");
1005+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must pass either an object or an array with the CURLOPT_HTTPHEADER, CURLOPT_QUOTE, CURLOPT_HTTP200ALIASES and CURLOPT_POSTQUOTE arguments");
9801006
RETURN_FALSE;
9811007
}
9821008

@@ -1002,6 +1028,28 @@ PHP_FUNCTION(curl_setopt)
10021028

10031029
error = curl_easy_setopt(ch->cp, option, slist);
10041030

1031+
break;
1032+
}
1033+
/* the following options deal with files, therefor safe_mode & open_basedir checks
1034+
* are required.
1035+
*/
1036+
case CURLOPT_COOKIEJAR:
1037+
case CURLOPT_SSLCERT:
1038+
case CURLOPT_RANDOM_FILE:
1039+
case CURLOPT_COOKIEFILE: {
1040+
char *copystr = NULL;
1041+
1042+
convert_to_string_ex(zvalue);
1043+
1044+
if (php_check_open_basedir(Z_STRVAL_PP(zvalue) TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(Z_STRVAL_PP(zvalue), "rb+", CHECKUID_CHECK_MODE_PARAM))) {
1045+
RETURN_FALSE;
1046+
}
1047+
1048+
copystr = estrndup(Z_STRVAL_PP(zvalue), Z_STRLEN_PP(zvalue));
1049+
1050+
error = curl_easy_setopt(ch->cp, option, copystr);
1051+
zend_llist_add_element(&ch->to_free.str, &copystr);
1052+
10051053
break;
10061054
}
10071055
}

0 commit comments

Comments
 (0)