cellog Sun Oct 26 05:49:24 2008 UTC
Modified files:
/php-src/ext/phar phar.c phar_object.c util.c
Log:
MFB: fix several errors found by valgrind
1 - entry metadata not properly processed or retrieved from cached phars
2 - copy on write was using a void return value instead of int, a dangerous
oversight in phar_update_cached_entry
3 - metadata creation in entries for cached phars was causing an invalid read
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.c?r1=1.390&r2=1.391&diff_format=u
Index: php-src/ext/phar/phar.c
diff -u php-src/ext/phar/phar.c:1.390 php-src/ext/phar/phar.c:1.391
--- php-src/ext/phar/phar.c:1.390 Sun Oct 12 21:09:10 2008
+++ php-src/ext/phar/phar.c Sun Oct 26 05:49:24 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: phar.c,v 1.390 2008/10/12 21:09:10 tony2001 Exp $ */
+/* $Id: phar.c,v 1.391 2008/10/26 05:49:24 cellog Exp $ */
#define PHAR_MAIN 1
#include "phar_internal.h"
@@ -1035,6 +1035,7 @@
/* check whether we have meta data, zero check works regardless of byte
order */
if (mydata->is_persistent) {
PHAR_GET_32(buffer, mydata->metadata_len);
+ if (!mydata->metadata_len) buffer -= 4;
if (phar_parse_metadata(&buffer, &mydata->metadata,
mydata->metadata_len TSRMLS_CC) == FAILURE) {
MAPPHAR_FAIL("unable to read phar metadata in .phar
file \"%s\"");
}
@@ -1114,7 +1115,9 @@
}
if (entry.is_persistent) {
- if (phar_parse_metadata(&buffer, &entry.metadata, 0
TSRMLS_CC) == FAILURE) {
+ PHAR_GET_32(buffer, entry.metadata_len);
+ if (!entry.metadata_len) buffer -= 4;
+ if (phar_parse_metadata(&buffer, &entry.metadata,
entry.metadata_len TSRMLS_CC) == FAILURE) {
pefree(entry.filename, entry.is_persistent);
MAPPHAR_FAIL("unable to read file metadata in
.phar file \"%s\"");
}
@@ -3622,7 +3625,7 @@
php_info_print_table_header(2, "Phar: PHP Archive support", "enabled");
php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION);
php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION);
- php_info_print_table_row(2, "CVS revision", "$Revision: 1.390 $");
+ php_info_print_table_row(2, "CVS revision", "$Revision: 1.391 $");
php_info_print_table_row(2, "Phar-based phar archives", "enabled");
php_info_print_table_row(2, "Tar-based phar archives", "enabled");
php_info_print_table_row(2, "ZIP-based phar archives", "enabled");
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar_object.c?r1=1.289&r2=1.290&diff_format=u
Index: php-src/ext/phar/phar_object.c
diff -u php-src/ext/phar/phar_object.c:1.289
php-src/ext/phar/phar_object.c:1.290
--- php-src/ext/phar/phar_object.c:1.289 Fri Oct 24 14:34:15 2008
+++ php-src/ext/phar/phar_object.c Sun Oct 26 05:49:24 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: phar_object.c,v 1.289 2008/10/24 14:34:15 felipe Exp $ */
+/* $Id: phar_object.c,v 1.290 2008/10/26 05:49:24 cellog Exp $ */
#include "phar_internal.h"
#include "func_interceptors.h"
@@ -4583,6 +4583,15 @@
PHAR_ENTRY_OBJECT();
if (entry_obj->ent.entry->metadata) {
+ if (entry_obj->ent.entry->is_persistent) {
+ zval *ret;
+ char *buf = estrndup((char *)
entry_obj->ent.entry->metadata, entry_obj->ent.entry->metadata_len);
+ /* assume success, we would have failed before */
+ phar_parse_metadata(&buf, &ret,
entry_obj->ent.entry->metadata_len TSRMLS_CC);
+ efree(buf);
+ RETURN_ZVAL(ret, 0, 1);
+ return;
+ }
RETURN_ZVAL(entry_obj->ent.entry->metadata, 1, 0);
}
}
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/util.c?r1=1.68&r2=1.69&diff_format=u
Index: php-src/ext/phar/util.c
diff -u php-src/ext/phar/util.c:1.68 php-src/ext/phar/util.c:1.69
--- php-src/ext/phar/util.c:1.68 Sun Oct 12 19:40:29 2008
+++ php-src/ext/phar/util.c Sun Oct 26 05:49:24 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: util.c,v 1.68 2008/10/12 19:40:29 cellog Exp $ */
+/* $Id: util.c,v 1.69 2008/10/26 05:49:24 cellog Exp $ */
#include "phar_internal.h"
@@ -2198,7 +2198,7 @@
}
/* }}} */
-static void phar_update_cached_entry(void *data, void *argument) /* {{{ */
+static int phar_update_cached_entry(void *data, void *argument) /* {{{ */
{
phar_entry_info *entry = (phar_entry_info *)data;
TSRMLS_FETCH();
@@ -2221,7 +2221,7 @@
if (entry->metadata_len) {
char *buf = estrndup((char *) entry->metadata,
entry->metadata_len);
/* assume success, we would have failed before */
- phar_parse_metadata((char **) &entry->metadata,
&entry->metadata, entry->metadata_len TSRMLS_CC);
+ phar_parse_metadata((char **) &buf, &entry->metadata,
entry->metadata_len TSRMLS_CC);
efree(buf);
} else {
zval *t;
@@ -2239,6 +2239,7 @@
entry->metadata_str.len = 0;
}
}
+ return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php