Skip to content

Commit

Permalink
BC: protect against core #define xpv_len
Browse files Browse the repository at this point in the history
8d919b0a  Father Chrysostomos 2012-10-30 redefined xpv_len
to xpv_len_u.xpvlenu_len
  • Loading branch information
Reini Urban committed Nov 2, 2012
1 parent 2cb0016 commit 8faee52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
42 changes: 21 additions & 21 deletions ByteLoader/bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ static int bget_swab = 0;
#define BGET_PV(arg) STMT_START { \
BGET_U32(arg); \
if (arg) { \
New(666, bstate->bs_pv.xpv_pv, (U32)arg, char); \
bl_read(bstate->bs_fdata, bstate->bs_pv.xpv_pv, (U32)arg, 1); \
bstate->bs_pv.xpv_len = (U32)arg; \
bstate->bs_pv.xpv_cur = (U32)arg - 1; \
New(666, bstate->bs_pv.pv, (U32)arg, char); \
bl_read(bstate->bs_fdata, bstate->bs_pv.pv, (U32)arg, 1); \
bstate->bs_pv.len = (U32)arg; \
bstate->bs_pv.cur = (U32)arg - 1; \
} else { \
bstate->bs_pv.xpv_pv = 0; \
bstate->bs_pv.xpv_len = 0; \
bstate->bs_pv.xpv_cur = 0; \
bstate->bs_pv.pv = 0; \
bstate->bs_pv.len = 0; \
bstate->bs_pv.cur = 0; \
} \
} STMT_END

Expand Down Expand Up @@ -164,7 +164,7 @@ static int bget_swab = 0;
arg = (char *) ary; \
} while (0)

#define BGET_pvcontents(arg) arg = bstate->bs_pv.xpv_pv
#define BGET_pvcontents(arg) arg = bstate->bs_pv.pv
/* read until \0. optionally limit the max stringsize for buffer overflow attempts */
#define BGET_strconst(arg, maxsize) STMT_START { \
char *end = NULL; \
Expand Down Expand Up @@ -237,7 +237,7 @@ static int bget_swab = 0;
} STMT_END
#define BSET_gv_fetchpvn_flags(sv, arg) STMT_START { \
int flags = (arg & 0xff80) >> 7; int type = arg & 0x7f; \
sv = (SV*)gv_fetchpv(savepv(bstate->bs_pv.xpv_pv), flags, type); \
sv = (SV*)gv_fetchpv(savepv(bstate->bs_pv.pv), flags, type); \
BSET_OBJ_STOREX(sv); \
} STMT_END

Expand All @@ -249,24 +249,24 @@ static int bget_swab = 0;

#define BSET_sv_magic(sv, arg) sv_magic(sv, Nullsv, arg, 0, 0)
/* mg_name was previously called mg_pv. we keep the new name and the old index */
#define BSET_mg_name(mg, arg) mg->mg_ptr = arg; mg->mg_len = bstate->bs_pv.xpv_cur
#define BSET_mg_name(mg, arg) mg->mg_ptr = arg; mg->mg_len = bstate->bs_pv.cur
#define BSET_mg_namex(mg, arg) \
(mg->mg_ptr = (char*)SvREFCNT_inc((SV*)arg), \
mg->mg_len = HEf_SVKEY)
#define BSET_xmg_stash(sv, arg) *(SV**)&(((XPVMG*)SvANY(sv))->xmg_stash) = (arg)
#define BSET_sv_upgrade(sv, arg) (void)SvUPGRADE(sv, arg)
#define BSET_xrv(sv, arg) SvRV_set(sv, arg)
#define BSET_xpv(sv) do { \
SvPV_set(sv, bstate->bs_pv.xpv_pv); \
SvCUR_set(sv, bstate->bs_pv.xpv_cur); \
SvLEN_set(sv, bstate->bs_pv.xpv_len); \
SvPV_set(sv, bstate->bs_pv.pv); \
SvCUR_set(sv, bstate->bs_pv.cur); \
SvLEN_set(sv, bstate->bs_pv.len); \
} while (0)
#if PERL_VERSION > 8
#define BSET_xpvshared(sv) do { \
U32 hash; \
PERL_HASH(hash, bstate->bs_pv.xpv_pv, bstate->bs_pv.xpv_cur); \
SvPV_set(sv, HEK_KEY(share_hek(bstate->bs_pv.xpv_pv,bstate->bs_pv.xpv_cur,hash))); \
SvCUR_set(sv, bstate->bs_pv.xpv_cur); \
PERL_HASH(hash, bstate->bs_pv.pv, bstate->bs_pv.cur); \
SvPV_set(sv, HEK_KEY(share_hek(bstate->bs_pv.pv,bstate->bs_pv.cur,hash))); \
SvCUR_set(sv, bstate->bs_pv.cur); \
SvLEN_set(sv, 0); \
} while (0)
#else
Expand All @@ -282,8 +282,8 @@ static int bget_swab = 0;
#define BSET_av_push(sv, arg) av_push((AV*)sv, arg)
#define BSET_av_pushx(sv, arg) (AvARRAY(sv)[++AvFILLp(sv)] = arg)
#define BSET_hv_store(sv, arg) \
hv_store((HV*)sv, bstate->bs_pv.xpv_pv, bstate->bs_pv.xpv_cur, arg, 0)
#define BSET_pv_free(pv) Safefree(pv.xpv_pv)
hv_store((HV*)sv, bstate->bs_pv.pv, bstate->bs_pv.cur, arg, 0)
#define BSET_pv_free(sv) Safefree(sv.pv)

#if PERL_VERSION > 13 || defined(CvGV_set)
#define BSET_xcv_gv(sv, arg) (CvGV_set((CV*)bstate->bs_sv, (GV*)arg))
Expand Down Expand Up @@ -350,7 +350,7 @@ static int bget_swab = 0;
STMT_START { \
SV* repointer; \
REGEXP* rx = arg \
? CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv_cur, cPMOPx(o)) \
? CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.cur, cPMOPx(o)) \
: Null(REGEXP*); \
if(av_len((AV*)PL_regex_pad[0]) > -1) { \
repointer = av_pop((AV*)PL_regex_pad[0]); \
Expand All @@ -374,7 +374,7 @@ static int bget_swab = 0;
#define BSET_pregcomp(o, arg) \
STMT_START { \
(((PMOP*)o)->op_pmregexp = (arg \
? CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv_cur, cPMOPx(o)) \
? CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.cur, cPMOPx(o)) \
: Null(REGEXP*))); \
} STMT_END
#endif
Expand All @@ -393,7 +393,7 @@ static int bget_swab = 0;
#if PERL_VERSION < 8
#define BSET_pregcomp(o, arg) \
((PMOP*)o)->op_pmregexp = arg \
? CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv_cur, ((PMOP*)o)) : 0
? CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.cur, ((PMOP*)o)) : 0
#endif


Expand Down
12 changes: 6 additions & 6 deletions bytecode.pl
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ package B::Asmdata;
print BYTERUN_C "\t\tDEBUG_v(Perl_deb(aTHX_ \"\t [%s %d]\\n\", PL_op_name[arg>>7], bstate->bs_ix));\n";
}
if ($fundtype eq 'PV') {
print BYTERUN_C "\t\tDEBUG_v(Perl_deb(aTHX_ \"\t BGET_PV(arg) => \\\"%s\\\"\\n\", bstate->bs_pv.xpv_pv));\n";
print BYTERUN_C "\t\tDEBUG_v(Perl_deb(aTHX_ \"\t BGET_PV(arg) => \\\"%s\\\"\\n\", bstate->bs_pv.pv));\n";
}
} else {
if ($unsupp and $holes{$insn_num}) {
Expand Down Expand Up @@ -607,9 +607,9 @@ package B::Asmdata;
#if PERL_VERSION > 8
struct byteloader_xpv {
char *xpv_pv;
int xpv_cur;
int xpv_len;
char *pv;
int cur;
int len;
};
#endif
Expand Down Expand Up @@ -865,7 +865,7 @@ =head1 AUTHOR
2 0 ldop PL_op opindex
3 0 stsv bstate->bs_sv U32 s
4 0 stop PL_op U32 s
5 6.001 stpv bstate->bs_pv.xpv_pv U32 x
5 6.001 stpv bstate->bs_pv.pv U32 x
6 0 ldspecsv bstate->bs_sv U8 x
7 8 ldspecsvx bstate->bs_sv U8 x
8 0 newsv bstate->bs_sv U8 x
Expand All @@ -875,7 +875,7 @@ =head1 AUTHOR
12 8 newopx PL_op U16 x
13 0 newopn PL_op U8 x
14 0 newpv none U32/PV
15 0 pv_cur bstate->bs_pv.xpv_cur STRLEN
15 0 pv_cur bstate->bs_pv.cur STRLEN
16 0 pv_free bstate->bs_pv none x
17 0 sv_upgrade bstate->bs_sv U8 x
18 0 sv_refcnt SvREFCNT(bstate->bs_sv) U32
Expand Down

0 comments on commit 8faee52

Please sign in to comment.