From: Christian Weiske Date: Wed, 29 Jun 2016 05:11:54 +0000 (+0200) Subject: Fix infinite loop when phancap tries to capture itself capturing itself X-Git-Tag: v0.3.0~10 X-Git-Url: https://git.cweiske.de/phancap.git/commitdiff_plain/39f9a7bf597c07be6cee65f60bec1fb33e04bbf0?ds=sidebyside Fix infinite loop when phancap tries to capture itself capturing itself --- diff --git a/src/phancap/Config.php b/src/phancap/Config.php index e45f08b..4c0617e 100644 --- a/src/phancap/Config.php +++ b/src/phancap/Config.php @@ -234,7 +234,7 @@ class Config * @return string Directory of URL without trailing slash, * and without .phar file */ - protected function getCurrentUrlDir() + public function getCurrentUrlDir() { $url = $this->getCurrentUrl(); $url = preg_replace('/\?.*$/', '', $url); diff --git a/www/get.php b/www/get.php index f78c3b5..694b843 100644 --- a/www/get.php +++ b/www/get.php @@ -46,6 +46,15 @@ try { exit(1); } +if (strpos($_SERVER['HTTP_USER_AGENT'], ' cutycapt ') !== false) { + //phancap is trying to render a page with an image that + // is being fetched from phancap itself, leading to an + // infinite loop + header('HTTP/1.0 500 Infinite Loop'); + header('Location: ' . $config->getCurrentUrlDir() . '/infinite.png'); + exit(3); +} + $rep = new Repository(); $rep->setConfig($config); try { diff --git a/www/infinite.png b/www/infinite.png new file mode 100644 index 0000000..2327d75 Binary files /dev/null and b/www/infinite.png differ