summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_pack.c2
-rw-r--r--t/op/pack.t6
2 files changed, 6 insertions, 2 deletions
diff --git a/pp_pack.c b/pp_pack.c
index e86de04bbb..0cbe3c4d4b 100644
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -2094,7 +2094,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
char *cur = start + SvCUR(cat);
bool needs_swap;
-#define NEXTFROM (lengthcode ? lengthcode : items-- > 0 ? *beglist++ : &PL_sv_no)
+#define NEXTFROM (lengthcode ? lengthcode : items > 0 ? (--items, *beglist++) : &PL_sv_no)
#define PEEKFROM (lengthcode ? lengthcode : items > 0 ? *beglist : &PL_sv_no)
switch (howlen) {
diff --git a/t/op/pack.t b/t/op/pack.t
index 8b464dd696..9416ad6e5e 100644
--- a/t/op/pack.t
+++ b/t/op/pack.t
@@ -12,7 +12,7 @@ my $no_endianness = $] > 5.009 ? '' :
my $no_signedness = $] > 5.009 ? '' :
"Signed/unsigned pack modifiers not available on this perl";
-plan tests => 14707;
+plan tests => 14708;
use strict;
use warnings qw(FATAL all);
@@ -2012,3 +2012,7 @@ package o {
is pack("c", bless [], "o"), chr(42), 'overloading called';
is $o::str, undef, 'pack "c" does not call string overloading';
is $o::num, 1, 'pack "c" does call num overloading';
+
+#[perl #123874]: argument underflow leads to corrupt length
+eval q{ pack "pi/x" };
+ok(1, "argument underflow did not crash");