Skip to content

Commit cb7c3c0

Browse files
authored
Merge pull request #11 from bleargh45/bleargh.address-cve-2026-56017
Fixes CVE-2026-56017, which would SEGFAULT Perl.
2 parents 02f59c3 + 69a975a commit cb7c3c0

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎Changes‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Revision history for Perl extension JavaScript::Minifier::XS.
22

33
{{$NEXT}}
4+
- Fixes CVE-2026-56017, which caused Perl to SEGFAULT when calling
5+
minify(). Thanks to CPANSec for raising the issue, and providing a
6+
prototype fix.
47

58
0.15 2021-10-15 20:21:23-07:00 America/Vancouver
69
- GH#8 - preserve newlines when collapsing whitespace; if a block of

‎XS.xs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,14 @@ Node* JsTokenizeString(JsDoc* doc, const char* string) {
446446
char ch = 0;
447447

448448
/* find last non-whitespace, non-comment node */
449-
while (nodeIsWHITESPACE(last) || nodeIsCOMMENT(last))
449+
while (last && (nodeIsWHITESPACE(last) || nodeIsCOMMENT(last)))
450450
last = last->prev;
451451

452-
ch = last->contents[last->length-1];
452+
if (last && (last->length > 0))
453+
ch = last->contents[last->length-1];
453454

454455
/* see if we're "division" or "regexp" */
455-
if (nodeIsIDENTIFIER(last) && nodeEquals(last, "return")) {
456+
if (last && nodeIsIDENTIFIER(last) && nodeEquals(last, "return")) {
456457
/* returning a regexp from a function */
457458
_JsExtractLiteral(doc, node);
458459
}

‎t/CVE-2026-56017.t‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use Test::More;
6+
use JavaScript::Minifier::XS qw(minify);
7+
8+
###############################################################################
9+
# CVE-2026-56017
10+
eval { minify('/') };
11+
pass 'minified the JS without SEGFAULTing';
12+
13+
###############################################################################
14+
done_testing();

0 commit comments

Comments
 (0)