Skip to content

Commit 179ca2b

Browse files
committed
Fix phpGH-16802: open_basedir bypass using curl extension
And fix a memleak while here. Closes phpGH-16804.
1 parent ed59c00 commit 179ca2b

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ PHP NEWS
1212
. Fixed bug GH-16799 (Assertion failure at Zend/zend_vm_execute.h:7469).
1313
(nielsdos)
1414

15+
- Curl:
16+
. Fixed bug GH-16802 (open_basedir bypass using curl extension). (nielsdos)
17+
1518
- FPM:
1619
. Fixed GH-16432 (PHP-FPM 8.2 SIGSEGV in fpm_get_status). (Jakub Zelenka)
1720

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

0 commit comments

Comments
 (0)