]> granicus.if.org Git - php/commitdiff
- Add additional check & test
authorMarcus Boerger <helly@php.net>
Mon, 5 Feb 2007 20:47:20 +0000 (20:47 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 5 Feb 2007 20:47:20 +0000 (20:47 +0000)
ext/phar/phar.c
ext/phar/tests/phar_stub_error.phpt [new file with mode: 0755]

index cd427ec3639c3f63ea9f46a32ebeefe38d0978ef..85bc153cc69bf71ad348f40bd9e1d0d1ab063745 100644 (file)
@@ -1876,7 +1876,7 @@ int phar_flush(phar_archive_data *archive, char *user_stub, long len, char **err
        static const char newstub[] = "<?php __HALT_COMPILER();";
        phar_entry_info *entry;
        int halt_offset, restore_alias_len, global_flags = 0, closeoldfile;
-       char *buf;
+       char *buf, *pos;
        char manifest[18], entry_buffer[24];
        off_t manifest_ftell;
        long offset;
@@ -1936,6 +1936,13 @@ int phar_flush(phar_archive_data *archive, char *user_stub, long len, char **err
                        }
                        archive->halt_offset = offset;
                } else {
+                       if ((pos = strstr(user_stub, "__HALT_COMPILER();")) == NULL)
+                       {
+                               if (error) {
+                                       spprintf(error, 0, "illegal stub for phar \"%s\"", archive->fname);
+                               }
+                               return EOF;
+                       }
                        if ((size_t)len != php_stream_write(newfile, user_stub, len)) {
                                if (closeoldfile) {
                                        php_stream_close(oldfile);
diff --git a/ext/phar/tests/phar_stub_error.phpt b/ext/phar/tests/phar_stub_error.phpt
new file mode 100755 (executable)
index 0000000..e8a3811
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--
+Phar::setStub()/getStub()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://' . $fname;
+$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
+$file = $stub;
+
+$files = array();
+$files['a'] = 'a';
+
+include 'phar_test.inc';
+
+$phar = new Phar($fname);
+var_dump($stub);
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+
+$newstub = '<?php echo "second stub\n"; _x_HALT_COMPILER(); ?>';
+try
+{
+       $phar->setStub($newstub);
+}
+catch(exception $e)
+{
+       echo 'Exception: ' . $e->getMessage() . "\n";
+}
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+$phar->commit();
+var_dump($phar->getStub());
+var_dump($phar->getStub() == $stub);
+
+?>
+===DONE===
+--CLEAN--
+<?php 
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECTF--
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+Exception: illegal stub for phar "%sphar_stub_error.phar.php"
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
+bool(true)
+===DONE===