Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid segfault when freeing parse
Browse files Browse the repository at this point in the history
RT-115034

Protect active parser from being freed

URL: https://rt.cpan.org/Public/Bug/Display.html?id=115034
Author: sprout
atoomic committed Aug 24, 2020
1 parent ce42c7b commit 54f2533
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ t/entities.t Test encoding/decoding of entities
t/entities2.t Test _decode_entities()
t/filter-methods.t Test ignore_tags, ignore_elements methods.
t/filter.t Test HTML::Filter
t/free.t Test freeing of active parser
t/handler-eof.t Test invocation of $p->eof in handlers
t/handler.t Test $p->handler method
t/headparser-http.t Test HTML::HeadParser
1 change: 1 addition & 0 deletions Parser.xs
Original file line number Diff line number Diff line change
@@ -377,6 +377,7 @@ parse(self, chunk)
PREINIT:
PSTATE* p_state = get_pstate_hv(aTHX_ self);
PPCODE:
(void)sv_2mortal(SvREFCNT_inc(SvRV(self)));
if (p_state->parsing)
croak("Parse loop not allowed");
p_state->parsing = 1;
14 changes: 14 additions & 0 deletions t/free.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!perl -w

use Test::More tests => 1;

use HTML::Parser;
$p = new HTML::Parser(
start_h => [sub {
undef $p;
}],
);

$p->parse(q(<foo>));

pass;

0 comments on commit 54f2533

Please sign in to comment.