]> granicus.if.org Git - php/commitdiff
- Check temp file creation
authorMarcus Boerger <helly@php.net>
Mon, 5 Feb 2007 22:11:27 +0000 (22:11 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 5 Feb 2007 22:11:27 +0000 (22:11 +0000)
ext/phar/phar.c

index 7434fb4bb8a341b8f85255f52075c52a6e633212..c85e2c00687c3e6b82eb629e67425ab032fca9a5 100644 (file)
@@ -381,6 +381,12 @@ static int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len
                if (for_write) {
                        /* open a new temp file for writing */
                        entry->fp = php_stream_fopen_tmpfile();
+                       if (!entry->fp) {
+                               if (error) {
+                                       spprintf(error, 0, "phar error: unable to create temprary file");
+                               }
+                               return FAILURE;
+                       }
                        (*ret)->fp = entry->fp;
                        entry->is_modified = 1;
                        phar->is_modified = 1;
@@ -468,6 +474,12 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char
        memset(&etemp, 0, sizeof(phar_entry_info));
        etemp.filename_len = path_len;
        etemp.fp = php_stream_fopen_tmpfile();
+       if (!etemp.fp) {
+               if (error) {
+                       spprintf(error, 0, "phar error: unable to create temorary file");
+               }
+               return NULL;
+       }
        etemp.fp_refcount = 1;
        etemp.is_modified = 1;
        etemp.filename = estrndup(path, path_len);
@@ -1904,6 +1916,15 @@ int phar_flush(phar_archive_data *archive, char *user_stub, long len, char **err
                closeoldfile = oldfile != NULL;
        }
        newfile = php_stream_fopen_tmpfile();
+       if (!newfile) {
+               if (error) {
+                       spprintf(error, 0, "unable to create temporary file");
+               }
+               if (closeoldfile) {
+                       php_stream_close(oldfile);
+               }
+               return EOF;
+       }
 
        if (user_stub) {
                if (len < 0) {
@@ -2068,6 +2089,17 @@ int phar_flush(phar_archive_data *archive, char *user_stub, long len, char **err
                in read count */
                entry->compressed_filesize = 0;
                entry->cfp = php_stream_fopen_tmpfile();
+               if (!entry->cfp) {
+                       if (error) {
+                               spprintf(error, 0, "unable to create temporary file");
+                       }
+                       if (closeoldfile) {
+                               php_stream_close(oldfile);
+                       }
+                       php_stream_close(newfile);
+                       efree(buf);
+                       return EOF;
+               }
                do {
                        read = php_stream_read(file, buf, 8192);
                        if (read) {