Skip to content

Commit b78a38a

Browse files
author
Andrei Zmievski
committed
Make all macros (RETURN_*, RETVAL_*, ZVAL_*, add_*) that convert binary
strings to Unicode actually issues errors on failure. I'm surprised we haven't done this already.
1 parent 4d9e16e commit b78a38a

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

Zend/zend_API.h

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -427,28 +427,28 @@ ZEND_API int add_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *value);
427427
} while (0)
428428
#define add_assoc_rt_stringl_ex(arg, key, key_len, str, length, flags) do { \
429429
if (UG(unicode)) { \
430-
UErrorCode ___status = U_ZERO_ERROR; \
431430
UChar *___u_str; \
432431
int ___u_len; \
433-
zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \
432+
if (zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length) == SUCCESS) { \
433+
add_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
434+
} \
434435
if ((flags) & ZSTR_AUTOFREE) { \
435436
efree(str); \
436437
} \
437-
add_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
438438
} else { \
439439
add_assoc_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
440440
} \
441441
} while (0)
442442
#define add_assoc_utf8_stringl_ex(arg, key, key_len, str, length, flags) do { \
443443
if (UG(unicode)) { \
444-
UErrorCode ___status = U_ZERO_ERROR; \
445444
UChar *___u_str; \
446445
int ___u_len; \
447-
zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \
446+
if (zend_string_to_unicode(UG(utf8_conv), &___u_str, &___u_len, str, length) == SUCCESS) { \
447+
add_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
448+
} \
448449
if ((flags) & ZSTR_AUTOFREE) { \
449450
efree(str); \
450451
} \
451-
add_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
452452
} else { \
453453
add_assoc_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
454454
} \
@@ -570,28 +570,28 @@ ZEND_API int add_ascii_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *v
570570
} while (0)
571571
#define add_ascii_assoc_rt_stringl_ex(arg, key, key_len, str, length, flags) do { \
572572
if (UG(unicode)) { \
573-
UErrorCode ___status = U_ZERO_ERROR; \
574573
UChar *___u_str; \
575574
int ___u_len; \
576-
zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \
575+
if (zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length) == SUCCESS) { \
576+
add_ascii_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
577+
} \
577578
if ((flags) & ZSTR_AUTOFREE) { \
578579
efree(str); \
579580
} \
580-
add_ascii_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
581581
} else { \
582582
add_ascii_assoc_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
583583
} \
584584
} while (0)
585585
#define add_ascii_assoc_utf8_stringl_ex(arg, key, key_len, str, length, flags) do { \
586586
if (UG(unicode)) { \
587-
UErrorCode ___status = U_ZERO_ERROR; \
588587
UChar *___u_str; \
589588
int ___u_len; \
590-
zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \
589+
if (zend_string_to_unicode(UG(utf8_conv), &___u_str, &___u_len, str, length) == SUCCESS) { \
590+
add_ascii_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
591+
} \
591592
if ((flags) & ZSTR_AUTOFREE) { \
592593
efree(str); \
593594
} \
594-
add_ascii_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
595595
} else { \
596596
add_ascii_assoc_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
597597
} \
@@ -714,28 +714,28 @@ ZEND_API int add_rt_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *valu
714714
} while (0)
715715
#define add_rt_assoc_rt_stringl_ex(arg, key, key_len, str, length, flags) do { \
716716
if (UG(unicode)) { \
717-
UErrorCode ___status = U_ZERO_ERROR; \
718717
UChar *___u_str; \
719718
int ___u_len; \
720-
zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \
719+
if (zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length) == SUCCESS) { \
720+
add_rt_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
721+
} \
721722
if ((flags) & ZSTR_AUTOFREE) { \
722723
efree(str); \
723724
} \
724-
add_rt_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
725725
} else { \
726726
add_rt_assoc_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
727727
} \
728728
} while (0)
729729
#define add_rt_assoc_utf8_stringl_ex(arg, key, key_len, str, length, flags) do { \
730730
if (UG(unicode)) { \
731-
UErrorCode ___status = U_ZERO_ERROR; \
732731
UChar *___u_str; \
733732
int ___u_len; \
734-
zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \
733+
if (zend_string_to_unicode(UG(utf8_conv), &___u_str, &___u_len, str, length) == SUCCESS) { \
734+
add_rt_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
735+
} \
735736
if ((flags) & ZSTR_AUTOFREE) { \
736737
efree(str); \
737738
} \
738-
add_rt_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
739739
} else { \
740740
add_rt_assoc_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
741741
} \
@@ -858,28 +858,28 @@ ZEND_API int add_utf8_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *va
858858
} while (0)
859859
#define add_utf8_assoc_rt_stringl_ex(arg, key, key_len, str, length, flags) do { \
860860
if (UG(unicode)) { \
861-
UErrorCode ___status = U_ZERO_ERROR; \
862861
UChar *___u_str; \
863862
int ___u_len; \
864-
zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \
863+
if (zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length) == SUCCESS) { \
864+
add_utf8_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
865+
} \
865866
if ((flags) & ZSTR_AUTOFREE) { \
866867
efree(str); \
867868
} \
868-
add_utf8_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
869869
} else { \
870870
add_utf8_assoc_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
871871
} \
872872
} while (0)
873873
#define add_utf8_assoc_utf8_stringl_ex(arg, key, key_len, str, length, flags) do { \
874874
if (UG(unicode)) { \
875-
UErrorCode ___status = U_ZERO_ERROR; \
876875
UChar *___u_str; \
877876
int ___u_len; \
878-
zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \
877+
if (zend_string_to_unicode(UG(utf8_conv), &___u_str, &___u_len, str, length) == SUCCESS) { \
878+
add_utf8_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
879+
} \
879880
if ((flags) & ZSTR_AUTOFREE) { \
880881
efree(str); \
881882
} \
882-
add_utf8_assoc_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
883883
} else { \
884884
add_utf8_assoc_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
885885
} \
@@ -1012,28 +1012,28 @@ ZEND_API int add_utf8_property_zval_ex(zval *arg, char *key, uint key_len, zval
10121012
} while (0)
10131013
#define add_utf8_property_rt_stringl_ex(arg, key, key_len, str, length, flags) do { \
10141014
if (UG(unicode)) { \
1015-
UErrorCode ___status = U_ZERO_ERROR; \
10161015
UChar *___u_str; \
10171016
int ___u_len; \
1018-
zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \
1017+
if (zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length) == SUCCESS) { \
1018+
add_utf8_property_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
1019+
} \
10191020
if ((flags) & ZSTR_AUTOFREE) { \
10201021
efree(str); \
10211022
} \
1022-
add_utf8_property_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
10231023
} else { \
10241024
add_utf8_property_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
10251025
} \
10261026
} while (0)
10271027
#define add_utf8_property_utf8_stringl_ex(arg, key, key_len, str, length, flags) do { \
10281028
if (UG(unicode)) { \
1029-
UErrorCode ___status = U_ZERO_ERROR; \
10301029
UChar *___u_str; \
10311030
int ___u_len; \
1032-
zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \
1031+
if (zend_string_to_unicode(UG(utf8_conv), &___u_str, &___u_len, str, length) == SUCCESS) { \
1032+
add_utf8_property_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
1033+
} \
10331034
if ((flags) & ZSTR_AUTOFREE) { \
10341035
efree(str); \
10351036
} \
1036-
add_utf8_property_unicodel_ex(arg, key, key_len, ___u_str, ___u_len, 0); \
10371037
} else { \
10381038
add_utf8_property_stringl_ex(arg, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
10391039
} \
@@ -1130,28 +1130,28 @@ ZEND_API int add_u_assoc_zval_ex(zval *arg, zend_uchar type, zstr key, uint key_
11301130
} while (0)
11311131
#define add_u_assoc_rt_stringl_ex(arg, type, key, key_len, str, length, flags) do { \
11321132
if (UG(unicode)) { \
1133-
UErrorCode ___status = U_ZERO_ERROR; \
11341133
UChar *___u_str; \
11351134
int ___u_len; \
1136-
zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \
1135+
if (zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length) == SUCCESS) { \
1136+
add_u_assoc_unicodel_ex(arg, type, key, key_len, ___u_str, ___u_len, 0); \
1137+
} \
11371138
if ((flags) & ZSTR_AUTOFREE) { \
11381139
efree(str); \
11391140
} \
1140-
add_u_assoc_unicodel_ex(arg, type, key, key_len, ___u_str, ___u_len, 0); \
11411141
} else { \
11421142
add_u_assoc_stringl_ex(arg, type, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
11431143
} \
11441144
} while (0)
11451145
#define add_u_assoc_utf8_stringl_ex(arg, type, key, key_len, str, length, flags) do { \
11461146
if (UG(unicode)) { \
1147-
UErrorCode ___status = U_ZERO_ERROR; \
11481147
UChar *___u_str; \
11491148
int ___u_len; \
1150-
zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \
1149+
if (zend_string_to_unicode(UG(utf8_conv), &___u_str, &___u_len, str, length) == SUCCESS) { \
1150+
add_u_assoc_unicodel_ex(arg, type, key, key_len, ___u_str, ___u_len, 0); \
1151+
} \
11511152
if ((flags) & ZSTR_AUTOFREE) { \
11521153
efree(str); \
11531154
} \
1154-
add_u_assoc_unicodel_ex(arg, type, key, key_len, ___u_str, ___u_len, 0); \
11551155
} else { \
11561156
add_u_assoc_stringl_ex(arg, type, key, key_len, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
11571157
} \
@@ -1274,28 +1274,28 @@ ZEND_API int add_index_zval(zval *arg, ulong index, zval *value);
12741274
} while (0)
12751275
#define add_index_rt_stringl(arg, idx, str, length, flags) do {\
12761276
if (UG(unicode)) { \
1277-
UErrorCode ___status = U_ZERO_ERROR; \
12781277
UChar *___u_str; \
12791278
int ___u_len; \
1280-
zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \
1279+
if (zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length) == SUCCESS) { \
1280+
add_index_unicodel(arg, idx, ___u_str, ___u_len, 0); \
1281+
} \
12811282
if ((flags) & ZSTR_AUTOFREE) { \
12821283
efree(str); \
12831284
} \
1284-
add_index_unicodel(arg, idx, ___u_str, ___u_len, 0); \
12851285
} else { \
12861286
add_index_stringl(arg, idx, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
12871287
} \
12881288
} while (0)
12891289
#define add_index_utf8_stringl(arg, idx, str, length, flags) do { \
12901290
if (UG(unicode)) { \
1291-
UErrorCode ___status = U_ZERO_ERROR; \
12921291
UChar *___u_str; \
12931292
int ___u_len; \
1294-
zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \
1293+
if (zend_string_to_unicode(UG(utf8_conv), &___u_str, &___u_len, str, length) == SUCCESS) { \
1294+
add_index_unicodel(arg, idx, ___u_str, ___u_len, 0); \
1295+
} \
12951296
if ((flags) & ZSTR_AUTOFREE) { \
12961297
efree(str); \
12971298
} \
1298-
add_index_unicodel(arg, idx, ___u_str, ___u_len, 0); \
12991299
} else { \
13001300
add_index_stringl(arg, idx, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
13011301
} \
@@ -1397,28 +1397,28 @@ ZEND_API int add_next_index_zval(zval *arg, zval *value);
13971397
} while (0)
13981398
#define add_next_index_rt_stringl(arg, str, length, flags) do { \
13991399
if (UG(unicode)) { \
1400-
UErrorCode ___status = U_ZERO_ERROR; \
14011400
UChar *___u_str; \
14021401
int ___u_len; \
1403-
zend_string_to_unicode_ex(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length, &___status); \
1402+
if (zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &___u_str, &___u_len, str, length) == SUCCESS) { \
1403+
add_next_index_unicodel(arg, ___u_str, ___u_len, 0); \
1404+
} \
14041405
if ((flags) & ZSTR_AUTOFREE) { \
14051406
efree(str); \
14061407
} \
1407-
add_next_index_unicodel(arg, ___u_str, ___u_len, 0); \
14081408
} else { \
14091409
add_next_index_stringl(arg, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
14101410
} \
14111411
} while (0)
14121412
#define add_next_index_utf8_stringl(arg, str, length, flags) do { \
14131413
if (UG(unicode)) { \
1414-
UErrorCode ___status = U_ZERO_ERROR; \
14151414
UChar *___u_str; \
14161415
int ___u_len; \
1417-
zend_string_to_unicode_ex(UG(utf8_conv), &___u_str, &___u_len, str, length, &___status); \
1416+
if (zend_string_to_unicode(UG(utf8_conv), &___u_str, &___u_len, str, length) == SUCCESS) { \
1417+
add_next_index_unicodel(arg, ___u_str, ___u_len, 0); \
1418+
} \
14181419
if ((flags) & ZSTR_AUTOFREE) { \
14191420
efree(str); \
14201421
} \
1421-
add_next_index_unicodel(arg, ___u_str, ___u_len, 0); \
14221422
} else { \
14231423
add_next_index_stringl(arg, (char*)(str), length, (flags) & ZSTR_DUPLICATE); \
14241424
} \
@@ -1643,16 +1643,16 @@ END_EXTERN_C()
16431643

16441644
#define ZVAL_U_STRING(conv, z, s, flags) { \
16451645
if (UG(unicode)) { \
1646-
UErrorCode status = U_ZERO_ERROR; \
16471646
char *__s = (s); \
16481647
int __s_len = strlen(__s); \
16491648
UChar *u_str; \
16501649
int u_len; \
1651-
zend_string_to_unicode_ex(conv, &u_str, &u_len, __s, __s_len, &status); \
1650+
if (zend_string_to_unicode(conv, &u_str, &u_len, __s, __s_len) == SUCCESS) { \
1651+
ZVAL_UNICODEL(z, u_str, u_len, 0); \
1652+
} \
16521653
if ((flags) & ZSTR_AUTOFREE) { \
16531654
efree(__s); \
16541655
} \
1655-
ZVAL_UNICODEL(z, u_str, u_len, 0); \
16561656
} else { \
16571657
char *__s=(s); \
16581658
Z_STRLEN_P(z) = strlen(__s); \
@@ -1663,16 +1663,16 @@ END_EXTERN_C()
16631663

16641664
#define ZVAL_U_STRINGL(conv, z, s, l, flags) { \
16651665
if (UG(unicode)) { \
1666-
UErrorCode status = U_ZERO_ERROR; \
16671666
char *__s = (s); \
16681667
int __s_len = (l); \
16691668
UChar *u_str; \
16701669
int u_len; \
1671-
zend_string_to_unicode_ex(conv, &u_str, &u_len, __s, __s_len, &status); \
1670+
if (zend_string_to_unicode(conv, &u_str, &u_len, __s, __s_len) == SUCCESS) { \
1671+
ZVAL_UNICODEL(z, u_str, u_len, 0); \
1672+
} \
16721673
if ((flags) & ZSTR_AUTOFREE) { \
16731674
efree(__s); \
16741675
} \
1675-
ZVAL_UNICODEL(z, u_str, u_len, 0); \
16761676
} else { \
16771677
char *__s=(s); int __l=l; \
16781678
Z_STRLEN_P(z) = __l; \

0 commit comments

Comments
 (0)