Skip to content

Commit

Permalink
Removed HAVE_MB_STRING code (PHP 5.4-incompatible)
Browse files Browse the repository at this point in the history
  • Loading branch information
jani committed Jan 22, 2013
1 parent 1fba865 commit e8beb4f
Showing 1 changed file with 1 addition and 135 deletions.
136 changes: 1 addition & 135 deletions rfc1867.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/

/* $Id: rfc1867.c,v 1.1.1.1 2007-11-28 01:15:35 sesser Exp $ */
/* $Id: rfc1867.c,v 1.1.1.3 2013-01-22 15:55:55 jani Exp $ */

/*
* This product includes software developed by the Apache Group
Expand All @@ -38,76 +38,6 @@

#define DEBUG_FILE_UPLOAD ZEND_DEBUG

#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
#include "ext/mbstring/mbstring.h"

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); \
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; }

static 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);
}
}

static void php_mb_gpc_realloc_buffer(char ***pval_list, int **plen_list, int *num_vars_max, int inc TSRMLS_DC)
{
/* allow only even increments */
if (inc & 1) {
inc++;
}
(*num_vars_max) += inc;
*pval_list = (char **)erealloc(*pval_list, (*num_vars_max+2)*sizeof(char *));
*plen_list = (int *)erealloc(*plen_list, (*num_vars_max+2)*sizeof(int));
}

static 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){
php_mb_gpc_realloc_buffer(pval_list, plen_list, num_vars_max,
16 TSRMLS_CC);
/* in case realloc relocated the buffer */
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); \
Expand All @@ -119,7 +49,6 @@ static void php_mb_gpc_stack_variable(char *param, char *value, char ***pval_lis
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]")
Expand Down Expand Up @@ -592,19 +521,7 @@ static char *substring_conf(char *start, int len, char quote TSRMLS_DC)
if (start[i] == '\\' && (start[i + 1] == '\\' || (quote && start[i + 1] == quote))) {
*resp++ = start[++i];
} else {
#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
if (php_mb_encoding_translation(TSRMLS_C)) {
size_t j = php_mb_gpc_mbchar_bytes(start+i TSRMLS_CC);
while (j-- > 0 && i < len) {
*resp++ = start[i++];
}
--i;
} else {
*resp++ = start[i];
}
#else
*resp++ = start[i];
#endif
}
}

Expand All @@ -617,13 +534,6 @@ static char *php_ap_getword_conf(char **line TSRMLS_DC)
{
char *str = *line, *strend, *res, quote;

#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
if (php_mb_encoding_translation(TSRMLS_C)) {
int len=strlen(str);
php_mb_gpc_encoding_detector(&str, &len, 1, NULL TSRMLS_CC);
}
#endif

while (*str && isspace(*str)) {
++str;
}
Expand Down Expand Up @@ -782,10 +692,6 @@ SAPI_POST_HANDLER_FUNC(suhosin_rfc1867_post_handler)
int boundary_len=0, total_bytes=0, cancel_upload=0, is_arr_upload=0, array_len=0;
int max_file_size=0, skip_upload=0, anonindex=0, is_anonymous;
zval *http_post_files=NULL; HashTable *uploaded_files=NULL;
#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
int str_len = 0, num_vars = 0, num_vars_max = 2*10, *len_list = NULL;
char **val_list = NULL;
#endif
multipart_buffer *mbuff;
zval *array_ptr = (zval *) arg;
int fd=-1;
Expand Down Expand Up @@ -858,12 +764,6 @@ SAPI_POST_HANDLER_FUNC(suhosin_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+2, sizeof(char *));
len_list = (int *)ecalloc(num_vars_max+2, sizeof(int));
}
#endif
zend_llist_init(&header, sizeof(mime_header_entry), (llist_dtor_func_t) php_free_hdr_entry, 0);


Expand Down Expand Up @@ -963,16 +863,7 @@ SDEBUG("calling inputfilter");
new_val_len = newlength;
}

#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
if (php_mb_encoding_translation(TSRMLS_C)) {
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);
}
#else
safe_php_register_variable(param, value, array_ptr, 0 TSRMLS_CC);
#endif
#ifdef ZEND_ENGINE_2
} else {
multipart_event_formdata event_formdata;
Expand Down Expand Up @@ -1201,27 +1092,6 @@ SDEBUG("calling inputfilter");
sprintf(lbuf, "%s_name", param);
}

#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
if (php_mb_encoding_translation(TSRMLS_C)) {
if (num_vars>=num_vars_max){
php_mb_gpc_realloc_buffer(&val_list, &len_list, &num_vars_max,
1 TSRMLS_CC);
}
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, 1, NULL, NULL TSRMLS_CC);
}
s = php_mb_strrchr(filename, '\\' TSRMLS_CC);
if ((tmp = php_mb_strrchr(filename, '/' TSRMLS_CC)) > s) {
s = tmp;
}
num_vars--;
goto filedone;
}
#endif
/* The \ check should technically be needed for win32 systems only where
* it is a valid path separator. However, IE in all it's wisdom always sends
* the full path of the file on the user's filesystem, which means that unless
Expand All @@ -1242,10 +1112,6 @@ SDEBUG("calling inputfilter");
}
#endif

#if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
filedone:
#endif

if (!is_anonymous) {
if (s && s > filename) {
safe_php_register_variable(lbuf, s+1, NULL, 0 TSRMLS_CC);
Expand Down

0 comments on commit e8beb4f

Please sign in to comment.