Patch cleanup for 5.6.5 Binary diff removed From e78ac461dbefb7c4a3e9fde78d50fbc56b7b0183 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Mon, 28 Sep 2015 17:12:35 -0700 Subject: [PATCH] FIx bug #70433 - Uninitialized pointer in phar_make_dirstream when zip entry filename is "/" --- ext/phar/dirstream.c | 2 +- ext/phar/tests/bug70433.phpt | 23 +++++++++++++++++++++++ ext/phar/tests/bug70433.zip | Bin 0 -> 264 bytes 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ext/phar/tests/bug70433.phpt create mode 100755 ext/phar/tests/bug70433.zip diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index 75cf049..4728e29 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -198,7 +198,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC) zend_hash_internal_pointer_reset(manifest); while (FAILURE != zend_hash_has_more_elements(manifest)) { - if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &str_key, &keylen, &unused, 0, NULL)) { + if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &str_key, &keylen, &unused, 0, NULL)) { break; } From 1ddf72180a52d247db88ea42a3e35f824a8fbda1 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Mon, 28 Sep 2015 21:37:26 -0700 Subject: [PATCH] Better fix for bug #70433 --- ext/phar/dirstream.c | 2 +- ext/phar/util.c | 2 +- ext/phar/zip.c | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index 4728e29..75cf049 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -198,7 +198,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC) zend_hash_internal_pointer_reset(manifest); while (FAILURE != zend_hash_has_more_elements(manifest)) { - if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &str_key, &keylen, &unused, 0, NULL)) { + if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &str_key, &keylen, &unused, 0, NULL)) { break; } diff --git a/ext/phar/util.c b/ext/phar/util.c index e7decda..303daed 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -1970,7 +1970,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename while ((s = zend_memrchr(filename, '/', filename_len))) { filename_len = s - filename; - if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) { + if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) { break; } } diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 142165c..e4883d3 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -396,7 +396,9 @@ int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, if (entry.filename[entry.filename_len - 1] == '/') { entry.is_dir = 1; - entry.filename_len--; + if(entry.filename_len > 1) { + entry.filename_len--; + } entry.flags |= PHAR_ENT_PERM_DEF_DIR; } else { entry.is_dir = 0;