Skip to content

Commit 9fb169d

Browse files
committed
Storable: don't call functions at wrong type
Avoid casting function pointers. Instead have all generic store_* helpers take an SV * and cast it to the correct type within the function. (Because calling a function through a function pointer of the wrong type has undefined behavior.) Should fix this ASan error: Storable.xs:4126:12: runtime error: call to function store_hash through pointer to incorrect function type 'int (*)(struct interpreter *, struct stcxt *, struct sv *)'
1 parent c3feabe commit 9fb169d

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

dist/Storable/Storable.xs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,27 +1356,27 @@ static SV *retrieve(pTHX_ stcxt_t *cxt, const char *cname);
13561356

13571357
static int store_ref(pTHX_ stcxt_t *cxt, SV *sv);
13581358
static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv);
1359-
static int store_array(pTHX_ stcxt_t *cxt, AV *av);
1360-
static int store_hash(pTHX_ stcxt_t *cxt, HV *hv);
1359+
static int store_array(pTHX_ stcxt_t *cxt, SV *av);
1360+
static int store_hash(pTHX_ stcxt_t *cxt, SV *hv);
13611361
static int store_tied(pTHX_ stcxt_t *cxt, SV *sv);
13621362
static int store_tied_item(pTHX_ stcxt_t *cxt, SV *sv);
1363-
static int store_code(pTHX_ stcxt_t *cxt, CV *cv);
1363+
static int store_code(pTHX_ stcxt_t *cxt, SV *cv);
13641364
static int store_regexp(pTHX_ stcxt_t *cxt, SV *sv);
13651365
static int store_other(pTHX_ stcxt_t *cxt, SV *sv);
13661366
static int store_blessed(pTHX_ stcxt_t *cxt, SV *sv, int type, HV *pkg);
13671367

13681368
typedef int (*sv_store_t)(pTHX_ stcxt_t *cxt, SV *sv);
13691369

13701370
static const sv_store_t sv_store[] = {
1371-
(sv_store_t)store_ref, /* svis_REF */
1372-
(sv_store_t)store_scalar, /* svis_SCALAR */
1373-
(sv_store_t)store_array, /* svis_ARRAY */
1374-
(sv_store_t)store_hash, /* svis_HASH */
1375-
(sv_store_t)store_tied, /* svis_TIED */
1376-
(sv_store_t)store_tied_item,/* svis_TIED_ITEM */
1377-
(sv_store_t)store_code, /* svis_CODE */
1378-
(sv_store_t)store_regexp, /* svis_REGEXP */
1379-
(sv_store_t)store_other, /* svis_OTHER */
1371+
store_ref, /* svis_REF */
1372+
store_scalar, /* svis_SCALAR */
1373+
store_array, /* svis_ARRAY */
1374+
store_hash, /* svis_HASH */
1375+
store_tied, /* svis_TIED */
1376+
store_tied_item,/* svis_TIED_ITEM */
1377+
store_code, /* svis_CODE */
1378+
store_regexp, /* svis_REGEXP */
1379+
store_other, /* svis_OTHER */
13801380
};
13811381

13821382
#define SV_STORE(x) (*sv_store[x])
@@ -2634,8 +2634,9 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
26342634
* Layout is SX_ARRAY <size> followed by each item, in increasing index order.
26352635
* Each item is stored as <object>.
26362636
*/
2637-
static int store_array(pTHX_ stcxt_t *cxt, AV *av)
2637+
static int store_array(pTHX_ stcxt_t *cxt, SV *xsv)
26382638
{
2639+
AV *av = (AV *)xsv;
26392640
SV **sav;
26402641
UV len = av_len(av) + 1;
26412642
UV i;
@@ -2760,8 +2761,9 @@ sortcmp(const void *a, const void *b)
27602761
* Currently the only hash flag is "restricted"
27612762
* Key flags are as for hv.h
27622763
*/
2763-
static int store_hash(pTHX_ stcxt_t *cxt, HV *hv)
2764+
static int store_hash(pTHX_ stcxt_t *cxt, SV *xsv)
27642765
{
2766+
HV *hv = (HV *)xsv;
27652767
dVAR;
27662768
UV len = (UV)HvTOTALKEYS(hv);
27672769
Size_t i;
@@ -3205,8 +3207,9 @@ static int store_lhash(pTHX_ stcxt_t *cxt, HV *hv, unsigned char hash_flags)
32053207
* Layout is SX_CODE <length> followed by a scalar containing the perl
32063208
* source code of the code reference.
32073209
*/
3208-
static int store_code(pTHX_ stcxt_t *cxt, CV *cv)
3210+
static int store_code(pTHX_ stcxt_t *cxt, SV *xsv)
32093211
{
3212+
CV *cv = (CV *)xsv;
32103213
dSP;
32113214
STRLEN len;
32123215
STRLEN count, reallen;

dist/Storable/lib/Storable.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ our @EXPORT_OK = qw(
3030
our ($canonical, $forgive_me);
3131

3232
BEGIN {
33-
our $VERSION = '3.37';
33+
our $VERSION = '3.38';
3434
}
3535

3636
our $recursion_limit;

0 commit comments

Comments
 (0)