Skip to content

Commit 181a7d2

Browse files
committed
Fix GH-16802: open_basedir bypass using curl extension
And fix a memleak while here.
1 parent d1f86bc commit 181a7d2

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

ext/curl/interface.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,10 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue
19761976
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
19771977
#if LIBCURL_VERSION_NUM >= 0x075500 /* Available since 7.85.0 */
19781978
if ((option == CURLOPT_PROTOCOLS_STR || option == CURLOPT_REDIR_PROTOCOLS_STR) &&
1979-
(PG(open_basedir) && *PG(open_basedir)) && php_memnistr(ZSTR_VAL(str), "file", sizeof("file") - 1, ZSTR_VAL(str) + ZSTR_LEN(str)) != NULL) {
1979+
(PG(open_basedir) && *PG(open_basedir))
1980+
&& (php_memnistr(ZSTR_VAL(str), "file", sizeof("file") - 1, ZSTR_VAL(str) + ZSTR_LEN(str)) != NULL
1981+
|| php_memnistr(ZSTR_VAL(str), "all", sizeof("all") - 1, ZSTR_VAL(str) + ZSTR_LEN(str)) != NULL)) {
1982+
zend_tmp_string_release(tmp_str);
19801983
php_error_docref(NULL, E_WARNING, "The FILE protocol cannot be activated when an open_basedir is set");
19811984
return FAILURE;
19821985
}

ext/curl/tests/gh16802.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-16802 (open_basedir bypass using curl extension)
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php
7+
if (PHP_OS_FAMILY === "Windows") die("skip not for Windows");
8+
?>
9+
--INI--
10+
open_basedir=/nowhere
11+
--FILE--
12+
<?php
13+
$ch = curl_init("file:///etc/passwd");
14+
curl_setopt($ch, CURLOPT_PROTOCOLS_STR, "all");
15+
curl_setopt($ch, CURLOPT_PROTOCOLS_STR, "ftp,all");
16+
curl_setopt($ch, CURLOPT_PROTOCOLS_STR, "all,ftp");
17+
curl_setopt($ch, CURLOPT_PROTOCOLS_STR, "all,file,ftp");
18+
var_dump(curl_exec($ch));
19+
?>
20+
--EXPECTF--
21+
Warning: curl_setopt(): The FILE protocol cannot be activated when an open_basedir is set in %s on line %d
22+
23+
Warning: curl_setopt(): The FILE protocol cannot be activated when an open_basedir is set in %s on line %d
24+
25+
Warning: curl_setopt(): The FILE protocol cannot be activated when an open_basedir is set in %s on line %d
26+
27+
Warning: curl_setopt(): The FILE protocol cannot be activated when an open_basedir is set in %s on line %d
28+
bool(false)

0 commit comments

Comments
 (0)