From db7dc95d15d2c82e3f06d6d2e28c806089047ab2 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Thu, 30 Apr 2009 04:40:31 +0000 Subject: [PATCH] MFPECL: fixed PECL Bug #14646: phar error message unclear with php stream wrappers --- ext/phar/phar.c | 12 +++++++- ext/phar/tests/phar_construct_invalidurl.phpt | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 ext/phar/tests/phar_construct_invalidurl.phpt diff --git a/ext/phar/phar.c b/ext/phar/phar.c index b2f6a82ade..4173cf0aab 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -1262,7 +1262,11 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al /* next try to create a new file */ if (FAILURE == phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, !is_data, 1, 1 TSRMLS_CC)) { if (error) { - spprintf(error, 0, "Cannot create phar '%s', file extension (or combination) not recognised", fname); + if (ext_len == -2) { + spprintf(error, 0, "Cannot create a phar archive from a URL like \"%s\". Phar objects can only be created from local files", fname); + } else { + spprintf(error, 0, "Cannot create phar '%s', file extension (or combination) not recognised", fname); + } } return FAILURE; } @@ -1903,6 +1907,12 @@ int phar_detect_phar_fname_ext(const char *filename, int filename_len, const cha pos = memchr(filename, '/', filename_len); if (pos && pos != filename) { + /* check for url like http:// or phar:// */ + if (*(pos - 1) == ':' && (pos - filename) < filename_len - 1 && *(pos + 1) == '/') { + *ext_len = -2; + *ext_str = NULL; + return FAILURE; + } if (zend_hash_exists(&(PHAR_GLOBALS->phar_alias_map), (char *) filename, pos - filename)) { *ext_str = pos; *ext_len = -1; diff --git a/ext/phar/tests/phar_construct_invalidurl.phpt b/ext/phar/tests/phar_construct_invalidurl.phpt new file mode 100644 index 0000000000..faac841261 --- /dev/null +++ b/ext/phar/tests/phar_construct_invalidurl.phpt @@ -0,0 +1,30 @@ +--TEST-- +Phar object passed URL +--INI-- +default_charset=UTF-8 +--SKIPIF-- + +--FILE-- +getMessage(),"\n"; +} +try { + $a = new Phar('http://'); +} catch (UnexpectedValueException $e) { + echo $e->getMessage(),"\n"; +} +try { + $a = new Phar('http:/'); +} catch (UnexpectedValueException $e) { + echo $e->getMessage(),"\n"; +} +?> +===DONE=== +--EXPECT-- +Cannot create a phar archive from a URL like "http://should.fail.com". Phar objects can only be created from local files +Cannot create a phar archive from a URL like "http://". Phar objects can only be created from local files +Cannot create phar 'http:/', file extension (or combination) not recognised +===DONE=== \ No newline at end of file -- 2.40.0