com php-src: Fix bug #72114 - int/size_t confusion in f read: ext/standard/file.c ext/standard/tests/file/bug 72114.phpt

From: Date: Tue, 10 May 2016 04:55:29 +0000
Subject: com php-src: Fix bug #72114 - int/size_t confusion in f read: ext/standard/file.c ext/standard/tests/file/bug 72114.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92195@lists.php.net to get a copy of this message
Commit: abd159cce48f3e34f08e4751c568e09677d5ec9c Author: Stanislav Malyshev <stas@php.net> Mon, 9 May 2016 21:55:29 -0700 Parents: 95ed19ae28009aa7b3ed42d5760478de82640560 Branches: PHP-5.5 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=abd159cce48f3e34f08e4751c568e09677d5ec9c Log: Fix bug #72114 - int/size_t confusion in fread Bugs: https://bugs.php.net/72114 Changed paths: M ext/standard/file.c A ext/standard/tests/file/bug72114.phpt Diff: diff --git a/ext/standard/file.c b/ext/standard/file.c index 0abc022..e39c84f 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1758,6 +1758,12 @@ PHPAPI PHP_FUNCTION(fread) RETURN_FALSE; } + if (len > INT_MAX) { + /* string length is int in 5.x so we can not read more than int */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be no more than %d", INT_MAX); + RETURN_FALSE; + } + Z_STRVAL_P(return_value) = emalloc(len + 1); Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len); diff --git a/ext/standard/tests/file/bug72114.phpt b/ext/standard/tests/file/bug72114.phpt new file mode 100644 index 0000000..5e591ee --- /dev/null +++ b/ext/standard/tests/file/bug72114.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #72114 (Integer underflow / arbitrary null write in fread/gzread) +--FILE-- +<?php +ini_set('memory_limit', "2500M"); +$fp = fopen("/dev/zero", "r"); +fread($fp, 2147483648); +?> +Done +--EXPECTF-- +Warning: fread(): Length parameter must be no more than 2147483647 in %s/bug72114.php on line %d +Done

« previous php.cvs (#92195) next »