Subject: | List::MoreUtils::after's XS implementation call XSRETURN(-1) when it doesn't find an element |
I noticed that List::MoreUtils::after can corrupt memory when it doesn't
find an element from a list.
List::MoreUtils::after's XS implementation have a loop
for (i = 1; i < items; i++) {
GvSV(PL_defgv) = args[i];
MULTICALL;
if (SvTRUE(*PL_stack_sp)) {
break;
}
}
and
XSRETURN(items-i-1);
However, if it can't find an element on the loop, XSRETURN(items-i-1)
became XSRETURN(-1).
In this patch, I added XSRETURN_EMPTY after the loop to fix this
problem.
Subject: | after.diff |
diff --git a/MoreUtils.xs b/MoreUtils.xs
index 5abed72..e14bb42 100644
--- a/MoreUtils.xs
+++ b/MoreUtils.xs
@@ -640,6 +640,9 @@ CODE:
POP_MULTICALL;
+ if (i == items) /* the above loop didn't find an element */
+ XSRETURN_EMPTY;
+
for (j = i + 1; j < items; ++j)
args[j-i-1] = args[j];