summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2003-05-10 02:45:23 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-05-11 20:06:03 +0000
commit815f25c6e302f84ecce02c74fa717a19d787f662 (patch)
tree375a44792420e7d61ab304dec3eee30530983e56 /pp_ctl.c
parent3ebac25bf00794df08226119e9ae3699268f48dc (diff)
downloadperl-815f25c6e302f84ecce02c74fa717a19d787f662.tar.gz
[perl #7391] Perl crashes with certain write() formats.
Message-ID: <20030510004523.GC20871@fdgroup.com> p4raw-id: //depot/perl@19496
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 91fc2caa00..866567836d 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3573,11 +3573,20 @@ S_doparseform(pTHX_ SV *sv)
U16 *linepc = 0;
register I32 arg;
bool ischop;
+ int maxops = 2; /* FF_LINEMARK + FF_END) */
if (len == 0)
Perl_croak(aTHX_ "Null picture in formline");
- New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
+ /* estimate the buffer size needed */
+ for (base = s; s <= send; s++) {
+ if (*s == '\n' || *s == '@' || *s == '^')
+ maxops += 10;
+ }
+ s = base;
+ base = Nullch;
+
+ New(804, fops, maxops, U16);
fpc = fops;
if (s < send) {
@@ -3740,6 +3749,7 @@ S_doparseform(pTHX_ SV *sv)
}
*fpc++ = FF_END;
+ assert (fpc <= fops + maxops); /* ensure our buffer estimate was valid */
arg = fpc - fops;
{ /* need to jump to the next word */
int z;