pollita         Sat Apr  9 15:36:50 2005 EDT

  Modified files:              
    /php-src/main/streams       streams.c 
  Log:
  Fold validation into an inlined function per Andi's suggestion
  
http://cvs.php.net/diff.php/php-src/main/streams/streams.c?r1=1.74&r2=1.75&ty=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.74 php-src/main/streams/streams.c:1.75
--- php-src/main/streams/streams.c:1.74 Wed Apr  6 04:26:06 2005
+++ php-src/main/streams/streams.c      Sat Apr  9 15:36:49 2005
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.74 2005/04/06 08:26:06 tony2001 Exp $ */
+/* $Id: streams.c,v 1.75 2005/04/09 19:36:49 pollita Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -1417,10 +1417,12 @@
        return SUCCESS;
 }
 
-/* API for registering GLOBAL wrappers */
-PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper 
*wrapper TSRMLS_DC)
+/* Validate protocol scheme names during registration
+ * Must conform to /^[a-zA-Z0-9+.-]+$/
+ */
+static inline int php_stream_wrapper_scheme_validate(char *protocol, int 
protocol_len)
 {
-       int i, protocol_len = strlen(protocol);
+       int i;
 
        for(i = 0; i < protocol_len; i++) {
                if (!isalnum((int)protocol[i]) &&
@@ -1431,6 +1433,18 @@
                }
        }
 
+       return SUCCESS;
+}
+
+/* API for registering GLOBAL wrappers */
+PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper 
*wrapper TSRMLS_DC)
+{
+       int protocol_len = strlen(protocol);
+
+       if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == 
FAILURE) {
+               return FAILURE;
+       }
+
        return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, 
wrapper, sizeof(*wrapper), NULL);
 }
 
@@ -1442,15 +1456,10 @@
 /* API for registering VOLATILE wrappers */
 PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, 
php_stream_wrapper *wrapper TSRMLS_DC)
 {
-       int i, protocol_len = strlen(protocol);
+       int protocol_len = strlen(protocol);
 
-       for(i = 0; i < protocol_len; i++) {
-               if (!isalnum((int)protocol[i]) &&
-                       protocol[i] != '+' &&
-                       protocol[i] != '-' &&
-                       protocol[i] != '.') {
-                       return FAILURE;
-               }
+       if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == 
FAILURE) {
+               return FAILURE;
        }
 
        if (!FG(stream_wrappers)) {

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

Reply via email to