json_parse()/pgtypes: Fix accidental creation of read-only array/hash values
&PL_sv_* shouldn't be used when constructing arrays or hashes in this context.
This commit is contained in:
parent
817fa600d0
commit
d0c5397e2d
8 changed files with 45 additions and 11 deletions
|
|
@ -236,12 +236,12 @@ static SV *fujson_parse(pTHX_ fujson_parse_ctx *ctx) {
|
|||
if (ctx->end - ctx->buf < 4) return NULL;
|
||||
if (memcmp(ctx->buf, "true", 4) != 0) return NULL;
|
||||
ctx->buf += 4;
|
||||
return &PL_sv_yes;
|
||||
return newSV_true();
|
||||
case 'f':
|
||||
if (ctx->end - ctx->buf < 5) return NULL;
|
||||
if (memcmp(ctx->buf, "false", 5) != 0) return NULL;
|
||||
ctx->buf += 5;
|
||||
return &PL_sv_no;
|
||||
return newSV_false();
|
||||
case 'n':
|
||||
if (ctx->end - ctx->buf < 4) return NULL;
|
||||
if (memcmp(ctx->buf, "null", 4) != 0) return NULL;
|
||||
|
|
|
|||
2
c/pgst.c
2
c/pgst.c
|
|
@ -463,7 +463,7 @@ static SV *fupg_st_kvv(pTHX_ fupg_st *st) {
|
|||
SAVETMPS;
|
||||
SV *key = sv_2mortal(fupg_st_getval(aTHX_ st, i, 0));
|
||||
if (hv_exists_ent(hv, key, 0)) fu_confess("Key '%s' is duplicated in $st->kvv() query results", SvPV_nolen(key));
|
||||
hv_store_ent(hv, key, st->nfields == 1 ? &PL_sv_yes : fupg_st_getval(aTHX_ st, i, 1), 0);
|
||||
hv_store_ent(hv, key, st->nfields == 1 ? newSV_true() : fupg_st_getval(aTHX_ st, i, 1), 0);
|
||||
FREETMPS;
|
||||
}
|
||||
return sv;
|
||||
|
|
|
|||
12
c/pgtypes.c
12
c/pgtypes.c
|
|
@ -78,7 +78,7 @@ SENDFN(domain) { (void)out; SERR("domain type should not be handled by this func
|
|||
|
||||
RECVFN(bool) {
|
||||
RLEN(1);
|
||||
return *buf ? &PL_sv_yes : &PL_sv_no;
|
||||
return *buf ? newSV_true() : newSV_false();
|
||||
}
|
||||
|
||||
SENDFN(bool) {
|
||||
|
|
@ -89,7 +89,7 @@ SENDFN(bool) {
|
|||
RECVFN(void) {
|
||||
RLEN(0);
|
||||
(void)buf;
|
||||
return &PL_sv_undef;
|
||||
return newSV(0);
|
||||
}
|
||||
|
||||
SENDFN(void) {
|
||||
|
|
@ -269,7 +269,7 @@ SENDFN(jsonpath) {
|
|||
#define ARRAY_MAXDIM 100
|
||||
|
||||
static SV *fupg_recv_array_elem(pTHX_ const fupg_tio *elem, const char *header, U32 dim, U32 ndim, const char **buf, const char *end) {
|
||||
SV *r = &PL_sv_undef;
|
||||
SV *r;
|
||||
if (dim == ndim) {
|
||||
if (end - *buf < 4) fu_confess("Invalid array format");
|
||||
I32 len = fu_frombeI(32, *buf);
|
||||
|
|
@ -279,6 +279,8 @@ static SV *fupg_recv_array_elem(pTHX_ const fupg_tio *elem, const char *header,
|
|||
if (len >= 0) {
|
||||
r = elem->recv(aTHX_ elem, *buf, len);
|
||||
*buf += len;
|
||||
} else {
|
||||
r = newSV(0);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
@ -403,12 +405,14 @@ RECVFN(record) {
|
|||
if (oid != ctx->record.info->attrs[i].oid)
|
||||
RERR("expected field %d to be of type %u but got %u", i, ctx->record.info->attrs[i].oid, oid);
|
||||
I32 vlen = fu_frombeI(32, buf+4);
|
||||
SV *r = &PL_sv_undef;
|
||||
SV *r;
|
||||
buf += 8; len -= 8;
|
||||
if (vlen > len) RERR("input data too short");
|
||||
if (vlen >= 0) {
|
||||
r = ctx->record.tio[i].recv(aTHX_ ctx->record.tio+i, buf, vlen);
|
||||
buf += vlen; len -= vlen;
|
||||
} else {
|
||||
r = newSV(0);
|
||||
}
|
||||
hv_store(hv, ctx->record.info->attrs[i].name.n, -strlen(ctx->record.info->attrs[i].name.n), r, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue