summaryrefslogtreecommitdiff
path: root/doop.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>1999-08-19 19:01:41 +0000
committerJarkko Hietaniemi <jhi@iki.fi>1999-08-19 19:01:41 +0000
commita50d7633b624bae17978449ecd97928ccd5098bb (patch)
tree2a13c20eda30cb53d3ac59bd980dbc05a43ce668 /doop.c
parent0a1cd6876ba3626bc024955a009f06feab677d27 (diff)
downloadperl-a50d7633b624bae17978449ecd97928ccd5098bb.tar.gz
Tighten the vec() code so that naughty BITS cause an error.
p4raw-id: //depot/cfgperl@4006
Diffstat (limited to 'doop.c')
-rw-r--r--doop.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/doop.c b/doop.c
index b06483852c..36fb6b37f8 100644
--- a/doop.c
+++ b/doop.c
@@ -704,8 +704,10 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
unsigned char *s = (unsigned char *) SvPV(sv, srclen);
UV retnum = 0;
- if (offset < 0 || size < 1)
+ if (offset < 0)
return retnum;
+ if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
+ Perl_croak(aTHX_ "Illegal number of bits in vec");
offset *= size; /* turn into bit offset */
len = (offset + size + 7) / 8; /* required number of bytes */
if (len > srclen) {
@@ -735,8 +737,6 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
((UV) s[offset + 1] << 16) +
( s[offset + 2] << 8);
}
- else
- Perl_croak(aTHX_ "Illegal number of bits in vec");
}
}
else if (size < 8)
@@ -755,8 +755,6 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
((UV) s[offset + 1] << 16) +
( s[offset + 2] << 8) +
s[offset + 3];
- else
- Perl_croak(aTHX_ "Illegal number of bits in vec");
}
return retnum;
@@ -780,6 +778,8 @@ Perl_do_vecset(pTHX_ SV *sv)
lval = SvUV(sv);
offset = LvTARGOFF(sv);
size = LvTARGLEN(sv);
+ if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
+ Perl_croak(aTHX_ "Illegal number of bits in vec");
offset *= size; /* turn into bit offset */
len = (offset + size + 7) / 8; /* required number of bytes */