From 67a9fd87835e2d2dd469b9ad30c8e517dc288d29 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Fri, 8 Feb 2008 01:06:12 +0000 Subject: [PATCH] fix mem leaks strip trailing slash if present in a directory entry. This code assumes that tar_type is directory, as it must be to be a valid directory. --- ext/phar/tar.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ext/phar/tar.c b/ext/phar/tar.c index 74f6c4984e..78b0022cde 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -184,6 +184,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i } php_stream_close(fp); zend_hash_destroy(&myphar->manifest); + myphar->manifest.arBuckets = 0; efree(myphar); return FAILURE; } @@ -201,6 +202,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i } php_stream_close(fp); zend_hash_destroy(&myphar->manifest); + myphar->manifest.arBuckets = 0; efree(myphar); return FAILURE; } @@ -214,10 +216,19 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i strcpy(name, hdr->prefix); strcat(name, hdr->name); entry.filename_len = strlen(name); + if (name[entry.filename_len - 1] == '/') { + /* some tar programs store directories with trailing slash */ + entry.filename_len--; + } entry.filename = estrndup(name, entry.filename_len); } else { entry.filename = estrdup(hdr->name); entry.filename_len = strlen(entry.filename); + if (entry.filename[entry.filename_len - 1] == '/') { + /* some tar programs store directories with trailing slash */ + entry.filename[entry.filename_len - 1] = '\0'; + entry.filename_len--; + } } entry.tar_type = ((old & (hdr->typeflag == 0))?'0':hdr->typeflag); @@ -246,6 +257,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i } php_stream_close(fp); zend_hash_destroy(&myphar->manifest); + myphar->manifest.arBuckets = 0; efree(myphar); return FAILURE; } @@ -269,6 +281,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i } php_stream_close(fp); zend_hash_destroy(&myphar->manifest); + myphar->manifest.arBuckets = 0; efree(myphar); return FAILURE; } @@ -293,6 +306,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i } php_stream_close(fp); zend_hash_destroy(&myphar->manifest); + myphar->manifest.arBuckets = 0; efree(myphar); return FAILURE; } @@ -404,7 +418,9 @@ int phar_tar_writeheaders(void *pDest, void *argument TSRMLS_DC) entry->is_modified = 0; if (entry->fp_type == PHAR_MOD && entry->fp != entry->phar->fp && entry->fp != entry->phar->ufp) { - php_stream_close(entry->fp); + if (!entry->fp_refcount) { + php_stream_close(entry->fp); + } entry->fp = NULL; } entry->fp_type = PHAR_FP; -- 2.50.1