[php-src] master: Merge branch 'PHP-7.4' into PHP-8.0

From: Date: Fri, 23 Apr 2021 13:59:08 +0000
Subject: [php-src] master: Merge branch 'PHP-7.4' into PHP-8.0
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-115789@lists.php.net to get a copy of this message
Author: Christoph M. Becker (cmb69) Date: 2021-04-23T15:57:11+02:00 Commit: https://github.com/php/php-src/commit/23a192d12dc026763cbed27a07b4d5f36554b141 Raw diff: https://github.com/php/php-src/commit/23a192d12dc026763cbed27a07b4d5f36554b141.diff Merge branch 'PHP-7.4' into PHP-8.0 * PHP-7.4: Fix #67792: HTTP Authorization schemes are treated as case-sensitive Changed paths: A sapi/cli/tests/php_cli_server_021.phpt M NEWS M main/main.c Diff: diff --git a/NEWS b/NEWS index 82f14f77493f5..1ae96a1e372d3 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - Core: . Fixed bug #80960 (opendir() warning wrong info when failed on Windows). (cmb) + . Fixed bug #67792 (HTTP Authorization schemes are treated as case-sensitive). + (cmb) - pgsql: . Fixed php_pgsql_fd_cast() wrt. php_stream_can_cast(). (cmb) diff --git a/main/main.c b/main/main.c index d59207f45cc30..0d399681d1325 100644 --- a/main/main.c +++ b/main/main.c @@ -2575,12 +2575,13 @@ PHPAPI void php_handle_aborted_connection(void) PHPAPI int php_handle_auth_data(const char *auth) { int ret = -1; + size_t auth_len = auth != NULL ? strlen(auth) : 0; - if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) { + if (auth && auth_len > 0 && zend_binary_strncasecmp(auth, auth_len, "Basic ", sizeof("Basic ")-1, sizeof("Basic ")-1) == 0) { char *pass; zend_string *user; - user = php_base64_decode((const unsigned char*)auth + 6, strlen(auth) - 6); + user = php_base64_decode((const unsigned char*)auth + 6, auth_len - 6); if (user) { pass = strchr(ZSTR_VAL(user), ':'); if (pass) { @@ -2599,7 +2600,7 @@ PHPAPI int php_handle_auth_data(const char *auth) SG(request_info).auth_digest = NULL; } - if (ret == -1 && auth && auth[0] != '\0' && strncmp(auth, "Digest ", 7) == 0) { + if (ret == -1 && auth && auth_len > 0 && zend_binary_strncasecmp(auth, auth_len, "Digest ", sizeof("Digest ")-1, sizeof("Digest ")-1) == 0) { SG(request_info).auth_digest = estrdup(auth + 7); ret = 0; } diff --git a/sapi/cli/tests/php_cli_server_021.phpt b/sapi/cli/tests/php_cli_server_021.phpt new file mode 100644 index 0000000000000..6269871b4c8e7 --- /dev/null +++ b/sapi/cli/tests/php_cli_server_021.phpt @@ -0,0 +1,37 @@ +--TEST-- +Digest Authentication +--SKIPIF-- +<?php +include "skipif.inc"; +?> +--FILE-- +<?php +include "php_cli_server.inc"; +php_cli_server_start('var_dump(!isset($_SERVER["PHP_AUTH_USER"]), !isset($_SERVER["PHP_AUTH_PW"]), $_SERVER["PHP_AUTH_DIGEST"]);'); + +$host = PHP_CLI_SERVER_HOSTNAME; +$fp = php_cli_server_connect(); + +if(fwrite($fp, <<<HEADER +GET / HTTP/1.1 +Host: {$host} +Authorization: digest username="Mufasa", realm="testrealm@host.com", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="6629fae49393a05397450978507c4ef1", opaque="5ccc069c403ebaf9f0171e9517f40e41" + + +HEADER +)) { + fpassthru($fp); +} + +?> +--EXPECTF-- +HTTP/1.1 200 OK +Host: %s +Date: %s +Connection: close +X-Powered-By: PHP/%s +Content-type: text/html; charset=UTF-8 + +bool(true) +bool(true) +string(242) "username="Mufasa", realm="testrealm@host.com", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="6629fae49393a05397450978507c4ef1", opaque="5ccc069c403ebaf9f0171e9517f40e41""

« previous php.cvs (#115789) next »