]> granicus.if.org Git - php/commitdiff
Update LSAPI to 6.7, added support for 'filter_input'.
authorGeorge Wang <gwang@php.net>
Wed, 3 Sep 2014 15:24:45 +0000 (11:24 -0400)
committerGeorge Wang <gwang@php.net>
Wed, 3 Sep 2014 15:27:54 +0000 (11:27 -0400)
Fixed a crash in CLI mode.

sapi/litespeed/lsapi_main.c
sapi/litespeed/lsapilib.c

index 3413a423ac3165fff210ac986865ec9135ff7b23..cb7c66b44a162c54b6b3cbf93c84d1b636b8c9f6 100644 (file)
@@ -195,15 +195,22 @@ static char *sapi_lsapi_getenv( char * name, size_t name_len TSRMLS_DC )
 /* }}} */
 
 
-/*
+
+
 static int add_variable( const char * pKey, int keyLen, const char * pValue, int valLen,
                          void * arg )
 {
-    php_register_variable_safe((char *)pKey, (char *)pValue, valLen, (zval *)arg TSRMLS_CC);
-    return 1;
+       int filter_arg = (arg == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER;
+    char * new_val = (char *) pValue; 
+    unsigned int new_val_len;
+
+    if (sapi_module.input_filter(filter_arg, (char *)pKey, &new_val, valLen, &new_val_len TSRMLS_CC)) {
+        php_register_variable_safe((char *)pKey, new_val, new_val_len, (zval *)arg );
+    }
+       return 1;
 }
-*/
 
+/*
 static int add_variable( const char * pKey, int keyLen, const char * pValue, int valLen,
                          void * arg )
 {
@@ -222,6 +229,55 @@ static int add_variable( const char * pKey, int keyLen, const char * pValue, int
 #endif
     return 1;
 }
+*/
+
+static void litespeed_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
+{
+       char buf[128];
+       char **env, *p, *t = buf;
+       size_t alloc_size = sizeof(buf);
+       unsigned long nlen; /* ptrdiff_t is not portable */
+
+       if (PG(http_globals)[TRACK_VARS_ENV] &&
+               array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
+               Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
+               zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0
+       ) {
+               zval_dtor(array_ptr);
+               *array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
+               INIT_PZVAL(array_ptr);
+               zval_copy_ctor(array_ptr);
+               return;
+       } else if (PG(http_globals)[TRACK_VARS_SERVER] &&
+               array_ptr != PG(http_globals)[TRACK_VARS_SERVER] &&
+               Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
+               zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0
+       ) {
+               zval_dtor(array_ptr);
+               *array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
+               INIT_PZVAL(array_ptr);
+               zval_copy_ctor(array_ptr);
+               return;
+       }
+
+       for (env = environ; env != NULL && *env != NULL; env++) {
+               p = strchr(*env, '=');
+               if (!p) {                               /* malformed entry? */
+                       continue;
+               }
+               nlen = p - *env;
+               if (nlen >= alloc_size) {
+                       alloc_size = nlen + 64;
+                       t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
+               }
+               memcpy(t, *env, nlen);
+               t[nlen] = '\0';
+               add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr TSRMLS_CC);
+       }
+       if (t != buf && t != NULL) {
+               efree(t);
+       }
+}
 
 
 #if ((PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) || PHP_MAJOR_VERSION < 5)
@@ -268,7 +324,7 @@ static void sapi_lsapi_register_variables(zval *track_vars_array TSRMLS_DC)
             add_variable_magic_quote("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array );
         }
 #endif
-        php_import_environment_variables(track_vars_array TSRMLS_CC);
+        litespeed_php_import_environment_variables(track_vars_array TSRMLS_CC);
     } else {
         php_import_environment_variables(track_vars_array TSRMLS_CC);
 
@@ -370,7 +426,7 @@ static void sapi_lsapi_log_message(char *message TSRMLS_DC)
 static sapi_module_struct lsapi_sapi_module =
 {
     "litespeed",
-    "LiteSpeed V6.6",
+    "LiteSpeed V6.7",
 
     php_lsapi_startup,              /* startup */
     php_module_shutdown_wrapper,    /* shutdown */
index 786a3bd20b21df0c32422343f36b5c27211eefa9..aac823fc1c6408207ef0aa3ee29d81b57bea69de 100644 (file)
@@ -1912,9 +1912,13 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
     int ret;
     int count = 0;
     struct _headerInfo headers[512];
+
     if ( !pReq || !fn )
         return -1;
-    
+
+    if ( !pReq->m_pHeaderIndex )
+        return 0;
+
     for( i = 0; i < H_TRANSFER_ENCODING; ++i )
     {
         if ( pReq->m_pHeaderIndex->m_headerOff[i] )