Skip to content

Commit 87803ac

Browse files
committed
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Fix handling of several uinitialized intl objects
2 parents fbacf9c + a5d0c1e commit 87803ac

17 files changed

+163
-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_G(default_locale);

ext/intl/dateformat/dateformat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
108108
goto error;
109109
}
110110

111-
DATE_FORMAT_METHOD_FETCH_OBJECT;
111+
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
112112

113113
if (DATE_FORMAT_OBJECT(dfo) != NULL) {
114114
intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR,

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
@@ -23,6 +23,8 @@
2323
#include "dateformat.h"
2424
#include "dateformat_attr.h"
2525

26+
#include <zend_exceptions.h>
27+
2628
zend_class_entry *IntlDateFormatter_ce_ptr = NULL;
2729
static zend_object_handlers IntlDateFormatter_handlers;
2830

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

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

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) {

0 commit comments

Comments
 (0)