}
use strict;
-plan(tests => 42);
+plan(tests => 43);
# heredoc without newline (#65838)
{},
"Don't assert parsing a here-doc if we hit EOF early"
);
+
+ # [perl #129064] heap-buffer-overflow S_scan_heredoc
+ fresh_perl_like(
+ qq(<<`\\),
+ # valgrind and asan reports an error between these two lines
+ qr/^Unterminated delimiter for here document/,
+ {},
+ "delimcpy(): handle last char being backslash properly"
+ );
+
}
#endif
-/* copy a string up to some (non-backslashed) delimiter, if any */
+/* copy a string up to some (non-backslashed) delimiter, if any.
+ * With allow_escape, converts \<delimiter> to <delimiter>, while leaves
+ * \<non-delimiter> as-is.
+ * Returns the position in the src string of the closing delimiter, if
+ * any, or returns fromend otherwise.
+ * This is the internal implementation for Perl_delimcpy and
+ * Perl_delimcpy_no_escape.
+ */
static char *
S_delimcpy(char *to, const char *toend, const char *from,
PERL_ARGS_ASSERT_DELIMCPY;
for (tolen = 0; from < fromend; from++, tolen++) {
- if (allow_escape && *from == '\\') {
+ if (allow_escape && *from == '\\' && from + 1 < fromend) {
if (from[1] != delim) {
if (to < toend)
*to++ = *from;