This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.git
5 years agofix leak in package name lookup
David Mitchell [Tue, 26 Mar 2019 08:56:55 +0000 (08:56 +0000)]
fix leak in package name lookup

S_parse_gv_stash_name() mallocs a temporary buffer when scanning package
names longer than 64 bytes. Depending on how it exits the function, it
doesn't always free the buffer afterwards. Change the function so that
there are only two exit points (which free the buffer) and make other bits
of code goto those two points.

Can be reproduced with e.g.

&{"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'x"}

Similar code is already present in t/op/stash_parse_gv.t

5 years agofix a leak with indented heredocs
David Mitchell [Mon, 25 Mar 2019 20:13:30 +0000 (20:13 +0000)]
fix a leak with indented heredocs

With something like

   |print <<~EOF;
   | some data
   |   EOF

it croaks (as it should) with "Indentation ... doesn't match delimiter",
but in that case it leaks the recently malloc()d 'indent' buffer.

The fix is simple.  I've also fixed by code inspection where the code
does 'goto interminable', although I didn't try to reproduce the conditions
where the goto might occur.

5 years agoreformat S_scan_heredoc()
David Mitchell [Mon, 25 Mar 2019 19:44:57 +0000 (19:44 +0000)]
reformat S_scan_heredoc()

The indentation was inconsistent and confusing.

Reindent, add blank lines where appropriate, and change this code
comment: "(Closing '}' here to balance"  to '<<}', since vim is far too
clever for its own good these days in terms of using '%' to bounce
between brace pairs.

Should be no functional changes.

5 years agoS_scan_heredoc(): add cosmetic braces
David Mitchell [Mon, 25 Mar 2019 19:14:43 +0000 (19:14 +0000)]
S_scan_heredoc(): add cosmetic braces

add braces round a single-statement 'if' clause which contains a while
loop and spans several lines.

Should be functionally equivalent, but less visually confusing.

5 years agofix leak with local ${^WARNING_BITS} = ...
David Mitchell [Mon, 25 Mar 2019 17:18:58 +0000 (17:18 +0000)]
fix leak with local ${^WARNING_BITS} = ...

When restoring the old value, need to free the current value first.
Can be reproduced with

    {
        local ${^WARNING_BITS} = 'swit';
    }

when run under ASan or similar.
An equivalent test already exists in t/op/leaky-magic.t.

5 years agoIt's an error if any component of \p{user-defined} fails
Karl Williamson [Sun, 24 Mar 2019 20:36:50 +0000 (14:36 -0600)]
It's an error if any component of \p{user-defined} fails

A user-defined property can expand to more than one component that are
combined into a single result.  Prior to this commit, since the move of
this into core C, it was possible that if any component was valid, the
whole thing was considered valid, though in many instances an assertion
failed on DEBUGGING builds.

5 years agoregcomp.c: Fix comment
Karl Williamson [Sun, 24 Mar 2019 20:27:38 +0000 (14:27 -0600)]
regcomp.c: Fix comment

It wasn't quite accurate

5 years agoavoid leak assigning regexp to non-COW string
David Mitchell [Fri, 22 Mar 2019 17:38:48 +0000 (17:38 +0000)]
avoid leak assigning regexp to non-COW string

In something like

    $s = substr(.....); # $s now a non-COW SvPOK() SV
    $r = qr/..../;
    $s = $$r;

$s's previous string buffer would leak when an SVt_REGEXP type SV is
assigned to it.

Worse, if $s was an SVt_PVPV, it would fail an assert on debugging
builds.

The fix is to make sure any remaining stringy stuff is cleaned up
before copying the REGEXP.

5 years agofix leak in BEGIN { threads->new(...) }
David Mitchell [Fri, 22 Mar 2019 15:43:56 +0000 (15:43 +0000)]
fix leak in BEGIN { threads->new(...) }

Normally by the time we reach perl_destruct(), PL_parser should be null
due to having its original (null) value restored by SAVEt_PARSER during
leaving scope (usually before run-time starts in fact).  But if a thread
is created within a BEGIN block, the parser is duped, but the
SAVEt_PARSER savestack entry isn't. So PL_parser never gets cleaned up.
Clean it up in perl_destruct() instead. This is a bit of a hack.

5 years agofix leak in cloned regexes.
David Mitchell [Fri, 22 Mar 2019 12:31:57 +0000 (12:31 +0000)]
fix leak in cloned regexes.

When a regex is cloned for a new thread, the string buffer (which holds
the text of the original pattern) wasn't being freed because SvLEN was
being set to 0.

For example:

    use threads;
    my $r = qr/abc/;
    threads->new( sub { 1; })->join;

In the new thread, $r is cloned  but when the thread exits, the string
buffer holding "(?^:abc)" was leaking.

This was broken by v5.27.2-30-gdf6b4bd565.

The problem was that in the cloned SV, the buffer was copied, but the
SvLEN(sv) was left set at zero, which along with the SVf_FAKE, mader it
look like the buffer was alien and so not freed.

SvLEN was 0 in the parent thread's $r, since $r and its compile-time
prototype share the same string buffer (so only the original SV has
SvLEN > 0 - all the copies - within the same thread - have mother_re
pointing to the original).

When REs are cloned into another thread, mother_re isn't preserved,
so each RE has its own copy of the buffer.

5 years agoFix POSIX::mblen mbstate_t initialization on threaded perls with glibc
Niko Tyni [Sun, 10 Mar 2019 17:40:42 +0000 (19:40 +0200)]
Fix POSIX::mblen mbstate_t initialization on threaded perls with glibc

As reported in https://bugs.launchpad.net/bugs/1818953 POSIX::mblen()
is broken on threaded perls with glibc.

  % perl -MPOSIX=mblen -e 'mblen("a", 1)'
  perl: mbrtowc.c:105: __mbrtowc: Assertion `__mbsinit (data.__statep)' failed.
  zsh: abort (core dumped)  perl -MPOSIX=mblen -e 'mblen("a", 1)'

This broke in v5.27.8-134-g6c9ff7e96e which made the function
use mbrlen(3) under the hood on threaded perls.

The problem is initialization of the shift state with

  mbrlen(NULL, 0, &ps));

The glibc documentation for mbrlen(3) at

  https://www.gnu.org/software/libc/manual/html_node/Converting-a-Character.html#Converting-a-Character

does not mention initialization by passing in a null pointer for the
string, only a pointer to a NUL wide character.

   If the next multibyte character corresponds to the NUL wide character,
   the return value is 0. If the next n bytes form a valid multibyte
   character, the number of bytes belonging to this multibyte character
   byte sequence is returned.

Use memset(3) instead for mbstate_t initialization, as suggested in

  https://www.gnu.org/software/libc/manual/html_node/Keeping-the-state.html

with the hope that this is more portable.

While at it, add a few basic test cases. These are in a new file because
they need fresh_perl_is() from test.pl while the existing ones use
Test::More (and conversion of at least posix.t looks way too involved.)

Bug-Ubuntu: https://bugs.launchpad.net/bugs/1818953

5 years agoPATCH: [perl #132928] Save some bytes
Karl Williamson [Sat, 23 Mar 2019 17:01:58 +0000 (11:01 -0600)]
PATCH: [perl #132928] Save some bytes

This takes Zefram's approach to avoid duplicated string constants on
some compilers

5 years agoperldelta: Add errata for 5.29.9 perldelta
Karl Williamson [Sat, 23 Mar 2019 16:36:59 +0000 (10:36 -0600)]
perldelta: Add errata for 5.29.9 perldelta

5 years agoreg_mesg.t: Add missing '#' comment indicator
Karl Williamson [Sat, 23 Mar 2019 16:25:32 +0000 (10:25 -0600)]
reg_mesg.t: Add missing '#' comment indicator

For d9a91485293e1414746fd028b3782f699519105e.

5 years agoPATCH: [perl #132851] Empty /(?)/
Karl Williamson [Sat, 23 Mar 2019 16:16:16 +0000 (10:16 -0600)]
PATCH: [perl #132851] Empty /(?)/

This changes perlre to note that zero modifiers are allowed in the
(?...) construct, but changes the code to warn about this no-op, but
only under "use re 'strict'".

5 years agoPATCH: [perl #133984] Failure in lookbehind
Karl Williamson [Fri, 22 Mar 2019 20:54:33 +0000 (14:54 -0600)]
PATCH: [perl #133984] Failure in lookbehind

I thought that lookbehind assertions weren't supposed to look beyond the
current position; but this CPAN module demonstrates that they can look
ahead as well.

I built some infrastructure to prevent them from looking ahead.  In
part, this is because Unicode recommends that pattern matching have the
ability to restrict the area of the target being matched.  That
infrastructure is not needed at this time.  But I think we should leave
it in for now anyway, as we see what other bugs the variable length
lookbehind changes may have caused.

So this patch just takes the easy way out, and at the place where it
would restrict the area searched, it uses the full width.  It's a one
line change.

5 years agoPATCH: [perl #133889] Assertion failure
Karl Williamson [Fri, 22 Mar 2019 17:32:32 +0000 (11:32 -0600)]
PATCH: [perl #133889] Assertion failure

I did not bisect this, but this is a regression.

This code is using a user-defined property that isn't defined.  It
should catch that and, since this is within regex sets,  quit, but
instead continues and ends up using an undefined value.

5 years agohandy.h: Change some macros to use new inRANGE
Karl Williamson [Thu, 21 Mar 2019 16:14:37 +0000 (10:14 -0600)]
handy.h: Change some macros to use new inRANGE

It turns out that on ASCII platforms, several of the character classes
are expressible as a single range, and using the new inRANGE macro saves
some instructions each time versus the array lookup still done for these
on EBCDIC platforms.  Here is a sample benchmark

Key:
    Ir   Instruction read
    Dr   Data read
    Dw   Data write
    COND conditional branches
    IND  indirect branches

The numbers represent raw counts per loop iteration.

isDIGIT_A('5')

       blead  hack Ratio %
       ----- ----- -------
    Ir 358.0 355.0   100.8
    Dr 123.0 121.0   101.7
    Dw  57.0  57.0   100.0
  COND  51.0  50.0   102.0
   IND   7.0   7.0   100.0

The differences are small, but these macros are executed ubiquitously

5 years agoGeneralize macro and move to handy.h
Karl Williamson [Wed, 20 Mar 2019 21:31:03 +0000 (15:31 -0600)]
Generalize macro and move to handy.h

The macro verified that its input was in the range '1' to '9' by using a
subtraction and a single conditional.  This commit generalizes this
non-obvious method of avoiding a conditional, and moves it to handy.h so
it can be used in other places.

5 years agoPATCH: [perl #133880] assertion failure
Karl Williamson [Thu, 21 Mar 2019 15:35:49 +0000 (09:35 -0600)]
PATCH: [perl #133880] assertion failure

This was caused by attempting to continue parsing after an error is
found, and later assuming that what came before was valid.  The fix is
to put in something valid that's usable until the parse eventually dies
from what caused this, or some other error.

5 years agolocale.c: White-space, comment only
Karl Williamson [Thu, 21 Mar 2019 15:02:24 +0000 (09:02 -0600)]
locale.c: White-space, comment only

Indent a block newly formed in the previous commit.
Wrap some too-long lines

5 years agolocale.c: Don't try to recreate the LC_ALL C locale
Karl Williamson [Thu, 21 Mar 2019 04:59:39 +0000 (22:59 -0600)]
locale.c: Don't try to recreate the LC_ALL C locale

On threaded perls, we create a locale object for LC_ALL "C" early in the
startup phase.  When the user asks for that locale, we can just switch
to it instead of trying to create a new one.

Doing the creation worked, but ended up with a memory leak.  My guess,
and its only a guess, is that it's a bug in glibc newlocale.c, in which
it does an early return, not doing proper cleanup, when it discovers it
can re-use an existing locale without needing to create a new one.

The reason I think its a glibc bug is that the sample one-liner sent
to me

PERL_DESTRUCT_LEVEL=2 valgrind --leak-check=full ./perl -DLv -Ilib -e'require POSIX;POSIX::setlocale(&POSIX::LC_ALL, "C");' 2>&1 | more

produced a stack output of where the leaked memory had been allocated.
I put a print immediately after that line, and prints at the points
where things get freed.  Every allocation was matched by an attempt to
free it.  But clearly at least one failed.  freelocale() returns void,
so can't be checked for failing.

Anyway, it's better to try not to create a new locale when we already
have an existing one, and doing so, as this commit does, causes the leak
to go away.

No tests are added, as there are plenty of similar tests already in the
suite, and they all should have been leaking.

5 years agoAdd, improve some debugging stmts for -DL (locales)
Karl Williamson [Thu, 21 Mar 2019 04:58:38 +0000 (22:58 -0600)]
Add, improve some debugging stmts for -DL (locales)

5 years agoperldelta: Rmv extraneous =back
Karl Williamson [Thu, 21 Mar 2019 16:46:33 +0000 (10:46 -0600)]
perldelta: Rmv extraneous =back

5 years agoUpdate Module::CoreList for 5.29.10
Zak B. Elep [Thu, 21 Mar 2019 16:18:23 +0000 (00:18 +0800)]
Update Module::CoreList for 5.29.10

Also fix the 5.29.9 `changed` key a bit to reflect commit
c15407c8b80c36d88f9038e7519e468ffd132da5.

5 years agoBump the perl version in various places for 5.29.10
Zak B. Elep [Thu, 21 Mar 2019 15:08:29 +0000 (23:08 +0800)]
Bump the perl version in various places for 5.29.10

5 years agoNew perldelta for 5.29.10
Zak B. Elep [Thu, 21 Mar 2019 12:54:06 +0000 (20:54 +0800)]
New perldelta for 5.29.10

5 years agoTick off 5.29.9!
Zak B. Elep [Thu, 21 Mar 2019 12:35:44 +0000 (20:35 +0800)]
Tick off 5.29.9!

5 years agoEpigraph for 5.29.9
Zak B. Elep [Thu, 21 Mar 2019 12:34:38 +0000 (20:34 +0800)]
Epigraph for 5.29.9

5 years agoEnsure autogenerated files for Devel::PPPort are up to date v5.29.9
Zak B. Elep [Wed, 20 Mar 2019 20:19:08 +0000 (04:19 +0800)]
Ensure autogenerated files for Devel::PPPort are up to date

`make regen` in dist/Devel-PPPort, thanks ether and Pali for guidance!

5 years agoAdd myself to AUTHORS
Zak B. Elep [Wed, 20 Mar 2019 18:02:55 +0000 (02:02 +0800)]
Add myself to AUTHORS

5 years agoAdd 5.29.9 release to pod/perlhist
Zak B. Elep [Wed, 20 Mar 2019 17:52:08 +0000 (01:52 +0800)]
Add 5.29.9 release to pod/perlhist

5 years agoUpdate perldelta for 5.29.9 release
Zak B. Elep [Wed, 20 Mar 2019 17:39:33 +0000 (01:39 +0800)]
Update perldelta for 5.29.9 release

5 years agoUpdate Module::CoreList for 5.29.9
Zak B. Elep [Wed, 20 Mar 2019 16:57:33 +0000 (00:57 +0800)]
Update Module::CoreList for 5.29.9

5 years agoFix $JSON::PP::Boolean::VERSION
Zak B. Elep [Wed, 20 Mar 2019 16:14:52 +0000 (00:14 +0800)]
Fix $JSON::PP::Boolean::VERSION

Match to the correct version of JSON::PP already installed in commit
929e53be972b0c811eca54a3c7017db116f62e4a.

5 years agoPorting/Maintainers.pl: vutil.c is CUSTOMIZED once more
Zak B. Elep [Wed, 20 Mar 2019 15:52:00 +0000 (23:52 +0800)]
Porting/Maintainers.pl: vutil.c is CUSTOMIZED once more

Commit 8633b5394e9f1be292f2b13d5f642a205ae31509 updated vutil.c from the
'version' CPAN distribution but seems to have missed updating the
corresponding Maintainers.pl key; this change also needs pushing to
upstream as well.

5 years agoAdd common UTF-8 first byte to ANYOFH regnodes
Karl Williamson [Wed, 20 Mar 2019 17:47:15 +0000 (11:47 -0600)]
Add common UTF-8 first byte to ANYOFH regnodes

An ANYOFH regnode is generated instead of a plain ANYOF one when
nothing it can match is in the bitmap used in ANYOF nodes.  It is
therefore smaller as the 4 word (or more) bitmap is omitted.

This means that for it to match a target string, that string must be
UTF-8 (since the bitmap is for at least the lowest 256 code points).
And only in rare circumstances are there any flags associated with it in
the regnode flags field.

This commit changes things so that the flags field in an ANYOFH node is
repurposed to be the first UTF-8 encoded byte of every code point
matched by the class if there is a common byte for all of them; or 0 if
some have different first bytes.

(That means that those rare cases where the flags field isn't otherwise
empty can no longer be ANYOFH nodes.)

The purpose of this is so that a future commit can take advantage of
this, and more quickly scan the target string for places that this node
can match.  A problem with ANYOF nodes is that they are code point
oriented (U32 or U64), and the target string is UTF-8, so conversion has
to be done.  By having the partial conversion compiled in, we can look
for that at runtime instead of having to look at every character in the
scan.

5 years agoBump Devel::PPPort to keep in sync with CPAN
Nicolas R [Tue, 19 Mar 2019 20:57:51 +0000 (14:57 -0600)]
Bump Devel::PPPort to keep in sync with CPAN

During Perl 5.29.8 release, Devel-PPPort was uploaded
to CPAN but the distro was incomplete as unit tests
were not part of the submitted tarball.

To fix this, a new 3.45 version was published to CPAN.
This commit, keep blead in sync with this change.

5 years agoPATCH: [perl #133937] Assertion failure
Karl Williamson [Tue, 19 Mar 2019 18:37:04 +0000 (12:37 -0600)]
PATCH: [perl #133937] Assertion failure

This recently added assertion actually caught an error, which is a
potential read beyond end of buffer.  This doesn't actually happen in
this case because this is a regular expression pattern, and the toker
makes sure there is a trailing NUL (that isn't counted).

The solution is to check the bounds before reading.

5 years agodquote.c: Prevent possible out-of-bounds read
Karl Williamson [Tue, 19 Mar 2019 18:21:49 +0000 (12:21 -0600)]
dquote.c: Prevent possible out-of-bounds read

This code read a byte that was potentially out-of-bounds.  I don't know
how it could get this far, but maybe some fuzzing code could get it.

5 years agoChange error wording for empty \x{}
Karl Williamson [Tue, 19 Mar 2019 18:14:26 +0000 (12:14 -0600)]
Change error wording for empty \x{}

An empty \x{} is unfortunately legal (returning a NUL) except in the
scope of "use re 'strict'".  Since this is an experimental feature,
things like wording changes are allowed.  It is unlikely anyone is
relying on the precise wording of this fatal error under 'strict', and
now all the messages for similar errors are similarly worded.

5 years agoChange error wording for \o{}
Karl Williamson [Tue, 19 Mar 2019 18:08:06 +0000 (12:08 -0600)]
Change error wording for \o{}

An empty \o{} no longer says "Number with no digits" in favor of "Empty
\o{}" which is more consistent with errors raised for things like \b{},
\P{}.

There is a small risk of breakage with this change, as with any
diagnostic wording change.  However, this construct is relatively new
and rarely used, and this is a fatal error, not a warning you might want
to trap on.  There are no empty \o{} instances in CPAN.

5 years agoMerge branch 'safer' into blead
Karl Williamson [Tue, 19 Mar 2019 16:25:06 +0000 (10:25 -0600)]
Merge branch 'safer' into blead

I undertook an audit to see where there might be places where malformed
UTF-8 input could cause us to exceed the boundaries of buffers.  I
looked for where hopping to other characters in the string and skipping
to the next character based on the current start byte.

This branch is the result of that.  Wherever I didn't see how exceeding
the bounds wasn't a problem, I changed to use the safer versions of the
hop and skip operations that we already have.  As an example of where it
isn't a problem is when doing the operation is at the end of a loop
iteration, and the loop tests if we've exceeded it, with the result that
the loop just stops executing.

I may have missed things, and  may have changed to unnecessarily use the
safer operations in places

5 years agoregexec.c: Use safe UTF8SKIP
Karl Williamson [Mon, 18 Mar 2019 17:02:23 +0000 (11:02 -0600)]
regexec.c: Use safe UTF8SKIP

5 years agoregexec.c: Use safer utf8_hop
Karl Williamson [Mon, 18 Mar 2019 17:09:22 +0000 (11:09 -0600)]
regexec.c: Use safer utf8_hop

5 years agoregcomp.c: Use safer utf8_hop
Karl Williamson [Mon, 18 Mar 2019 16:38:56 +0000 (10:38 -0600)]
regcomp.c: Use safer utf8_hop

5 years agoregcomp.c: Use safe UTF8SKIP
Karl Williamson [Tue, 19 Mar 2019 02:16:39 +0000 (20:16 -0600)]
regcomp.c: Use safe UTF8SKIP

5 years agopp_ctl.c: Use safe UTF8SKIP
Karl Williamson [Tue, 19 Mar 2019 01:48:48 +0000 (19:48 -0600)]
pp_ctl.c: Use safe UTF8SKIP

5 years agopp_pack.c: Use safe UTF8SKIP
Karl Williamson [Tue, 19 Mar 2019 01:27:57 +0000 (19:27 -0600)]
pp_pack.c: Use safe UTF8SKIP

5 years agopp.c: Use safer utf8_hop
Karl Williamson [Mon, 18 Mar 2019 16:29:46 +0000 (10:29 -0600)]
pp.c: Use safer utf8_hop

5 years agoregexec.c: Add comments
Karl Williamson [Tue, 19 Mar 2019 03:43:34 +0000 (21:43 -0600)]
regexec.c: Add comments

5 years agopp.c, pp_sys.c: Use DO_UTF8 instead of its expansion
Karl Williamson [Tue, 19 Mar 2019 03:17:03 +0000 (21:17 -0600)]
pp.c, pp_sys.c: Use DO_UTF8 instead of its expansion

We have a macro to hide the details of this; use it

5 years agoop_free() remove redundant !kid test
David Mitchell [Tue, 19 Mar 2019 11:15:21 +0000 (11:15 +0000)]
op_free() remove redundant !kid test

and replace with an assert.

If an op has the OPf_KIDS flag, then cUNOPo->op_first must be non-null.
So testing for !kid doesn't do much, especially as on the previous line
we dereference it anyway.

5 years agohandle scope error in qr/\(?{/
David Mitchell [Tue, 19 Mar 2019 10:58:46 +0000 (10:58 +0000)]
handle scope error in qr/\(?{/

RT #133879

In this code:

    BEGIN {$^H = 0x10000 }; # HINT_NEW_RE
    qr/\(?{/

When the toker sees the 'qr', it looks ahead and thinks that the
pattern *might* contain code blocks, so creates a new anon sub to wrap
compilation of the pattern in (so that any code blocks get compiled as
part of the anon sub rather than the main body of the code).

Normally at the end of parsing the qr construct, the parser notes that
no code blocks were found, and throws the unneeded CV away and
restores the old PL_compcv (via a LEAVE_SCOPE). This false positive is
normal and is expected in the relevant code paths.

However, setting the HINT_NEW_RE  (which indicates that
overload::constant is present for qr// but with no overloaded function
actually present) causes an error to be raised. The parser does error
recovery and continues.

However, v5.25.9-148-g7c44985626 added a test to not bother compiling a
pattern if the parser is in an errored state, which again is fine,
except it turns out that if this branch is taken, it skips the 'restore
the old PL_compcv' code, leading to the wrong value for PL_compcv when
ops are freed.

The fix is simple: move the "skip if errored" test to after PL_compcv
has been restored.

5 years agoMerge branch 'vlb' into blead
Karl Williamson [Mon, 18 Mar 2019 17:05:33 +0000 (11:05 -0600)]
Merge branch 'vlb' into blead

This branch implements variable length lookbehind in regular expression
patterns.

5 years agoregexec.c: White-space only
Karl Williamson [Mon, 18 Mar 2019 03:47:16 +0000 (21:47 -0600)]
regexec.c: White-space only

Outdent to reflect removed enclosing block

5 years agoImplement variable length lookbehind in regex patterns
Karl Williamson [Mon, 18 Mar 2019 03:06:10 +0000 (21:06 -0600)]
Implement variable length lookbehind in regex patterns

See [perl #132367].

5 years agoregexec.c: regmatch(): Add pushing eol
Karl Williamson [Sun, 17 Mar 2019 18:36:48 +0000 (12:36 -0600)]
regexec.c: regmatch(): Add pushing eol

This continues the process of changing regmatch() to be able to restrict
the end point of where it is looking in the input, by adding that eol
position to the pushed state, and popping it when appropriate.

5 years agoregexec.c: restrict match to substring in regmatch()
Karl Williamson [Sun, 17 Mar 2019 16:52:41 +0000 (10:52 -0600)]
regexec.c: restrict match to substring in regmatch()

This begins to add the capability to regmatch() to not look beyond a
certain point in the string in order to find a match.  But this is
currently set to the end of the entire string so it shouldn't affect any
current outcomes.

5 years agoregexec.c: Add parameter to static fcn
Karl Williamson [Sun, 17 Mar 2019 16:36:48 +0000 (10:36 -0600)]
regexec.c: Add parameter to static fcn

This parameter will be used to limit how far in the input string to
apply the function to.  But currently, it is set to the end of the
string, so there should be no change from previous behavior.

5 years agoAdd warning category for variable length lookbehind
Karl Williamson [Sat, 16 Mar 2019 19:37:59 +0000 (13:37 -0600)]
Add warning category for variable length lookbehind

5 years agoregexec.c: Rmv unnecessary assigns
Karl Williamson [Sun, 17 Mar 2019 16:19:21 +0000 (10:19 -0600)]
regexec.c: Rmv unnecessary assigns

We never use this variable again (this isn't in a loop unlike similar
cases in other functions in this file), so we don't care if it gets
updated.  Instead use the source value directly.

5 years agoregexec.c: Delete unused macro
Karl Williamson [Sun, 17 Mar 2019 18:00:23 +0000 (12:00 -0600)]
regexec.c: Delete unused macro

5 years agoregexec.c: Comment fixes, additions
Karl Williamson [Sun, 17 Mar 2019 18:09:40 +0000 (12:09 -0600)]
regexec.c: Comment fixes, additions

5 years agoregexec.c: Move macro defns, comments adjacent to fcn
Karl Williamson [Sun, 17 Mar 2019 18:07:41 +0000 (12:07 -0600)]
regexec.c: Move macro defns, comments adjacent to fcn

Over the years the heading comments for regmatch(), as well as the macro
definitions that are used by just it, have become separated from it by
many intervening functions.  This moves things back so the things that
apply just to regmatch() are just before it.

5 years agoperlre: Link technique for variable length lookbehind
Karl Williamson [Sat, 16 Mar 2019 20:26:49 +0000 (14:26 -0600)]
perlre: Link technique for variable length lookbehind

This web page gives a technique that one can use to achieve variable
length lookbehinds.

5 years agoperlvar: improve POD markup for $-[n] example
Dagfinn Ilmari Mannsåker [Mon, 18 Mar 2019 15:47:26 +0000 (15:47 +0000)]
perlvar: improve POD markup for $-[n] example

Closing and re-opening the C<> arond the I<> leads to weird formatting
in man/text mode.  Instead nest the I<> inside the C<>.

5 years agofix paren buffer leak in (?|...)
David Mitchell [Tue, 12 Mar 2019 11:05:48 +0000 (11:05 +0000)]
fix paren buffer leak in (?|...)

The (?| ... | ... |... ) alternation resets the paren index for each
branch. This can trick the code in S_reg() into re-mallocing the open
and close paren index buffers during every branch, leaking the old ones.

This commit fixes the leak by introducing a new compilation variable,
RExC_parens_buf_size, which records the actual number of slots malloced.

By decoupling RExC_parens_buf_size from RExC_npar, it also means that
the code can allocate a buffer larger than currently needed. This means
that
    /(.)(.)(.)(.)/

no longer does a malloc() and 3 reallocs(), but instead initially
mallocs 10 slots, and if more than 10 captures are seen during
compilation, reallocs() to 20, 40, 80 ....

5 years agoPATCH: [perl #131551] Too deep regex compilation recursion
Karl Williamson [Mon, 18 Mar 2019 04:11:04 +0000 (22:11 -0600)]
PATCH: [perl #131551] Too deep regex compilation recursion

This patch, started by Yves Orton, and refined in consultation with Tony
Cook, imposes a maximum depth of unclosed left parentheses, at which
point it croaks.  This is to prevent the segfault in the ticket.

The patch adds a variable that can be set to increase or decrease this
limit at run time (actually regex compilation time) should this be
desired, and hence our pre-determined limit of 1000 can be changed if
necessary.

5 years agoregcomp.c: Use mnemonic for flag parameter
Karl Williamson [Mon, 18 Mar 2019 03:59:52 +0000 (21:59 -0600)]
regcomp.c: Use mnemonic for flag parameter

5 years agoperlre: Consistent casing and spelling of VERB args
Karl Williamson [Sat, 16 Mar 2019 19:22:35 +0000 (13:22 -0600)]
perlre: Consistent casing and spelling of VERB args

5 years agorealclean unidatafiles on VMS the same way as elsewhere.
Craig A. Berry [Sat, 16 Mar 2019 19:10:40 +0000 (14:10 -0500)]
realclean unidatafiles on VMS the same way as elsewhere.

We were deleting lib/unicore/*.pl, but with uni_keywords.pl there
is now one non-generated .pl file in that directory.  Deleting it
in realclean caused subsequent configure attempts in the same
directory tree to fail.

5 years agoinline.h: Improve comment
Karl Williamson [Fri, 15 Mar 2019 17:11:11 +0000 (11:11 -0600)]
inline.h: Improve comment

5 years agoutf8_length() Add two UNLIKELY()s
Karl Williamson [Fri, 15 Mar 2019 03:39:56 +0000 (21:39 -0600)]
utf8_length() Add two UNLIKELY()s

The input is likely to be valid.

5 years agoS_multiconcat() Use faster variant counting
Karl Williamson [Thu, 23 Nov 2017 06:10:01 +0000 (23:10 -0700)]
S_multiconcat() Use faster variant counting

5 years agotoke.c: lex_stuff_pvn() Use faster UTF-8 variant count
Karl Williamson [Thu, 23 Nov 2017 06:12:37 +0000 (23:12 -0700)]
toke.c: lex_stuff_pvn() Use faster UTF-8 variant count

What finally got me to push this commit, since speed really doesn't
matter during compilation, is that this removes a hand-rolled
implementation.

5 years agot/re/pat.t: Add test for [perl #133933]
Karl Williamson [Thu, 14 Mar 2019 23:37:29 +0000 (17:37 -0600)]
t/re/pat.t: Add test for [perl #133933]

This was fixed by bf848a12528ab1e63a2f20da532eda498adbdca6.

5 years agoregcomp.c: Add assertions
Karl Williamson [Thu, 14 Mar 2019 23:06:16 +0000 (17:06 -0600)]
regcomp.c: Add assertions

These make sure we don't exceed the 32 bits available for long jumps.

5 years agoAdd more checking for regnode offset overflowing
Karl Williamson [Thu, 14 Mar 2019 22:46:50 +0000 (16:46 -0600)]
Add more checking for regnode offset overflowing

This is part of the ongoing failures in [perl #133921].

The bottom line cause is that there are generally 16 bits available for
the address of the next regnode.  On very large patterns, this may not
be enough.  When that happens, a long jump is used instead.

What previous commits have done is to insert tests in a loop to detect
that overflow isn't going to occur.  But it turns out that there are
other places where such overflow could occur.  The real solution should
be to detect overflow in the base level routine that would otherwise get
things wrong.  This entails making that routine be able to return
failure.  It turns out that another function is used under DEBUGGING, so
that one must be changed as well.  And the calls where it is possible
for this to overflow are changed to look for failure return and proceed
appropriately, which is to set a flag that we need to use long jumps,
and restart the parse.

5 years agoregnodes.h, perldebguts: Shorten some descriptions
Karl Williamson [Thu, 14 Mar 2019 17:50:10 +0000 (11:50 -0600)]
regnodes.h, perldebguts: Shorten some descriptions

5 years agoAny Common digit set can match in any script
Karl Williamson [Thu, 14 Mar 2019 17:48:11 +0000 (11:48 -0600)]
Any Common digit set can match in any script

This fixes a design flaw in script runs that in 5.30 effectively
prevented digits from the Common script except the ASCII [0-9] from
being in any meaningful script run.

5 years agoPATCH: [perl #133921] Segfaults in regcomp.c
Karl Williamson [Thu, 14 Mar 2019 03:25:05 +0000 (21:25 -0600)]
PATCH: [perl #133921] Segfaults in regcomp.c

If a regular expression pattern gets too long so that the branch
instructions need more bits than are available, it is supposed to
reparse and use long jumps instead of the normal ones that don't take up
extra room.  The blamed commit caused the test for this to be done too
late.  This just moves the test to do it in time; lexically later in the
file, but just after the variable takes on the too-large value and
before it gets used in the next loop iteration.

5 years agot/re/pat.t: Rmv stray semi-colon
Karl Williamson [Thu, 14 Mar 2019 03:24:47 +0000 (21:24 -0600)]
t/re/pat.t: Rmv stray semi-colon

5 years agoPATCH: [perl #133871] heap-buffer-overflow in S_reginsert
Karl Williamson [Thu, 14 Mar 2019 01:11:46 +0000 (19:11 -0600)]
PATCH: [perl #133871] heap-buffer-overflow in S_reginsert

The regex compiler was written assuming it knew how many parentheses
pairs there were at code generation time.  When I converted to a single
pass in 7c932d07cab18751bfc7515b4320436273a459e2, most things were
straight forward to not have to know this number, but there were a few
where it was non-trivial (for me anyway) to figure out how to handle.
So I punted on these and do a second pass when these are encountered.
There are few of them and are less commonly used, namely (?R), (?|...)
and forward references to groups (which most commonly will end up being
a syntax error anyway).

The fix in this commit is to avoid doing some parentheses relocations
when a regnode is inserted when it is known that the parentheses counts
are unreliable (during initial parsing of one of these tricky
constructs).  The code in the ticket is using a branch reset '(?|...)'.
A second pass will get done, and the insert properly handled then, after
the counts are reliable.

5 years agoregcomp.c: Create macro, add comments
Karl Williamson [Thu, 14 Mar 2019 00:41:45 +0000 (18:41 -0600)]
regcomp.c: Create macro, add comments

5 years agoregcomp.c: Rmv unused variable
Karl Williamson [Thu, 14 Mar 2019 00:45:34 +0000 (18:45 -0600)]
regcomp.c: Rmv unused variable

5 years agot/re/pat.t: Outdent 2 lines
Karl Williamson [Tue, 12 Mar 2019 21:56:05 +0000 (15:56 -0600)]
t/re/pat.t: Outdent 2 lines

5 years agoAllow qr'\N{...}'
Karl Williamson [Thu, 14 Mar 2019 00:03:01 +0000 (18:03 -0600)]
Allow qr'\N{...}'

5 years agoregcomp.c: White-space, comments only
Karl Williamson [Wed, 13 Mar 2019 23:58:00 +0000 (17:58 -0600)]
regcomp.c: White-space, comments only

5 years agotoke.c: Allow \N{} handling fcn to be used elsewhere in core
Karl Williamson [Thu, 12 Jan 2017 21:50:26 +0000 (14:50 -0700)]
toke.c: Allow \N{} handling fcn to be used elsewhere in core

This function will be used in regcomp.c in a later commit.  This commit
changes the function so that it is callable outside of toke.c.  It adds
a parameter and moves some code in new_constant to the wrapper function
so that these do not cause problems when called from outside toke.  And
it adds some assertions

5 years agotoke.c: Add wrapper function
Karl Williamson [Thu, 12 Jan 2017 21:46:21 +0000 (14:46 -0700)]
toke.c: Add wrapper function

This is in preparation for the underlying function to be called from
elsewhere.  This adds a wrapper to be used internally in toke.c that
keeps the other caller of the underlying function from having to know
the changes to that function.  That function is changed to return any
error message instead of raising it itself.

5 years agotoke.c: Change API of static function
Karl Williamson [Tue, 17 Jan 2017 00:43:06 +0000 (17:43 -0700)]
toke.c: Change API of static function

This will be useful in future commits.  new_constant() is changed so
that if an extra parameter is not NULL, it sets it to point to an error
message instead of raising the message itself.  Thus its caller can
choose to handle errors itself.

5 years agothere is no sv_catpvfn()
Tony Cook [Wed, 13 Mar 2019 23:19:04 +0000 (10:19 +1100)]
there is no sv_catpvfn()

Replace in various documentation and messages appropriately.

5 years agoregcomp.h: Rmv obsolete references to 'swash'
Karl Williamson [Fri, 8 Mar 2019 20:16:53 +0000 (13:16 -0700)]
regcomp.h: Rmv obsolete references to 'swash'

regexes no longer use these

5 years agoregexec.c: We know the end ptr; don't need to recalc
Karl Williamson [Wed, 13 Mar 2019 21:21:39 +0000 (15:21 -0600)]
regexec.c: We know the end ptr; don't need to recalc

5 years agoregexec.c: Add assertion
Karl Williamson [Wed, 13 Mar 2019 21:20:50 +0000 (15:20 -0600)]
regexec.c: Add assertion

5 years agoregcomp.c: Add assertion
Karl Williamson [Wed, 13 Mar 2019 20:23:03 +0000 (14:23 -0600)]
regcomp.c: Add assertion

5 years agoregcomp.c: Rmv unnecessary branch
Karl Williamson [Wed, 13 Mar 2019 19:36:00 +0000 (13:36 -0600)]
regcomp.c: Rmv unnecessary branch

The function memchr() seems to get inlined so it is very fast, and it's
legal to call it with a 0 length, so let it figure out that it's zero.

5 years agoperlvar: Fix broken link
Karl Williamson [Wed, 13 Mar 2019 19:23:24 +0000 (13:23 -0600)]
perlvar: Fix broken link

5 years agoperlrecharclass: Minor wording improvements
Karl Williamson [Wed, 13 Mar 2019 19:18:28 +0000 (13:18 -0600)]
perlrecharclass: Minor wording improvements