Skip to content

Commit fcd4420

Browse files
committed
Merge branch 'PHP-5.4'
* PHP-5.4: Fix handling of several uinitialized intl objects Fix handling of several uinitialized intl objects - Fix NEWS - BFN Conflicts: ext/intl/dateformat/dateformat.c
2 parents 815874c + cd1f45b commit fcd4420

18 files changed

+172
-40
lines changed

ext/intl/collator/collator_class.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
#include <php.h>
2222

23-
#include "intl_common.h"
24-
#include "intl_error.h"
23+
#include "../intl_common.h"
24+
#include "../intl_error.h"
25+
#include "../intl_data.h"
2526

2627
#include <unicode/ucol.h>
2728

@@ -54,9 +55,7 @@ extern zend_class_entry *Collator_ce_ptr;
5455
Collator_object* co = NULL; \
5556
intl_error_reset( NULL TSRMLS_CC ); \
5657

57-
#define COLLATOR_METHOD_FETCH_OBJECT \
58-
co = (Collator_object *) zend_object_store_get_object( object TSRMLS_CC ); \
59-
intl_error_reset( COLLATOR_ERROR_P( co ) TSRMLS_CC ); \
58+
#define COLLATOR_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(Collator, co)
6059

6160
// Macro to check return value of a ucol_* function call.
6261
#define COLLATOR_CHECK_STATUS( co, msg ) \

ext/intl/collator/collator_create.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
4545
}
4646

4747
INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
48-
co = (Collator_object *) zend_object_store_get_object( object TSRMLS_CC );
48+
COLLATOR_METHOD_FETCH_OBJECT;
4949

5050
if(locale_len == 0) {
5151
locale = intl_locale_get_default(TSRMLS_C);

ext/intl/dateformat/dateformat_attr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#include "config.h"
1818
#endif
1919

20-
#include "php_intl.h"
21-
#include "intl_convert.h"
20+
#include "../php_intl.h"
21+
#include "dateformat_class.h"
22+
#include "../intl_convert.h"
2223
#include "dateformat_class.h"
2324
#include "dateformat_attr.h"
2425

ext/intl/dateformat/dateformat_class.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "dateformat_attr.h"
2626
#include "dateformat_attrcpp.h"
2727

28+
#include <zend_exceptions.h>
29+
2830
zend_class_entry *IntlDateFormatter_ce_ptr = NULL;
2931
static zend_object_handlers IntlDateFormatter_handlers;
3032

@@ -90,18 +92,23 @@ zend_object_value IntlDateFormatter_object_clone(zval *object TSRMLS_DC)
9092
zend_object_handle handle = Z_OBJ_HANDLE_P(object);
9193
IntlDateFormatter_object *dfo, *new_dfo;
9294

93-
DATE_FORMAT_METHOD_FETCH_OBJECT;
95+
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
96+
9497
new_obj_val = IntlDateFormatter_ce_ptr->create_object(IntlDateFormatter_ce_ptr TSRMLS_CC);
9598
new_dfo = (IntlDateFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
9699
/* clone standard parts */
97100
zend_objects_clone_members(&new_dfo->zo, new_obj_val, &dfo->zo, handle TSRMLS_CC);
98101
/* clone formatter object */
99-
DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo), &INTL_DATA_ERROR_CODE(new_dfo));
100-
if(U_FAILURE(INTL_DATA_ERROR_CODE(new_dfo))) {
101-
/* set up error in case error handler is interested */
102-
intl_error_set( NULL, INTL_DATA_ERROR_CODE(new_dfo), "Failed to clone IntlDateFormatter object", 0 TSRMLS_CC );
103-
IntlDateFormatter_object_dtor(new_dfo, new_obj_val.handle TSRMLS_CC); /* free new object */
104-
zend_error(E_ERROR, "Failed to clone IntlDateFormatter object");
102+
if (dfo->datef_data.udatf != NULL) {
103+
DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo), &INTL_DATA_ERROR_CODE(dfo));
104+
if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
105+
/* set up error in case error handler is interested */
106+
intl_errors_set(INTL_DATA_ERROR_P(dfo), INTL_DATA_ERROR_CODE(dfo),
107+
"Failed to clone IntlDateFormatter object", 0 TSRMLS_CC );
108+
zend_throw_exception(NULL, "Failed to clone IntlDateFormatter object", 0 TSRMLS_CC);
109+
}
110+
} else {
111+
zend_throw_exception(NULL, "Cannot clone unconstructed IntlDateFormatter", 0 TSRMLS_CC);
105112
}
106113
return new_obj_val;
107114
}

ext/intl/dateformat/dateformat_class.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ extern zend_class_entry *IntlDateFormatter_ce_ptr;
3838
/* Auxiliary macros */
3939

4040
#define DATE_FORMAT_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlDateFormatter, dfo)
41-
#define DATE_FORMAT_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(IntlDateFormatter, dfo)
41+
#define DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(IntlDateFormatter, dfo)
42+
#define DATE_FORMAT_METHOD_FETCH_OBJECT \
43+
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \
44+
if (dfo->datef_data.udatf == NULL) \
45+
{ \
46+
intl_errors_set(&dfo->datef_data.error, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlDateFormatter", 0 TSRMLS_CC); \
47+
RETURN_FALSE; \
48+
}
49+
4250
#define DATE_FORMAT_OBJECT(dfo) (dfo)->datef_data.udatf
4351

4452
#endif // #ifndef DATE_FORMAT_CLASS_H

ext/intl/formatter/formatter_class.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "formatter_main.h"
2525
#include "formatter_attr.h"
2626

27+
#include <zend_exceptions.h>
28+
2729
zend_class_entry *NumberFormatter_ce_ptr = NULL;
2830
static zend_object_handlers NumberFormatter_handlers;
2931

@@ -83,18 +85,23 @@ zend_object_value NumberFormatter_object_clone(zval *object TSRMLS_DC)
8385
zend_object_handle handle = Z_OBJ_HANDLE_P(object);
8486
NumberFormatter_object *nfo, *new_nfo;
8587

86-
FORMATTER_METHOD_FETCH_OBJECT;
88+
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
8789
new_obj_val = NumberFormatter_ce_ptr->create_object(NumberFormatter_ce_ptr TSRMLS_CC);
8890
new_nfo = (NumberFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
8991
/* clone standard parts */
9092
zend_objects_clone_members(&new_nfo->zo, new_obj_val, &nfo->zo, handle TSRMLS_CC);
91-
/* clone formatter object */
92-
FORMATTER_OBJECT(new_nfo) = unum_clone(FORMATTER_OBJECT(nfo), &INTL_DATA_ERROR_CODE(new_nfo));
93-
if(U_FAILURE(INTL_DATA_ERROR_CODE(new_nfo))) {
94-
/* set up error in case error handler is interested */
95-
intl_error_set( NULL, INTL_DATA_ERROR_CODE(new_nfo), "Failed to clone NumberFormatter object", 0 TSRMLS_CC );
96-
NumberFormatter_object_dtor(new_nfo, new_obj_val.handle TSRMLS_CC); /* free new object */
97-
zend_error(E_ERROR, "Failed to clone NumberFormatter object");
93+
/* clone formatter object. It may fail, the destruction code must handle this case */
94+
if (FORMATTER_OBJECT(nfo) != NULL) {
95+
FORMATTER_OBJECT(new_nfo) = unum_clone(FORMATTER_OBJECT(nfo),
96+
&INTL_DATA_ERROR_CODE(nfo));
97+
if (U_FAILURE(INTL_DATA_ERROR_CODE(nfo))) {
98+
/* set up error in case error handler is interested */
99+
intl_errors_set(INTL_DATA_ERROR_P(nfo), INTL_DATA_ERROR_CODE(nfo),
100+
"Failed to clone NumberFormatter object", 0 TSRMLS_CC);
101+
zend_throw_exception(NULL, "Failed to clone NumberFormatter object", 0 TSRMLS_CC);
102+
}
103+
} else {
104+
zend_throw_exception(NULL, "Cannot clone unconstructed NumberFormatter", 0 TSRMLS_CC);
98105
}
99106
return new_obj_val;
100107
}

ext/intl/formatter/formatter_class.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ extern zend_class_entry *NumberFormatter_ce_ptr;
3434

3535
/* Auxiliary macros */
3636

37-
#define FORMATTER_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(NumberFormatter, nfo)
38-
#define FORMATTER_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(NumberFormatter, nfo)
39-
#define FORMATTER_OBJECT(nfo) (nfo)->nf_data.unum
37+
#define FORMATTER_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(NumberFormatter, nfo)
38+
#define FORMATTER_OBJECT(nfo) (nfo)->nf_data.unum
39+
#define FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(NumberFormatter, nfo)
40+
#define FORMATTER_METHOD_FETCH_OBJECT \
41+
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; \
42+
if (FORMATTER_OBJECT(nfo) == NULL) \
43+
{ \
44+
intl_errors_set(&nfo->nf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \
45+
"Found unconstructed NumberFormatter", 0 TSRMLS_CC); \
46+
RETURN_FALSE; \
47+
}
48+
4049

4150
#endif // #ifndef FORMATTER_CLASS_H

ext/intl/formatter/formatter_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
4747

4848
INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
4949
object = return_value;
50-
FORMATTER_METHOD_FETCH_OBJECT;
50+
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
5151

5252
/* Convert pattern (if specified) to UTF-16. */
5353
if(pattern && pattern_len) {

ext/intl/msgformat/msgformat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
4949
}
5050

5151
INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
52-
MSG_FORMAT_METHOD_FETCH_OBJECT;
52+
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
5353

5454
/* Convert pattern (if specified) to UTF-16. */
5555
if(pattern && pattern_len) {

ext/intl/msgformat/msgformat_class.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "msgformat.h"
2525
#include "msgformat_attr.h"
2626

27+
#include <zend_exceptions.h>
28+
2729
zend_class_entry *MessageFormatter_ce_ptr = NULL;
2830
static zend_object_handlers MessageFormatter_handlers;
2931

@@ -81,18 +83,24 @@ zend_object_value MessageFormatter_object_clone(zval *object TSRMLS_DC)
8183
zend_object_handle handle = Z_OBJ_HANDLE_P(object);
8284
MessageFormatter_object *mfo, *new_mfo;
8385

84-
MSG_FORMAT_METHOD_FETCH_OBJECT;
86+
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
8587
new_obj_val = MessageFormatter_ce_ptr->create_object(MessageFormatter_ce_ptr TSRMLS_CC);
8688
new_mfo = (MessageFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
8789
/* clone standard parts */
8890
zend_objects_clone_members(&new_mfo->zo, new_obj_val, &mfo->zo, handle TSRMLS_CC);
91+
8992
/* clone formatter object */
90-
MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo), &INTL_DATA_ERROR_CODE(new_mfo));
91-
if(U_FAILURE(INTL_DATA_ERROR_CODE(new_mfo))) {
92-
/* set up error in case error handler is interested */
93-
intl_error_set( NULL, INTL_DATA_ERROR_CODE(new_mfo), "Failed to clone MessageFormatter object", 0 TSRMLS_CC );
94-
MessageFormatter_object_dtor(new_mfo, new_obj_val.handle TSRMLS_CC); /* free new object */
95-
zend_error(E_ERROR, "Failed to clone MessageFormatter object");
93+
if (MSG_FORMAT_OBJECT(mfo) != NULL) {
94+
MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo),
95+
&INTL_DATA_ERROR_CODE(mfo));
96+
97+
if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
98+
intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo),
99+
"Failed to clone MessageFormatter object", 0 TSRMLS_CC);
100+
zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object");
101+
}
102+
} else {
103+
zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter");
96104
}
97105
return new_obj_val;
98106
}

0 commit comments

Comments
 (0)