From: Markus Fischer Date: Sat, 18 May 2002 13:31:31 +0000 (+0000) Subject: - Fix portability issues with empty results on Linux and FreeBSD, add safe_mode X-Git-Tag: php-4.3.0dev-ZendEngine2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25a616d7aab4acb903e167ad64523752af01d34d;p=php - Fix portability issues with empty results on Linux and FreeBSD, add safe_mode check and simplify code. # Hartmut, what was the VCWD check for ?! --- diff --git a/ext/standard/dir.c b/ext/standard/dir.c index e14eb56dae..51a1f53080 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -327,30 +327,38 @@ PHP_NAMED_FUNCTION(php_if_readdir) PHP_FUNCTION(glob) { char *pattern = NULL; - int argc = ZEND_NUM_ARGS(); int pattern_len; - long flags; + long flags = 0; glob_t globbuf; - zval *new_val; - int n; - char path[MAXPATHLEN]; - char *ret=NULL; + int n, ret; + + if (PG(safe_mode)) { + php_error(E_WARNING, "%s() SAFE MODE Restriction in effect, function is disabled", + get_active_function_name(TSRMLS_C)); + RETURN_FALSE; + } - if (zend_parse_parameters(argc TSRMLS_CC, "s|l", &pattern, &pattern_len, &flags) == FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &pattern, &pattern_len, &flags) == FAILURE) return; globbuf.gl_offs = 0; - if(glob(pattern, 0, NULL, &globbuf)) { + if (0 != (ret = glob(pattern, flags, NULL, &globbuf))) { +#ifdef GLOB_NOMATCH + if (GLOB_NOMATCH == ret) { + /* Linux handles no matches as an error condition, but FreeBSD + * doesn't. This ensure that if no match is found, an empty array + * is always returned so it can be used with worrying in e.g. + * foreach() */ + array_init(return_value); + return; + } +#endif RETURN_FALSE; } array_init(return_value); - for(n=0;n