Commit:ed6ce831013d8c6f6f585e814ee9b542da283749
Author:Stanislav Malyshev Wed, 30 May 2012 22:26:26
-0700
Parents: 303dd7f3469106f8cd91a8648de1c4fed51374b3
Branches: PHP-5.4
Link:
http://git.php.net/?p=php-src.git;a=commitdiff;h=ed6ce831013d8c6f6f585e814ee9b542da283749
Log:
fix bug #55042 - erealloc without updating pointer
Bugs:
https://bugs.php.net/55042
Changed paths:
M ext/iconv/iconv.c
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 92675eb..9cae535 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -190,7 +190,7 @@ typedef enum _php_iconv_enc_scheme_t {
#define PHP_ICONV_MIME_DECODE_STRICT(1<<0)
#define PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR (1<<1)
-/* {{{ prototypes */
+/* {{{ prototypes */
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t
l, iconv_t cd);
static php_iconv_err_t _php_iconv_appendc(smart_str *d, const char c, iconv_t
cd);
@@ -249,7 +249,7 @@ PHP_MINIT_FUNCTION(miconv)
{
static char buf[16];
snprintf(buf, sizeof(buf), "%d.%d",
- ((_libiconv_version >> 8) & 0x0f), (_libiconv_version &
0x0f));
+ ((_libiconv_version >> 8) & 0x0f), (_libiconv_version &
0x0f));
version = buf;
}
#elif HAVE_GLIBC_ICONV
@@ -354,7 +354,7 @@ static int php_iconv_output_handler(void **nothing,
php_output_context *output_c
if (mimetype != NULL && !(output_context->op &
PHP_OUTPUT_HANDLER_CLEAN)) {
int len;
- char *p = strstr(ICONVG(output_encoding), "//");
+ char *p = strstr(ICONVG(output_encoding), "//");
if (p) {
len = spprintf(&content_type, 0,
"Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int)
strlen(mimetype), mimetype, (int)(p - ICONVG(output_encoding)),
ICONVG(output_encoding));
@@ -375,7 +375,7 @@ static int php_iconv_output_handler(void **nothing,
php_output_context *output_c
return SUCCESS;
}
-
+
/* {{{ _php_iconv_appendl() */
static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t
l, iconv_t cd)
{
@@ -400,7 +400,7 @@ static php_iconv_err_t _php_iconv_appendl(smart_str *d,
const char *s, size_t l,
if (iconv(cd, (char **)&in_p, &in_left, (char **)
&out_p, &out_left) == (size_t)-1) {
#if ICONV_SUPPORTS_ERRNO
- switch (errno) {
+ switch (errno) {
case EINVAL:
return
PHP_ICONV_ERR_ILLEGAL_CHAR;
@@ -415,7 +415,7 @@ static php_iconv_err_t _php_iconv_appendl(smart_str *d,
const char *s, size_t l,
}
#else
if (prev_in_left == in_left) {
- return PHP_ICONV_ERR_UNKNOWN;
+ return PHP_ICONV_ERR_UNKNOWN;
}
#endif
}
@@ -446,7 +446,7 @@ static php_iconv_err_t _php_iconv_appendl(smart_str *d,
const char *s, size_t l,
#else
if (out_left != 0) {
return PHP_ICONV_ERR_UNKNOWN;
- }
+ }
#endif
}
(d)->len += (buf_growth - out_left);
@@ -492,31 +492,35 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char
*in_p, size_t in_len,
in_size = in_len;
cd = iconv_open(out_charset, in_charset);
-
+
if (cd == (iconv_t)(-1)) {
return PHP_ICONV_ERR_UNKNOWN;
}
out_buffer = (char *) emalloc(out_size + 1);
out_p = out_buffer;
-
+
#ifdef NETWARE
result = iconv(cd, (char **) &in_p, &in_size, (char **)
#else
result = iconv(cd, (const char **) &in_p, &in_size, (char **)
#endif
&out_p, &out_left);
-
+
if (result == (size_t)(-1)) {
efree(out_buffer);
return PHP_ICONV_ERR_UNKNOWN;
}
if (out_left < 8) {
- out_buffer = (char *) erealloc(out_buffer, out_size + 8);
+ size_t pos = out_p - out_buffer;
+ out_buffer = (char *) safe_erealloc(out_buffer, out_size, 1, 8);
+ out_p = out_buffer+pos;
+ out_size += 7;
+ out_left += 7;
}
- /* flush the shift-out sequences */
+ /* flush the shift-out sequences */
result = iconv(cd, NULL, NULL, &out_p, &out_left);
if (result == (size_t)(-1)) {
@@ -555,10 +559,10 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char
*in_p, size_t in_len,
}
}
in_left= in_len;
- out_