From a5612288433836c7793850a72d278ee10364a72e Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Sat, 23 Feb 2008 18:09:31 +0000 Subject: [PATCH] revert previous changes to tar.c, fix incorrect user_stub == dummy check, now things work that should --- ext/phar/tar.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ext/phar/tar.c b/ext/phar/tar.c index e95c7237cf..a6d8ad5496 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -475,7 +475,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er } /* set stub */ - if (user_stub && user_stub != "dummy") { + if (user_stub && (len < 0 || (len = sizeof("dummy") - 1 && !strncmp(user_stub, "dummy", sizeof("dummy")-1)))) { char *pos; if (len < 0) { /* resource passed in */ @@ -534,15 +534,12 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er } } else { /* Either this is a brand new phar (add the stub), or setDefaultStub() is the caller (overwrite the stub) */ - if (zend_hash_exists(&phar->manifest, ".phar/stub.php", sizeof(".phar/stub.php")-1)) { - goto no_default_stub; - } entry.fp = php_stream_fopen_tmpfile(); if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { + php_stream_close(entry.fp); if (error) { spprintf(error, 0, "unable to %s stub in%star-based phar \"%s\", failed", user_stub ? "overwrite" : "create", user_stub ? " " : " new ", phar->fname); } - php_stream_close(entry.fp); return EOF; } entry.uncompressed_filesize = entry.compressed_filesize = sizeof(newstub) - 1; @@ -550,13 +547,18 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er entry.filename_len = sizeof(".phar/stub.php")-1; if (!user_stub) { - if (SUCCESS != zend_hash_add(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { + if (!zend_hash_exists(&phar->manifest, ".phar/stub.php", sizeof(".phar/stub.php")-1)) { + if (SUCCESS != zend_hash_add(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { + php_stream_close(entry.fp); + efree(entry.filename); + if (error) { + spprintf(error, 0, "unable to create stub in tar-based phar \"%s\"", phar->fname); + } + return EOF; + } + } else { php_stream_close(entry.fp); efree(entry.filename); - if (error) { - spprintf(error, 0, "unable to create stub in tar-based phar \"%s\"", phar->fname); - } - return EOF; } } else { if (SUCCESS != zend_hash_update(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { @@ -569,7 +571,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er } } } -no_default_stub: + if (phar->fp && !phar->is_brandnew) { oldfile = phar->fp; closeoldfile = 0; -- 2.50.1