Subject: | segmentation fault during t/exotic_names.t |
On OpenBSD 6.0 the test t/exotic_names.t fails sometimes.
Program received signal SIGSEGV, Segmentation fault.
0x00000a9bf44b686a in XS_Sub__Name_subname (cv=Variable "cv" is not available.
) at Name.xs:72
72 else if (*s && s[-1] == '\'') {
(gdb) print s
$1 = 0xa9c6d507000 "test::SOME_y_STASH::SOME_y_NAME"
With OpenBSD malloc randomisation the storage for nameptr is sometimes
at the beginning of the page. Then accessing s[-1] with s == nameptr
is fatal. There must be some check to prevent this. This diff
fixes the bug.
--- Name.xs.orig Thu Aug 18 20:52:37 2016
+++ Name.xs Fri Aug 19 22:57:13 2016
@@ -63,13 +63,13 @@ subname(name, sub)
croak("Not a subroutine reference");
for (s = nameptr; s <= nameptr + namelen; s++) {
- if (*s == ':' && s[-1] == ':') {
+ if (s > nameptr && *s == ':' && s[-1] == ':') {
end = s - 1;
begin = ++s;
if (seen_quote)
need_subst++;
}
- else if (*s && s[-1] == '\'') {
+ else if (s > nameptr && *s != '\0' && s[-1] == '\'') {
end = s - 1;
begin = s;
if (seen_quote++)