Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Commit 9a25f21

Browse files
committed
Fix infinite loop when a character is not detected.
1 parent f064c9e commit 9a25f21

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/char_ref.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13993,12 +13993,8 @@ static bool consume_named_ref(
1399313993
(void) ts;
1399413994

1399513995
start = p;
13996-
// Note that the state machine operates on raw character buffers, so it's not
13997-
// consuming any characters. As a result, we don't need to do any mark/reset
13998-
// calls, but we do need to call utf8iterator_maybe_consume_match on success
13999-
// to consume the characters we just looked at.
1400013996

14001-
#line 14002 "char_ref.c"
13997+
#line 13998 "char_ref.c"
1400213998
{
1400313999
int _slen;
1400414000
int _trans;
@@ -14020,7 +14016,7 @@ static bool consume_named_ref(
1402014016
#line 1 "NONE"
1402114017
{ts = p;}
1402214018
break;
14023-
#line 14024 "char_ref.c"
14019+
#line 14020 "char_ref.c"
1402414020
}
1402514021
}
1402614022

@@ -22999,7 +22995,7 @@ static bool consume_named_ref(
2299922995
#line 2272 "char_ref.rl"
2300022996
{{p = ((te))-1;}{ output->first = 0xd7; }}
2300122997
break;
23002-
#line 23003 "char_ref.c"
22998+
#line 22999 "char_ref.c"
2300322999
}
2300423000
}
2300523001

@@ -23012,7 +23008,7 @@ static bool consume_named_ref(
2301223008
#line 1 "NONE"
2301323009
{ts = 0;}
2301423010
break;
23015-
#line 23016 "char_ref.c"
23011+
#line 23012 "char_ref.c"
2301623012
}
2301723013
}
2301823014

@@ -23032,15 +23028,16 @@ static bool consume_named_ref(
2303223028
_out: {}
2303323029
}
2303423030

23035-
#line 2490 "char_ref.rl"
23031+
#line 2486 "char_ref.rl"
2303623032

23037-
if (false) {
23033+
if (cs >=
23034+
#line 23035 "char_ref.c"
23035+
7623
23036+
#line 2487 "char_ref.rl"
23037+
) {
2303823038
assert(output->first != kGumboNoChar);
2303923039
char last_char = *(te - 1);
2304023040
int len = te - start;
23041-
// Consume the match outside of the if-statement below;
23042-
// is_legal_attribute_char_next depends upon the iterator having been
23043-
// advanced past it.
2304423041
if (last_char == ';') {
2304523042
bool matched = utf8iterator_maybe_consume_match(input, start, len, true);
2304623043
assert(matched);
@@ -23061,6 +23058,8 @@ static bool consume_named_ref(
2306123058
return false;
2306223059
}
2306323060
} else {
23061+
output->first = kGumboNoChar;
23062+
output->second = kGumboNoChar;
2306423063
bool status = maybe_add_invalid_named_reference(parser, input);
2306523064
utf8iterator_reset(input);
2306623065
return status;

src/char_ref.rl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,7 @@ static bool consume_named_ref(
24842484
start = p;
24852485
%% write exec;
24862486

2487-
if (output->first != kGumboNoChar) {
2487+
if (cs >= %%{ write first_final; }%%) {
24882488
assert(output->first != kGumboNoChar);
24892489
char last_char = *(te - 1);
24902490
int len = te - start;
@@ -2508,6 +2508,8 @@ static bool consume_named_ref(
25082508
return false;
25092509
}
25102510
} else {
2511+
output->first = kGumboNoChar;
2512+
output->second = kGumboNoChar;
25112513
bool status = maybe_add_invalid_named_reference(parser, input);
25122514
utf8iterator_reset(input);
25132515
return status;

0 commit comments

Comments
 (0)