Skip to content

Commit

Permalink
Use hv_fetchs() instead of hv_fetch() with literal key and manual length
Browse files Browse the repository at this point in the history
This avoids potential length miscounting bugs. hv_fetchs() was
introduced in Perl 5.10, but is covered by dbipport.h, which is
included by DBIXS.h.
  • Loading branch information
ilmari committed Sep 3, 2024
1 parent e78101f commit a59d964
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Pg.xs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ quote(dbh, to_quote_sv, type_sv=Nullsv)
/* Currently the type argument must be a hashref, so throw an exception if not */
if (!SvROK(type_sv) || SvTYPE(SvRV(type_sv)) != SVt_PVHV)
croak("Second argument to quote must be a hashref");
if ((svp = hv_fetch((HV*)SvRV(type_sv),"pg_type", 7, 0)) != NULL) {
if ((svp = hv_fetchs((HV*)SvRV(type_sv),"pg_type", 0)) != NULL) {
type_info = pg_type_data(SvIV(*svp));
}
else if ((svp = hv_fetch((HV*)SvRV(type_sv),"type", 4, 0)) != NULL) {
else if ((svp = hv_fetchs((HV*)SvRV(type_sv),"type", 0)) != NULL) {
type_info = sql_type_data(SvIV(*svp));
}
else {
Expand Down Expand Up @@ -383,7 +383,7 @@ void do(dbh, statement_sv, attr=Nullsv, ...)

if (attr && SvROK(attr) && SvTYPE(SvRV(attr)) == SVt_PVHV) {
SV **svp;
if ((svp = hv_fetch((HV*)SvRV(attr),"pg_async", 8, 0)) != NULL) {
if ((svp = hv_fetchs((HV*)SvRV(attr),"pg_async", 0)) != NULL) {
asyncflag = (int)SvIV(*svp);
}
}
Expand Down
14 changes: 7 additions & 7 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,21 +1658,21 @@ int dbd_st_prepare_sv (SV * sth, imp_sth_t * imp_sth, SV * statement_sv, SV * at

/* Parse and set any attributes passed in */
if (attribs) {
if ((svp = hv_fetch((HV*)SvRV(attribs),"pg_server_prepare", 17, 0)) != NULL) {
if ((svp = hv_fetchs((HV*)SvRV(attribs),"pg_server_prepare", 0)) != NULL) {
imp_sth->server_prepare = SvTRUE(*svp) ? DBDPG_TRUE : DBDPG_FALSE;
}
if ((svp = hv_fetch((HV*)SvRV(attribs),"pg_direct", 9, 0)) != NULL)
if ((svp = hv_fetchs((HV*)SvRV(attribs),"pg_direct", 0)) != NULL)
imp_sth->direct = 0==SvIV(*svp) ? DBDPG_FALSE : DBDPG_TRUE;
else if ((svp = hv_fetch((HV*)SvRV(attribs),"pg_prepare_now", 14, 0)) != NULL) {
else if ((svp = hv_fetchs((HV*)SvRV(attribs),"pg_prepare_now", 0)) != NULL) {
imp_sth->prepare_now = 0==SvIV(*svp) ? DBDPG_FALSE : DBDPG_TRUE;
}
if ((svp = hv_fetch((HV*)SvRV(attribs),"pg_placeholder_dollaronly", 25, 0)) != NULL) {
if ((svp = hv_fetchs((HV*)SvRV(attribs),"pg_placeholder_dollaronly", 0)) != NULL) {
imp_sth->dollaronly = SvTRUE(*svp) ? DBDPG_TRUE : DBDPG_FALSE;
}
if ((svp = hv_fetch((HV*)SvRV(attribs),"pg_placeholder_nocolons", 23, 0)) != NULL) {
if ((svp = hv_fetchs((HV*)SvRV(attribs),"pg_placeholder_nocolons", 0)) != NULL) {
imp_sth->nocolons = SvTRUE(*svp) ? DBDPG_TRUE : DBDPG_FALSE;
}
if ((svp = hv_fetch((HV*)SvRV(attribs),"pg_async", 8, 0)) != NULL) {
if ((svp = hv_fetchs((HV*)SvRV(attribs),"pg_async", 0)) != NULL) {
imp_sth->async_flag = (int)SvIV(*svp);
}
}
Expand Down Expand Up @@ -2565,7 +2565,7 @@ int dbd_bind_ph (SV * sth, imp_sth_t * imp_sth, SV * ph_name, SV * newvalue, IV

/* Check for a pg_type argument (sql_type already handled) */
if (attribs) {
if((svp = hv_fetch((HV*)SvRV(attribs),"pg_type", 7, 0)) != NULL)
if((svp = hv_fetchs((HV*)SvRV(attribs),"pg_type", 0)) != NULL)
pg_type = (int)SvIV(*svp);
}

Expand Down

0 comments on commit a59d964

Please sign in to comment.