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;
}
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);
--- /dev/null
+--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===