diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 1999-08-19 19:01:41 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 1999-08-19 19:01:41 +0000 |
commit | a50d7633b624bae17978449ecd97928ccd5098bb (patch) | |
tree | 2a13c20eda30cb53d3ac59bd980dbc05a43ce668 /doop.c | |
parent | 0a1cd6876ba3626bc024955a009f06feab677d27 (diff) | |
download | perl-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.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -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 */ |