sniper          Tue Nov  1 12:05:10 2005 EDT

  Modified files:              (Branch: PHP_5_1)
    /php-src/ext/gd     gd.c gd_ctx.c php_gd.h 
  Log:
  MFH: - Added missing safe-mode checks
  # Added by replacing the existing open_basedir checks with a macro
  # Also, the filename passed might be null, etc. so it's not very good
  # idea to pass to php_error_docref() (catch by Ilia)
  
  
http://cvs.php.net/diff.php/php-src/ext/gd/gd.c?r1=1.312.2.3&r2=1.312.2.4&ty=u
Index: php-src/ext/gd/gd.c
diff -u php-src/ext/gd/gd.c:1.312.2.3 php-src/ext/gd/gd.c:1.312.2.4
--- php-src/ext/gd/gd.c:1.312.2.3       Wed Oct 26 17:38:20 2005
+++ php-src/ext/gd/gd.c Tue Nov  1 12:05:09 2005
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: gd.c,v 1.312.2.3 2005/10/26 21:38:20 tony2001 Exp $ */
+/* $Id: gd.c,v 1.312.2.4 2005/11/01 17:05:09 sniper Exp $ */
 
 /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
    Cold Spring Harbor Labs. */
@@ -706,7 +706,7 @@
 
        convert_to_string_ex(file);
 
-       stream = php_stream_open_wrapper(Z_STRVAL_PP(file), "rb", IGNORE_PATH | 
IGNORE_URL_WIN | REPORT_ERRORS, NULL);
+       stream = php_stream_open_wrapper(Z_STRVAL_PP(file), "rb", 
ENFORCE_SAFE_MODE | IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL);
        if (stream == NULL) {
                RETURN_FALSE;
        }
@@ -1519,7 +1519,7 @@
 
        fn = Z_STRVAL_PP(file);
 
-       stream = php_stream_open_wrapper(fn, "rb", 
REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
+       stream = php_stream_open_wrapper(fn, "rb", 
ENFORCE_SAFE_MODE|REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
        if (stream == NULL)     {
                RETURN_FALSE;
        }
@@ -1727,10 +1727,7 @@
        }
 
        if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) {
-               if (!fn || php_check_open_basedir(fn TSRMLS_CC) || 
(PG(safe_mode) && !php_checkuid(fn, "rb+", CHECKUID_CHECK_FILE_AND_DIR))) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid 
filename '%s'", fn);
-                       RETURN_FALSE;
-               }
+               PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
 
                fp = VCWD_FOPEN(fn, "wb");
                if (!fp) {
@@ -3826,16 +3823,10 @@
        }
 
        /* Check origin file */
-       if (!fn_org || php_check_open_basedir(fn_org TSRMLS_CC)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid origin 
filename '%s'", fn_org);
-               RETURN_FALSE;
-       }
+       PHP_GD_CHECK_OPEN_BASEDIR(fn_org, "Invalid origin filename");
 
        /* Check destination file */
-       if (!fn_dest || php_check_open_basedir(fn_dest TSRMLS_CC)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid 
destination filename '%s'", fn_dest);
-               RETURN_FALSE;
-       }
+       PHP_GD_CHECK_OPEN_BASEDIR(fn_dest, "Invalid destination filename");
 
        /* Open origin file */
        org = VCWD_FOPEN(fn_org, "rb");
http://cvs.php.net/diff.php/php-src/ext/gd/gd_ctx.c?r1=1.22.2.1&r2=1.22.2.2&ty=u
Index: php-src/ext/gd/gd_ctx.c
diff -u php-src/ext/gd/gd_ctx.c:1.22.2.1 php-src/ext/gd/gd_ctx.c:1.22.2.2
--- php-src/ext/gd/gd_ctx.c:1.22.2.1    Thu Oct  6 16:47:40 2005
+++ php-src/ext/gd/gd_ctx.c     Tue Nov  1 12:05:09 2005
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: gd_ctx.c,v 1.22.2.1 2005/10/06 20:47:40 iliaa Exp $ */
+/* $Id: gd_ctx.c,v 1.22.2.2 2005/11/01 17:05:09 sniper Exp $ */
 
 #include "php_gd.h"
 
@@ -82,10 +82,8 @@
        }
 
        if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) {
-               if (!fn || php_check_open_basedir(fn TSRMLS_CC) || 
(PG(safe_mode) && !php_checkuid(fn, "rb+", CHECKUID_CHECK_FILE_AND_DIR))) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid 
filename '%s'", fn);
-                       RETURN_FALSE;
-               }
+
+               PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
 
                fp = VCWD_FOPEN(fn, "wb");
                if (!fp) {
http://cvs.php.net/diff.php/php-src/ext/gd/php_gd.h?r1=1.59&r2=1.59.2.1&ty=u
Index: php-src/ext/gd/php_gd.h
diff -u php-src/ext/gd/php_gd.h:1.59 php-src/ext/gd/php_gd.h:1.59.2.1
--- php-src/ext/gd/php_gd.h:1.59        Wed Aug  3 10:07:13 2005
+++ php-src/ext/gd/php_gd.h     Tue Nov  1 12:05:09 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_gd.h,v 1.59 2005/08/03 14:07:13 sniper Exp $ */
+/* $Id: php_gd.h,v 1.59.2.1 2005/11/01 17:05:09 sniper Exp $ */
 
 #ifndef PHP_GD_H
 #define PHP_GD_H
@@ -30,6 +30,15 @@
 
 #if HAVE_LIBGD
 
+/* open_basedir and safe_mode checks */
+#define PHP_GD_CHECK_OPEN_BASEDIR(filename, errormsg)                          
         \
+       if (!filename || php_check_open_basedir(filename TSRMLS_CC) ||          
            \
+               (PG(safe_mode) && !php_checkuid(filename, "rb+", 
CHECKUID_CHECK_FILE_AND_DIR))  \
+       ) {                                                                     
            \
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, errormsg);          
                \
+               RETURN_FALSE;                                                   
                \
+       }
+
 #define PHP_GDIMG_TYPE_GIF      1
 #define PHP_GDIMG_TYPE_PNG      2
 #define PHP_GDIMG_TYPE_JPG      3

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to