summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/pcre/php_pcre.c16
-rw-r--r--ext/phar/func_interceptors.c8
-rw-r--r--ext/standard/php_string.h2
-rw-r--r--ext/standard/streamsfuncs.c6
-rw-r--r--ext/standard/string.c38
5 files changed, 25 insertions, 45 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 7a74082b46..d3bdf87bca 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -881,14 +881,13 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
zval retval; /* Return value from evaluation */
char *eval_str_end, /* End of eval string */
*match, /* Current match for a backref */
- *esc_match, /* Quote-escaped match */
*walk, /* Used to walk the code string */
*segment, /* Start of segment to append while walking */
walk_last; /* Last walked character */
int match_len; /* Length of the match */
- int esc_match_len; /* Length of the quote-escaped match */
int result_len; /* Length of the result of the evaluation */
int backref; /* Current backref */
+ zend_string *esc_match; /* Quote-escaped match */
char *compiled_string_description;
smart_str code = {0};
@@ -914,22 +913,19 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
match = subject + offsets[backref<<1];
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
if (match_len) {
- esc_match = php_addslashes(match, match_len, &esc_match_len, 0 TSRMLS_CC);
+ esc_match = php_addslashes(match, match_len, 0 TSRMLS_CC);
} else {
- esc_match = match;
- esc_match_len = 0;
+ esc_match = STR_INIT(match, match_len, 0);
}
} else {
- esc_match = "";
- esc_match_len = 0;
+ esc_match = STR_EMPTY_ALLOC();
}
- smart_str_appendl(&code, esc_match, esc_match_len);
+ smart_str_appendl(&code, esc_match->val, esc_match->len);
segment = walk;
/* Clean up and reassign */
- if (esc_match_len)
- efree(esc_match);
+ STR_RELEASE(esc_match);
continue;
}
}
diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c
index c0b03e5838..5080ddf7c8 100644
--- a/ext/phar/func_interceptors.c
+++ b/ext/phar/func_interceptors.c
@@ -203,14 +203,8 @@ phar_it:
/* uses mmap if possible */
if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) {
-#if PHP_API_VERSION < 20100412
- if (PG(magic_quotes_runtime)) {
- int newlen;
- contents = php_addslashes(contents, len, &newlen, 1 TSRMLS_CC); /* 1 = free source string */
- len = newlen;
- }
-#endif
RETVAL_STRINGL(contents, len, 0);
+ efree(contents);
} else if (len == 0) {
RETVAL_EMPTY_STRING();
} else {
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h
index 2076eff272..0f4240ea57 100644
--- a/ext/standard/php_string.h
+++ b/ext/standard/php_string.h
@@ -121,7 +121,7 @@ PHPAPI struct lconv *localeconv_r(struct lconv *out);
PHPAPI char *php_strtoupper(char *s, size_t len);
PHPAPI char *php_strtolower(char *s, size_t len);
PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int trlen);
-PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC);
+PHPAPI zend_string *php_addslashes(char *str, int length, int should_free TSRMLS_DC);
PHPAPI zend_string *php_addcslashes(const char *str, int length, int freeit, char *what, int wlength TSRMLS_DC);
PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC);
PHPAPI void php_stripcslashes(char *str, int *len);
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index 68567ea0d5..b5608f450d 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -136,10 +136,10 @@ PHP_FUNCTION(stream_socket_client)
if (stream == NULL) {
/* host might contain binary characters */
- char *quoted_host = php_addslashes(host, host_len, NULL, 0 TSRMLS_CC);
+ zend_string *quoted_host = php_addslashes(host, host_len, 0 TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", quoted_host, errstr == NULL ? "Unknown error" : errstr);
- efree(quoted_host);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", quoted_host->val, errstr == NULL ? "Unknown error" : errstr);
+ STR_RELEASE(quoted_host);
}
if (hashkey) {
diff --git a/ext/standard/string.c b/ext/standard/string.c
index f16e389218..90391ab14e 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -922,12 +922,12 @@ PHP_FUNCTION(wordwrap)
/* Multiple character line break or forced cut */
if (linelength > 0) {
chk = (int)(textlen/linelength + 1);
- newtext = STR_ALLOC(chk * breakcharlen + textlen + 1, 0);
+ newtext = STR_ALLOC(chk * breakcharlen + textlen, 0);
alloced = textlen + chk * breakcharlen + 1;
} else {
chk = textlen;
alloced = textlen * (breakcharlen + 1) + 1;
- newtext = STR_ALLOC(textlen * (breakcharlen + 1) + 1, 0);
+ newtext = STR_ALLOC(textlen * (breakcharlen + 1), 0);
}
/* now keep track of the actual new text length */
@@ -3305,8 +3305,8 @@ PHP_FUNCTION(addcslashes)
Escapes single quote, double quotes and backslash characters in a string with backslashes */
PHP_FUNCTION(addslashes)
{
- char *str, *new_str;
- int str_len, new_len;
+ char *str;
+ int str_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
return;
@@ -3316,13 +3316,7 @@ PHP_FUNCTION(addslashes)
RETURN_EMPTY_STRING();
}
-//??? RETURN_STRING(php_addslashes(str,
-//??? str_len,
-//??? &Z_STRLEN_P(return_value), 0
-//??? TSRMLS_CC), 0);
- new_str = php_addslashes(str, str_len, &new_len, 0 TSRMLS_CC);
- RETVAL_STRINGL(new_str, new_len);
- efree(new_str);
+ RETURN_STR(php_addslashes(str, str_len, 0 TSRMLS_CC));
}
/* }}} */
@@ -3449,7 +3443,7 @@ PHPAPI zend_string *php_addcslashes(const char *str, int length, int should_free
char *end;
char c;
int newlen;
- zend_string *new_str = STR_ALLOC(4 * (length? length : (length = strlen(str))) + 1, 0);
+ zend_string *new_str = STR_ALLOC(4 * (length? length : (length = strlen(str))), 0);
if (!wlength) {
wlength = strlen(what);
@@ -3492,25 +3486,21 @@ PHPAPI zend_string *php_addcslashes(const char *str, int length, int should_free
/* {{{ php_addslashes
*/
-PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC)
+PHPAPI zend_string *php_addslashes(char *str, int length, int should_free TSRMLS_DC)
{
/* maximum string length, worst case situation */
- char *new_str;
char *source, *target;
char *end;
- int local_new_length;
+ zend_string *new_str;
- if (!new_length) {
- new_length = &local_new_length;
- }
if (!str) {
- *new_length = 0;
- return str;
+ return STR_EMPTY_ALLOC();
}
- new_str = (char *) safe_emalloc(2, (length ? length : (length = strlen(str))), 1);
+
+ new_str = STR_ALLOC(2 * (length ? length : (length = strlen(str))), 0);
source = str;
end = source + length;
- target = new_str;
+ target = new_str->val;
while (source < end) {
switch (*source) {
@@ -3532,11 +3522,11 @@ PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_f
}
*target = 0;
- *new_length = target - new_str;
if (should_free) {
//??? STR_FREE(str);
}
- new_str = (char *) erealloc(new_str, *new_length + 1);
+ new_str = STR_REALLOC(new_str, target - new_str->val, 0);
+
return new_str;
}
/* }}} */