cvs: php4 /ext/zlib zlib.c

From: Date: Mon, 26 Jun 2000 17:40:24 +0000
Subject: cvs: php4 /ext/zlib zlib.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-488@lists.php.net to get a copy of this message
zeev Mon Jun 26 10:40:24 2000 EDT Modified files: /php4/ext/zlib zlib.c Log: - Please NEVER copy fopen_wrappers.c functions to modules. They are ugly - enough as is and need cleaning up. Duplicating the mess makes things just - worse and prevents bug fixes in the functions from propogating throughout - PHP. - This fix is untested so someone who uses zlib, please test it and report - back. Index: php4/ext/zlib/zlib.c diff -u php4/ext/zlib/zlib.c:1.48 php4/ext/zlib/zlib.c:1.49 --- php4/ext/zlib/zlib.c:1.48 Sun Jun 25 10:02:46 2000 +++ php4/ext/zlib/zlib.c Mon Jun 26 10:40:24 2000 @@ -16,7 +16,7 @@ | Stefan Röhrich <sr@linux.de> | +----------------------------------------------------------------------+ */ -/* $Id: zlib.c,v 1.48 2000/06/25 17:02:46 zeev Exp $ */ +/* $Id: zlib.c,v 1.49 2000/06/26 17:40:24 zeev Exp $ */ #define IS_EXT_MODULE #include "php.h" @@ -150,129 +150,16 @@ php_info_print_table_end(); } -static gzFile *php_gzopen_with_path(char *filename, char *mode, char *path, char **opened_path); - static gzFile php_gzopen_wrapper(char *path, char *mode, int options) { - PLS_FETCH(); - - if (options & USE_PATH && PG(include_path) != NULL) { - return php_gzopen_with_path(path, mode, PG(include_path), NULL); - } - else { - if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!php_checkuid(path, NULL, 1))) { - return NULL; - } - if (php_check_open_basedir(path)) return NULL; - return gzopen(path, mode); - } -} + FILE *f; -/* - * Tries to open a .gz-file with a PATH-style list of directories. - * If the filename starts with "." or "/", the path is ignored. - */ -static gzFile *php_gzopen_with_path(char *filename, char *mode, char *path, char **opened_path) -{ - char *pathbuf, *ptr, *end; - char trypath[MAXPATHLEN + 1]; - struct stat sb; - gzFile *zp; - PLS_FETCH(); - - if (opened_path) { - *opened_path = NULL; - } - - /* Relative path open */ - if (*filename == '.') { - if (PG(safe_mode) &&(!php_checkuid(filename, NULL, 2))) { - return(NULL); - } - if (php_check_open_basedir(filename)) return NULL; - zp = gzopen(filename, mode); - if (zp && opened_path) { - *opened_path = expand_filepath(filename); - } - return zp; - } + f = php_fopen_wrapper(path, mode, options & ~IGNORE_URL, NULL, NULL, NULL); - /* Absolute path open - prepend document_root in safe mode */ -#ifdef PHP_WIN32 - if ((*filename == '\\')||(*filename == '/')||(filename[1] == ':')) { -#else - if (*filename == '/') { -#endif - if (PG(safe_mode)) { - if(PG(doc_root)) { - snprintf(trypath, MAXPATHLEN, "%s%s", PG(doc_root), filename); - } else { - strlcpy(trypath,filename,sizeof(trypath)); - } - if (!php_checkuid(trypath, NULL, 2)) { - return(NULL); - } - if (php_check_open_basedir(trypath)) return NULL; - zp = gzopen(trypath, mode); - if (zp && opened_path) { - *opened_path = expand_filepath(trypath); - } - return zp; - } else { - if (php_check_open_basedir(filename)) return NULL; - return gzopen(filename, mode); - } - } - - if (!path || (path && !*path)) { - if (PG(safe_mode) &&(!php_checkuid(filename, NULL, 2))) { - return(NULL); - } - if (php_check_open_basedir(filename)) return NULL; - zp = gzopen(filename, mode); - if (zp && opened_path) { - *opened_path = strdup(filename); - } - return zp; - } - - pathbuf = estrdup(path); - - ptr = pathbuf; - - while (ptr && *ptr) { -#ifdef PHP_WIN32 - end = strchr(ptr, ';'); -#else - end = strchr(ptr, ':'); -#endif - if (end != NULL) { - *end = '\0'; - end++; - } - snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename); - if (PG(safe_mode)) { - if (V_STAT(trypath,&sb) == 0 &&(!php_checkuid(trypath, NULL, 2))) { - efree(pathbuf); - return(NULL); - } - } - if ((zp = gzopen(trypath, mode)) != NULL) { - if (php_check_open_basedir(trypath)) { - gzclose(zp); - efree(pathbuf); - return NULL; - } - if (opened_path) { - *opened_path = expand_filepath(trypath); - } - efree(pathbuf); - return zp; - } - ptr = end; + if (!f) { + return NULL; } - efree(pathbuf); - return NULL; + return gzdopen(fileno(f), mode); } /* {{{ proto array gzfile(string filename [, int use_include_path])

« previous php.cvs (#488) next »