# [PATCH] Fixed bug #68839 Possible null pointer dereference

- Thread: https://externals.io/message/80565
- Original archive: https://news-web.php.net/php.internals/80565
- Started by Joshua Rogers on 2015-01-15T16:31:51+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #80565 — Joshua Rogers — 2015-01-15T16:31:51+00:00

URL: https://externals.io/message/80565#80565

---
 ext/phar/zip.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/ext/phar/zip.c b/ext/phar/zip.c
index 2a95580..2117b0e 100644
--- a/ext/phar/zip.c
+++ b/ext/phar/zip.c
@@ -1217,7 +1217,9 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
 	if (!phar->is_temporary_alias && phar->alias_len) {
 		entry.fp = php_stream_fopen_tmpfile();
 		if (entry.fp == NULL) {
-			spprintf(error, 0, "phar error: unable to create temporary file");
+			if (error) {
+				spprintf(error, 0, "phar error: unable to create temporary file");
+			}
 			return EOF;
 		}
 		if (phar->alias_len != (int)php_stream_write(entry.fp, phar->alias, phar->alias_len)) {
@@ -1309,7 +1311,9 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
 		len = pos - user_stub + 18;
 		entry.fp = php_stream_fopen_tmpfile();
 		if (entry.fp == NULL) {
-			spprintf(error, 0, "phar error: unable to create temporary file");
+			if (error) {
+				spprintf(error, 0, "phar error: unable to create temporary file");
+			}
 			return EOF;
 		}
 		entry.uncompressed_filesize = len + 5;
@@ -1346,7 +1350,9 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
 		/* Either this is a brand new phar (add the stub), or the default stub is required (overwrite the stub) */
 		entry.fp = php_stream_fopen_tmpfile();
 		if (entry.fp == NULL) {
-			spprintf(error, 0, "phar error: unable to create temporary file");
+			if (error) {
+				spprintf(error, 0, "phar error: unable to create temporary file");
+			}
 			return EOF;
 		}
 		if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) {
-- 
1.9.1

---

## #80568 — Michael Wallner — 2015-01-15T16:41:16+00:00

URL: https://externals.io/message/80565#80568 · In reply to: #80565

> ---
>  ext/phar/zip.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/ext/phar/zip.c b/ext/phar/zip.c
> index 2a95580..2117b0e 100644
> --- a/ext/phar/zip.c
> +++ b/ext/phar/zip.c
> @@ -1217,7 +1217,9 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
>  	if (!phar->is_temporary_alias && phar->alias_len) {
>  		entry.fp = php_stream_fopen_tmpfile();
>  		if (entry.fp == NULL) {
> -			spprintf(error, 0, "phar error: unable to create temporary file");
> +			if (error) {
> +				spprintf(error, 0, "phar error: unable to create temporary file");
> +			}
>  			return EOF;
>  		}
>  		if (phar->alias_len != (int)php_stream_write(entry.fp, phar->alias, phar->alias_len)) {
> @@ -1309,7 +1311,9 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
>  		len = pos - user_stub + 18;
>  		entry.fp = php_stream_fopen_tmpfile();
>  		if (entry.fp == NULL) {
> -			spprintf(error, 0, "phar error: unable to create temporary file");
> +			if (error) {
> +				spprintf(error, 0, "phar error: unable to create temporary file");
> +			}
>  			return EOF;
>  		}
>  		entry.uncompressed_filesize = len + 5;
> @@ -1346,7 +1350,9 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
>  		/* Either this is a brand new phar (add the stub), or the default stub is required (overwrite the stub) */
>  		entry.fp = php_stream_fopen_tmpfile();
>  		if (entry.fp == NULL) {
> -			spprintf(error, 0, "phar error: unable to create temporary file");
> +			if (error) {
> +				spprintf(error, 0, "phar error: unable to create temporary file");
> +			}
>  			return EOF;
>  		}
>  		if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) {
> 

Looks good.

-- 
Regards,
Mike

---

## #80569 — Joshua Rogers — 2015-01-15T16:48:29+00:00

URL: https://externals.io/message/80565#80569 · In reply to: #80568

Hi,

> Looks good.
There's another one(2) in /ext/phar/util.c:

--snip--
 911        if (error) {
 912                *error = NULL;
 913        }
 914        /* seek to start of internal file and read it */


 915        if (FAILURE == phar_open_entry_fp(entry, error, 1)) {
 916                return NULL;
 917        }
    

 918        if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 1)) {
 919                spprintf(error, 4096, "phar error: cannot seek to start of file \"%s\" in phar \"%s\"", entry->filename, phar->fname);
 920                return NULL;
 921        }
--snip--

Should the patch, perhaps be inside the spprintf() function?
That would take care of future problems, too.

Thoughts?



Thanks,
-- 
-- Joshua Rogers <https://internot.info/

---

## #80618 — Joshua Rogers — 2015-01-16T07:34:45+00:00

URL: https://externals.io/message/80565#80618 · In reply to: #80569

> Should the patch, perhaps be inside the spprintf() function?
> That would take care of future problems, too.
>
> Thoughts?
Ok, so, there are many many places where 'error' is not  checked against
NULL. So I'm going to submit a patch that will fix this in the spprintf
function instead of each use-case.


Thanks,
-- 
-- Joshua Rogers <https://internot.info/
