Skip to content

Commit e9c763e

Browse files
committed
pv_uni_display() Don't assume input is valid
This function naively assumed that it could do UTF8_SKIP on its input unchallenged. But it's actually less work to get the actual value; just change the call of the function it uses to translate the input, so that it returns the length.
1 parent 1e60ec6 commit e9c763e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

utf8.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,14 +4188,15 @@ char *
41884188
Perl_pv_uni_display(pTHX_ SV *dsv, const U8 *spv, STRLEN len, STRLEN pvlim,
41894189
UV flags)
41904190
{
4191+
PERL_ARGS_ASSERT_PV_UNI_DISPLAY;
4192+
41914193
int truncated = 0;
41924194
const U8 *s, *e;
4193-
4194-
PERL_ARGS_ASSERT_PV_UNI_DISPLAY;
4195+
STRLEN next_len = 0;
41954196

41964197
SvPVCLEAR(dsv);
41974198
SvUTF8_off(dsv);
4198-
for (s = spv, e = s + len; s < e; s += UTF8SKIP(s)) {
4199+
for (s = spv, e = s + len; s < e; s += next_len) {
41994200
UV u;
42004201
bool ok = 0;
42014202

@@ -4204,7 +4205,9 @@ Perl_pv_uni_display(pTHX_ SV *dsv, const U8 *spv, STRLEN len, STRLEN pvlim,
42044205
break;
42054206
}
42064207

4207-
u = utf8_to_uvchr_buf(s, e, 0);
4208+
u = utf8_to_uvchr_buf(s, e, &next_len);
4209+
assert(next_len > 0);
4210+
42084211
if (u < 256) {
42094212
const U8 c = (U8) u;
42104213
if (flags & UNI_DISPLAY_BACKSLASH) {

0 commit comments

Comments
 (0)