com php-src: Fixed null termination: ext/spl/spl_directory. c ext/spl/tests/bug65545.phpt
| From: | Tjerk Anne Meesters | Date: | Fri, 07 Mar 2014 11:23:46 +0000 |
| Subject: | com php-src: Fixed null termination: ext/spl/spl_directory. c ext/spl/tests/bug65545.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-76387@lists.php.net to get a copy of this message | ||
Commit: 972935cd957ed626fcdb66f0e770ae6c429156d4
Author: Tjerk Meesters <datibbaw@php.net> Fri, 7 Mar 2014 19:23:46 +0800
Parents: 091b7f841bdd873494c7523f856d882d025969b3
Branches: PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=972935cd957ed626fcdb66f0e770ae6c429156d4
Log:
Fixed null termination
Changed paths:
M ext/spl/spl_directory.c
M ext/spl/tests/bug65545.phpt
Diff:
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 6689771..3fbf2ce 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -2865,7 +2865,8 @@ SPL_METHOD(SplFileObject, fread)
Z_STRVAL_P(return_value) = emalloc(length + 1);
Z_STRLEN_P(return_value) = php_stream_read(intern->u.file.stream, Z_STRVAL_P(return_value),
length);
- Z_STRVAL_P(return_value)[length] = 0;
+ /* needed because recv/read/gzread doesnt put a null at the end*/
+ Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0;
Z_TYPE_P(return_value) = IS_STRING;
}
diff --git a/ext/spl/tests/bug65545.phpt b/ext/spl/tests/bug65545.phpt
index b43f10f..76c29cb 100644
--- a/ext/spl/tests/bug65545.phpt
+++ b/ext/spl/tests/bug65545.phpt
@@ -12,6 +12,10 @@ var_dump($data);
$data = $obj->fread(0);
var_dump($data);
+// read more data than is available
+$data = $obj->fread(filesize(__FILE__) + 32);
+var_dump(strlen($data) === filesize(__FILE__) - 5);
+
?>
--EXPECTF--
string(5) "<?php"
@@ -21,3 +25,4 @@ NULL
Warning: SplFileObject::fread(): Length parameter must be greater than 0 in %s on line %d
bool(false)
+bool(true)