com php-src: Fix bug #68089 - do not accept options with embedded \0: ext/curl/interface.c ext/curl/tests/bug68089.phpt

From: Date: Tue, 14 Oct 2014 17:51:46 +0000
Subject: com php-src: Fix bug #68089 - do not accept options with embedded \0: ext/curl/interface.c ext/curl/tests/bug68089.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-82304@lists.php.net to get a copy of this message
Commit: 81b67937e4561b23fa4e1cbbd6a7f1d444772bd6 Author: Stanislav Malyshev <stas@php.net> Sun, 28 Sep 2014 17:53:49 -0700 Parents: 3eb679b952f4655f178cf576584ef172602325ab Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=81b67937e4561b23fa4e1cbbd6a7f1d444772bd6 Log: Fix bug #68089 - do not accept options with embedded \0 Conflicts: ext/curl/interface.c Bugs: https://bugs.php.net/68089 Changed paths: M ext/curl/interface.c A ext/curl/tests/bug68089.phpt Diff: diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 6caaa52..65894c7 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -170,28 +170,20 @@ static int php_curl_option_str(php_curl *ch, zend_long option, const char *str, { CURLcode error = CURLE_OK; + if (strlen(str) != len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Curl option contains invalid characters (\\0)"); + return 0; + } + #if LIBCURL_VERSION_NUM >= 0x071100 if (make_copy) { #endif - char *copystr; - /* Strings passed to libcurl as 'char *' arguments, are copied by the library since 7.17.0 */ - copystr = estrndup(str, len); - error = curl_easy_setopt(ch->cp, option, copystr); - zend_llist_add_element(&ch->to_free->str, &copystr); -#if LIBCURL_VERSION_NUM >= 0x071100 - } else { - error = curl_easy_setopt(ch->cp, option, str); + if (strlen(url) != len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Curl option contains invalid characters (\\0)"); + return 0; } -#endif - SAVE_CURL_ERROR(ch, error) - - return error == CURLE_OK ? SUCCESS : FAILURE; -} - -static int php_curl_option_url(php_curl *ch, const char *url, const int len TSRMLS_DC) /* {{{ */ -{ /* Disable file:// if open_basedir are used */ if (PG(open_basedir) && *PG(open_basedir)) { #if LIBCURL_VERSION_NUM >= 0x071304 diff --git a/ext/curl/tests/bug68089.phpt b/ext/curl/tests/bug68089.phpt new file mode 100644 index 0000000..3bd5889 --- /dev/null +++ b/ext/curl/tests/bug68089.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #68089 (NULL byte injection - cURL lib) +--SKIPIF-- +<?php +include 'skipif.inc'; + +?> +--FILE-- +<?php +$url = "file:///etc/passwd\0http://google.com"; +$ch = curl_init(); +var_dump(curl_setopt($ch, CURLOPT_URL, $url)); +?> +Done +--EXPECTF-- +Warning: curl_setopt(): Curl option contains invalid characters (\0) in %s/bug68089.php on line 4 +bool(false) +Done

« previous php.cvs (#82304) next »