]> granicus.if.org Git - php/commitdiff
name/value in multipart/form-date will be converted into internal encoding when mbstr...
authorRui Hirokawa <hirokawa@php.net>
Wed, 22 Oct 2003 14:14:05 +0000 (14:14 +0000)
committerRui Hirokawa <hirokawa@php.net>
Wed, 22 Oct 2003 14:14:05 +0000 (14:14 +0000)
ext/mbstring/mbstring.c
ext/mbstring/mbstring.h
main/rfc1867.c

index ab51a376c8fc915a4f044fce5fbb9f802ffff9ce..d0dd74602ba5a51a1c0c6908c8ca0418e49751b9 100644 (file)
@@ -3327,9 +3327,10 @@ MBSTRING_API size_t php_mb_gpc_mbchar_bytes(const char *s TSRMLS_DC)
 /* }}} */
 
 /*     {{{ MBSTRING_API int php_mb_gpc_encoding_converter() */
-MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, const char *encoding_to, const char *encoding_from 
+MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, const char *encoding_to, const char *encoding_from 
                TSRMLS_DC)
 {
+       int i;
        mbfl_string string, result, *ret;
        enum mbfl_no_encoding from_encoding, to_encoding;
        mbfl_buffer_converter *convd;
@@ -3358,36 +3359,40 @@ MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, const char
        mbfl_string_init(&result);
        string.no_encoding = from_encoding;
        string.no_language = MBSTRG(current_language);
-       string.val = (char*)(*str);
-       string.len = *len;
 
-       /* initialize converter */
-       convd = mbfl_buffer_converter_new(from_encoding, to_encoding, string.len);
-       if (convd == NULL) {
-               return -1;
-       }
-       mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
-       mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
+       for (i=0; i<num; i++){
+               string.val = (char*)str[i];
+               string.len = len[i];
 
-       /* do it */
-       ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
-       if (ret != NULL) {
-               efree(*str);
-               *str = ret->val;
-               *len = ret->len;
+               /* initialize converter */
+               convd = mbfl_buffer_converter_new(from_encoding, to_encoding, string.len);
+               if (convd == NULL) {
+                       return -1;
+               }
+               mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
+               mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
+               
+               /* do it */
+               ret = mbfl_buffer_converter_feed_result(convd, &string, &result);
+               if (ret != NULL) {
+                       efree(str[i]);
+                       str[i] = ret->val;
+                       len[i] = ret->len;
+               }
+               mbfl_buffer_converter_delete(convd);
        }
-       mbfl_buffer_converter_delete(convd);
 
        return ret ? 0 : -1;
 }
 
 /* {{{ MBSTRING_API int php_mb_gpc_encoding_detector()
  */
-MBSTRING_API int php_mb_gpc_encoding_detector(const char *arg_string, int arg_length, char *arg_list TSRMLS_DC)
+MBSTRING_API int php_mb_gpc_encoding_detector(char **arg_string, int *arg_length, int num, char *arg_list TSRMLS_DC)
 {
        mbfl_string string;
        enum mbfl_no_encoding *elist;
        enum mbfl_no_encoding encoding;
+       mbfl_encoding_detector *identd = NULL; 
 
        int size, *list;
 
@@ -3418,9 +3423,23 @@ MBSTRING_API int php_mb_gpc_encoding_detector(const char *arg_string, int arg_le
 
        mbfl_string_init(&string);
        string.no_language = MBSTRG(current_language);
-       string.val = (char*)arg_string;
-       string.len = arg_length;
-       encoding = mbfl_identify_encoding_no(&string, elist, size);
+
+       identd = mbfl_encoding_detector_new(elist, size);
+
+       if (identd) {
+               int n = 0;
+               while(n < num){
+                       string.val = (unsigned char *)arg_string[n];
+                       string.len = arg_length[n];
+                       if (mbfl_encoding_detector_feed(identd, &string)) {
+                               break;
+                       }
+                       n++;
+               }
+               encoding = mbfl_encoding_detector_judge(identd);
+               mbfl_encoding_detector_delete(identd);
+       }
+
        if (encoding != mbfl_no_encoding_invalid) {
                MBSTRG(http_input_identify) = encoding;
                return SUCCESS;
index 646ee72e3454e0b083110b1e5274aa7058413de1..b396ac17a5af58449d27a6d156f4cd2cf5cb4336 100644 (file)
@@ -143,9 +143,9 @@ MBSTRING_API int php_mb_encoding_detector_ex(const char *arg_string, int arg_len
 
 MBSTRING_API int php_mb_encoding_converter_ex(char **str, int *len, const char *encoding_to, 
                                                                                          const char *encoding_from TSRMLS_DC);
-MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, const char *encoding_to, const char *encoding_from TSRMLS_DC);
+MBSTRING_API int php_mb_gpc_encoding_converter(char **str, int *len, int num, const char *encoding_to, const char *encoding_from TSRMLS_DC);
 
-MBSTRING_API int php_mb_gpc_encoding_detector(const char *arg_string, int arg_length, char *arg_list TSRMLS_DC);
+MBSTRING_API int php_mb_gpc_encoding_detector(char **arg_string, int *arg_length, int num, char *arg_list TSRMLS_DC);
 
 ZEND_BEGIN_MODULE_GLOBALS(mbstring)
        enum mbfl_no_language language;
index 12ba613c2cebd6e2495de5c9e66b90f4e3225165..57b0e9ae93ae557aeecd96cb52d0a657113f9c27 100644 (file)
 #include "php_variables.h"
 #include "rfc1867.h"
 
+#undef DEBUG_FILE_UPLOAD
+
 #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
 #include "ext/mbstring/mbstring.h"
-#endif
 
-#undef DEBUG_FILE_UPLOAD
+static void safe_php_register_variable(char *var, char *strval, zval *track_vars_array, zend_bool override_protection TSRMLS_DC);
 
 #define SAFE_RETURN { \
+    php_mb_flush_gpc_variables(num_vars, val_list, len_list, array_ptr TSRMLS_CC); \
        if (lbuf) efree(lbuf); \
        if (abuf) efree(abuf); \
        if (array_index) efree(array_index); \
        if (mbuff) efree(mbuff); \
        return; }
 
+void php_mb_flush_gpc_variables(int num_vars, char **val_list, int *len_list, zval *array_ptr  TSRMLS_DC)
+{
+       int i;
+       if (php_mb_encoding_translation(TSRMLS_C)) {
+               if (num_vars > 0 &&
+                       php_mb_gpc_encoding_detector(val_list, len_list, num_vars, NULL TSRMLS_CC) == SUCCESS) {
+                       php_mb_gpc_encoding_converter(val_list, len_list, num_vars, NULL, NULL TSRMLS_CC);
+               }
+               for (i=0; i<num_vars; i+=2){
+                       safe_php_register_variable(val_list[i], val_list[i+1], array_ptr, 0 TSRMLS_CC);
+                       efree(val_list[i]);
+                       efree(val_list[i+1]);
+               } 
+               efree(val_list);
+               efree(len_list);
+       }
+}
+
+void php_mb_gpc_stack_variable(char *param, char *value, char ***pval_list, int **plen_list, int *num_vars, int *num_vars_max TSRMLS_DC)
+{
+       char **val_list=*pval_list;
+       int *len_list=*plen_list;
+
+       if (*num_vars>=*num_vars_max){
+               (*num_vars_max) += 16;
+               *pval_list = (char **)erealloc(val_list, *num_vars_max*sizeof(char *));
+               *plen_list = (int *)erealloc(len_list, *num_vars_max*sizeof(int));
+               val_list=*pval_list;
+               len_list=*plen_list;
+       }
+       val_list[*num_vars] = (char *)estrdup(param);
+       len_list[*num_vars] = strlen(param);
+       (*num_vars)++;
+       val_list[*num_vars] = (char *)estrdup(value);
+       len_list[*num_vars] = strlen(value);
+       (*num_vars)++;
+}
+
+#else
+
+#define SAFE_RETURN { \
+       if (lbuf) efree(lbuf); \
+       if (abuf) efree(abuf); \
+       if (array_index) efree(array_index); \
+       zend_hash_destroy(&PG(rfc1867_protected_variables)); \
+       zend_llist_destroy(&header); \
+       if (mbuff->boundary_next) efree(mbuff->boundary_next); \
+       if (mbuff->boundary) efree(mbuff->boundary); \
+       if (mbuff->buffer) efree(mbuff->buffer); \
+       if (mbuff) efree(mbuff); \
+       return; }
+#endif
 
 /* The longest property name we use in an uploaded file array */
 #define MAX_SIZE_OF_INDEX sizeof("[tmp_name]")
@@ -550,7 +604,8 @@ static char *php_ap_getword_conf(char **line TSRMLS_DC)
 
 #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
        if (php_mb_encoding_translation(TSRMLS_C)) {
-               php_mb_gpc_encoding_detector(str, strlen(str), NULL TSRMLS_CC);
+               int len=strlen(str);
+               php_mb_gpc_encoding_detector(&str, &len, 1, NULL TSRMLS_CC);
        }
 #endif
 
@@ -700,7 +755,8 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
        int max_file_size=0, skip_upload=0, anonindex=0, is_anonymous;
        zval *http_post_files=NULL;
 #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
-       int str_len = 0;
+       int str_len = 0, num_vars = 0, num_vars_max = 2*10+1, *len_list = NULL;
+       char **val_list = NULL;
 #endif
        zend_bool magic_quotes_gpc;
        multipart_buffer *mbuff;
@@ -756,6 +812,12 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
        INIT_PZVAL(http_post_files);
        PG(http_globals)[TRACK_VARS_FILES] = http_post_files;
 
+#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
+       if (php_mb_encoding_translation(TSRMLS_C)) {
+               val_list = (char **)ecalloc(num_vars_max, sizeof(char *));
+               len_list = (int *)ecalloc(num_vars_max, sizeof(int));
+       }
+#endif
        zend_llist_init(&header, sizeof(mime_header_entry), (llist_dtor_func_t) php_free_hdr_entry, 0);
 
        while (!multipart_buffer_eof(mbuff TSRMLS_CC))
@@ -818,13 +880,14 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
                                sapi_module.input_filter(PARSE_POST, param, &value, strlen(value) TSRMLS_CC);
 #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
                                if (php_mb_encoding_translation(TSRMLS_C)) {
-                                       if (php_mb_gpc_encoding_detector(value, strlen(value), NULL TSRMLS_CC) == SUCCESS) {
-                                               str_len = strlen(value);
-                                               php_mb_gpc_encoding_converter(&value , &str_len, NULL, NULL TSRMLS_CC);
-                                       } 
+                                       php_mb_gpc_stack_variable(param, value, &val_list, &len_list, 
+                                                                                         &num_vars, &num_vars_max TSRMLS_CC);
+                               } else {
+                                       safe_php_register_variable(param, value, array_ptr, 0 TSRMLS_CC);
                                }
-#endif
+#else
                                safe_php_register_variable(param, value, array_ptr, 0 TSRMLS_CC);
+#endif
                                if (!strcasecmp(param, "MAX_FILE_SIZE")) {
                                        max_file_size = atol(value);
                                }
@@ -949,11 +1012,15 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
 
 #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
                        if (php_mb_encoding_translation(TSRMLS_C)) {
-                               if(php_mb_gpc_encoding_detector(filename, strlen(filename), NULL TSRMLS_CC) == SUCCESS) {
+                               val_list[num_vars] = filename;
+                               len_list[num_vars] = strlen(filename);
+                               num_vars++;
+                               if(php_mb_gpc_encoding_detector(val_list, len_list, num_vars, NULL TSRMLS_CC) == SUCCESS) {
                                        str_len = strlen(filename);
-                                       php_mb_gpc_encoding_converter(&filename, &str_len, NULL, NULL TSRMLS_CC);
+                                       php_mb_gpc_encoding_converter(&filename, &str_len, 1, NULL, NULL TSRMLS_CC);
                                }
                                s = php_mb_strrchr(filename, '\\' TSRMLS_CC);
+                               num_vars--;
                        } else {
                                s = strrchr(filename, '\\');
                        }