Skip to content

Commit 452bfe6

Browse files
committed
[intl] Return false from Spoofchecker checks on ICU failure
isSuspicious(), areConfusable() and areBidiConfusable() warned on U_FAILURE and then returned true, reporting an internal ICU failure as a positive detection, and left the intl error code at U_ZERO_ERROR so a caller could not tell the two apart. Record the code and return false, matching setAllowedChars() and the skeleton helpers in the same file.
1 parent 0a3fe0a commit 452bfe6

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

ext/intl/spoofchecker/spoofchecker_main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ U_CFUNC PHP_METHOD(Spoofchecker, isSuspicious)
4646
ret = intl_icu_compat_uspoof_check_utf8(co->uspoof, ZSTR_VAL(text), ZSTR_LEN(text), co->uspoofres, SPOOFCHECKER_ERROR_CODE_P(co));
4747

4848
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
49+
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
4950
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
5051

5152
if (intl_icu_compat_uspoof_check_result_mismatch(co->uspoofres, ret, &errmask, SPOOFCHECKER_ERROR_CODE_P(co))) {
5253
php_error_docref(NULL, E_WARNING, "unexpected error (%d), does not relate to the flags passed to setChecks (%d)", ret, errmask);
5354
}
54-
RETURN_TRUE;
55+
RETURN_FALSE;
5556
}
5657

5758
if (error_code) {
@@ -83,8 +84,9 @@ U_CFUNC PHP_METHOD(Spoofchecker, areConfusable)
8384
ret = uspoof_areConfusableUTF8(co->uspoof, ZSTR_VAL(s1), (int32_t)ZSTR_LEN(s1), ZSTR_VAL(s2), (int32_t)ZSTR_LEN(s2), SPOOFCHECKER_ERROR_CODE_P(co));
8485
}
8586
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
87+
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
8688
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
87-
RETURN_TRUE;
89+
RETURN_FALSE;
8890
}
8991

9092
if (error_code) {
@@ -355,8 +357,9 @@ U_CFUNC PHP_METHOD(Spoofchecker, areBidiConfusable)
355357
ret = uspoof_areBidiConfusableUTF8(co->uspoof, (UBiDiDirection)direction, ZSTR_VAL(s1), (int32_t)ZSTR_LEN(s1), ZSTR_VAL(s2), (int32_t)ZSTR_LEN(s2), SPOOFCHECKER_ERROR_CODE_P(co));
356358
}
357359
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
360+
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
358361
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
359-
RETURN_TRUE;
362+
RETURN_FALSE;
360363
}
361364

362365
if (error_code) {

0 commit comments

Comments
 (0)