Skip to content

Commit 7ed6553

Browse files
author
Rui Hirokawa
committed
fixed bugs: memory related, strtok separator, lack of mail() parameter.
1 parent 0d5555e commit 7ed6553

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

ext/mbstring/mbfilter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6854,6 +6854,9 @@ mbfl_strimwidth(
68546854
}
68556855
mbfl_convert_filter_flush(encoder);
68566856
}
6857+
} else if (pc.status != 0) {
6858+
pc.device.pos = pc.endpos;
6859+
mbfl_convert_filter_copy(pc.decoder_backup, pc.decoder);
68576860
}
68586861
mbfl_convert_filter_flush(pc.decoder);
68596862
}

ext/mbstring/mbstring.c

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ PHP_FUNCTION(mb_parse_str)
11641164
len_list[n] = 0;
11651165
}
11661166
n++;
1167-
var = php_strtok_r(NULL, "&", &strtok_buf);
1167+
var = php_strtok_r(NULL, separator, &strtok_buf);
11681168
}
11691169
num = n;
11701170

@@ -1267,6 +1267,8 @@ PHP_FUNCTION(mb_output_handler)
12671267
{
12681268
pval **arg_string, **arg_status;
12691269
mbfl_string string, result, *ret;
1270+
const char *mimetype, *charset;
1271+
mbfl_memory_device device;
12701272
SLS_FETCH();
12711273
MBSTRLS_FETCH();
12721274

@@ -1277,13 +1279,35 @@ PHP_FUNCTION(mb_output_handler)
12771279
convert_to_string_ex(arg_string);
12781280
convert_to_long_ex(arg_status);
12791281

1282+
if ( SG(sapi_headers).send_default_content_type && ! SG(headers_sent) &&
1283+
MBSTRG(current_http_output_encoding) != mbfl_no_encoding_pass &&
1284+
(Z_LVAL_PP(arg_status) & PHP_OUTPUT_HANDLER_START) != 0) {
1285+
mimetype = SG(default_mimetype) ? SG(default_mimetype) : SAPI_DEFAULT_MIMETYPE;
1286+
charset = mbfl_no2preferred_mime_name(MBSTRG(current_http_output_encoding));
1287+
if ( charset != NULL && (*mimetype == '\0' || strncasecmp(mimetype, "text/", 5) == 0) ) {
1288+
mbfl_memory_device_init(&device, 0, 0);
1289+
mbfl_memory_device_strcat(&device, "Content-Type: ");
1290+
if (*mimetype == '\0') {
1291+
mbfl_memory_device_strcat(&device, "text/html");
1292+
} else {
1293+
mbfl_memory_device_strcat(&device, mimetype);
1294+
}
1295+
mbfl_memory_device_strcat(&device, ";charset=");
1296+
mbfl_memory_device_strcat(&device, charset);
1297+
ret = mbfl_memory_device_result(&device, &result);
1298+
if (ret != NULL) {
1299+
if (sapi_add_header(ret->val, ret->len, 0) != FAILURE) {
1300+
SG(sapi_headers).send_default_content_type = 0;
1301+
}
1302+
}
1303+
}
1304+
}
1305+
12801306
ret = NULL;
1281-
if (SG(sapi_headers).send_default_content_type &&
1282-
MBSTRG(current_http_output_encoding) != mbfl_no_encoding_pass &&
1283-
MBSTRG(outconv) == NULL) {
1307+
if (MBSTRG(current_http_output_encoding) != mbfl_no_encoding_pass && MBSTRG(outconv) == NULL) {
12841308
MBSTRG(outconv) = mbfl_buffer_converter_new(MBSTRG(current_internal_encoding), MBSTRG(current_http_output_encoding), 0);
12851309
}
1286-
if (SG(sapi_headers).send_default_content_type && MBSTRG(outconv) != NULL) {
1310+
if (MBSTRG(current_http_output_encoding) != mbfl_no_encoding_pass && MBSTRG(outconv) != NULL) {
12871311
mbfl_buffer_converter_illegal_mode(MBSTRG(outconv), MBSTRG(current_filter_illegal_mode));
12881312
mbfl_buffer_converter_illegal_substchar(MBSTRG(outconv), MBSTRG(current_filter_illegal_substchar));
12891313
mbfl_string_init(&string);
@@ -2256,7 +2280,7 @@ PHP_FUNCTION(mb_convert_variables)
22562280
if (Z_TYPE_PP(hash_entry) == IS_ARRAY || Z_TYPE_PP(hash_entry) == IS_OBJECT) {
22572281
if (stack_level >= stack_max) {
22582282
stack_max += PHP_MBSTR_STACK_BLOCK_SIZE;
2259-
ptmp = erealloc(stack, stack_max);
2283+
ptmp = erealloc(stack, sizeof(pval **)*stack_max);
22602284
if (ptmp == NULL) {
22612285
php_error(E_WARNING, "stack err at %s:(%d)", __FILE__, __LINE__);
22622286
continue;
@@ -2347,7 +2371,7 @@ PHP_FUNCTION(mb_convert_variables)
23472371
if (Z_TYPE_PP(hash_entry) == IS_ARRAY || Z_TYPE_PP(hash_entry) == IS_OBJECT) {
23482372
if (stack_level >= stack_max) {
23492373
stack_max += PHP_MBSTR_STACK_BLOCK_SIZE;
2350-
ptmp = erealloc(stack, stack_max);
2374+
ptmp = erealloc(stack, sizeof(pval **)*stack_max);
23512375
if (ptmp == NULL) {
23522376
php_error(E_WARNING, "stack err at %s:(%d)", __FILE__, __LINE__);
23532377
continue;
@@ -2497,13 +2521,13 @@ PHP_FUNCTION(mb_decode_numericentity)
24972521

24982522

24992523
#if HAVE_SENDMAIL
2500-
/* {{{ proto int mb_send_mail(string to, string subject, string message [, string additional_headers])
2524+
/* {{{ proto int mb_send_mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
25012525
Sends an email message with MIME scheme */
25022526
PHP_FUNCTION(mb_send_mail)
25032527
{
25042528
int argc, n;
25052529
pval **argv[4];
2506-
char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL;
2530+
char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL, *extra_cmd=NULL;
25072531
char *message_buf=NULL, *subject_buf=NULL, *p;
25082532
mbfl_string orig_str, conv_str;
25092533
mbfl_string *pstr; /* pointer to mbfl string for return value */
@@ -2537,7 +2561,7 @@ PHP_FUNCTION(mb_send_mail)
25372561
}
25382562

25392563
argc = ZEND_NUM_ARGS();
2540-
if (argc < 3 || argc > 4 || zend_get_parameters_array_ex(argc, argv) == FAILURE) {
2564+
if (argc < 3 || argc > 5 || zend_get_parameters_array_ex(argc, argv) == FAILURE) {
25412565
WRONG_PARAM_COUNT;
25422566
}
25432567

@@ -2621,7 +2645,12 @@ PHP_FUNCTION(mb_send_mail)
26212645
mbfl_memory_device_output('\0', &device);
26222646
headers = device.buffer;
26232647

2624-
if (!err && php_mail(to, subject, message, headers, NULL)){
2648+
if (argc == 5) { /* extra options that get passed to the mailer */
2649+
convert_to_string_ex(argv[4]);
2650+
extra_cmd = (*argv[4])->value.str.val;
2651+
}
2652+
2653+
if (!err && php_mail(to, subject, message, headers, extra_cmd)){
26252654
RETVAL_TRUE;
26262655
} else {
26272656
RETVAL_FALSE;

0 commit comments

Comments
 (0)