From: Ludek Finstrle <luf@pzkagis.cz>
To: Hiroshi Inoue <inoue@tpf.co.jp>
Cc: pgsql-odbc@postgresql.org
Subject: Re: More strict bind param count checking
Date: Sat, 17 Dec 2005 21:50:47 +0100
Message-ID: <20051217205047.GA28826@soptik.pzkagis.cz> (raw)
In-Reply-To: <43A3301A.5070406@tpf.co.jp>
References: <20051214002452.GA9345@soptik.pzkagis.cz>
<43A0EE2D.8090702@tpf.co.jp>
<20051215051256.GA21336@soptik.pzkagis.cz>
<43A10178.5070107@tpf.co.jp>
<20051216172713.GB22756@soptik.pzkagis.cz>
<43A3301A.5070406@tpf.co.jp>
> Looks pretty good to me.
Very good.
> It's more safe to adjust the param_count in case of apdopts->allocated <
> param_count.
Thanks fot pointing it.
> Also it's safe to change the following code in PGAPI_ParamData.
>
> /* At least 1 data at execution parameter, so Fill in the token value */
> for (; i < apdopts->allocated; i++)
I implement it both. New patch attached.
I also change older test for param number from == to >= and
comment out some not used code.
Thank you very much again Hiroshi
Luf
P.S. Dave can I commit it if there it no negative answer?
Attachments:psqlodbc-limit_bind_param.diff (text/plain, 4.1K) download
diff -c psqlodbc.orig\convert.c psqlodbc\convert.c
*** psqlodbc.orig\convert.c Mon Dec 05 20:20:53 2005
--- psqlodbc\convert.c Sat Dec 17 22:18:46 2005
***************
*** 1860,1866 ****
}
if (marker_count > 0)
{
! if (ipdopts && (ipdopts->allocated == marker_count))
{
CVT_APPEND_CHAR(qb, '(');
for (i = 0; i < marker_count; i++)
--- 1860,1866 ----
}
if (marker_count > 0)
{
! if (ipdopts->allocated >= marker_count)
{
CVT_APPEND_CHAR(qb, '(');
for (i = 0; i < marker_count; i++)
diff -c psqlodbc.orig\execute.c psqlodbc\execute.c
*** psqlodbc.orig\execute.c Tue Dec 06 21:53:30 2005
--- psqlodbc\execute.c Sat Dec 17 22:40:54 2005
***************
*** 542,547 ****
--- 542,548 ----
UInt4 offset = apdopts->param_offset_ptr ? *apdopts->param_offset_ptr : 0;
Int4 bind_size = apdopts->param_bind_type;
Int4 current_row = stmt->exec_current_row < 0 ? 0 : stmt->exec_current_row;
+ SWORD param_count;
/*
* Increment the number of currently processed rows
***************
*** 549,555 ****
if (ipdopts->param_processed_ptr)
(*ipdopts->param_processed_ptr)++;
stmt->data_at_exec = -1;
! for (i = 0; i < apdopts->allocated; i++)
{
Int4 *pcVal = apdopts->parameters[i].used;
--- 550,565 ----
if (ipdopts->param_processed_ptr)
(*ipdopts->param_processed_ptr)++;
stmt->data_at_exec = -1;
! /* Check bind parameters count */
! if (SQL_SUCCESS != PGAPI_NumParams(stmt, ¶m_count))
! return SQL_ERROR;
! if (param_count > apdopts->allocated)
! {
! SC_set_error(stmt, STMT_COUNT_FIELD_INCORRECT, "The # of binded parameters < the # of parameter markers");
! SC_set_sqlstate(stmt, "07002");
! return SQL_ERROR;
! }
! for (i = 0; i < param_count; i++)
{
Int4 *pcVal = apdopts->parameters[i].used;
***************
*** 740,750 ****
}
/* In the middle of SQLParamData/SQLPutData, so cancel that. */
- - /* Free all previous data-at-exec buffers */- mylog("%s: Clearing parameters et al.\n", func);- - SC_free_params(stmt, STMT_FREE_PARAMS_ALL);
stmt->data_at_exec = -1;
stmt->current_exec_param = -1;
stmt->put_data = FALSE;
--- 750,755 ----
***************
*** 819,828 ****
--- 824,836 ----
CSTR func = "PGAPI_ParamData";
StatementClass *stmt = (StatementClass *) hstmt, *estmt;
APDFields *apdopts;
+ /* not used
IPDFields *ipdopts;
+ */
RETCODE retval;
int i;
ConnInfo *ci;
+ SWORD param_count;
mylog("%s: entering...\n", func);
***************
*** 844,850 ****
return SQL_ERROR;
}
! if (estmt->data_at_exec > apdopts->allocated)
{
SC_set_error(stmt, STMT_SEQUENCE_ERROR, "Too many execution-time parameters were present");
SC_log_error(func, "", stmt);
--- 852,868 ----
return SQL_ERROR;
}
! /* Check bind parameters count */
! if (SQL_SUCCESS != PGAPI_NumParams(stmt, ¶m_count))
! return SQL_ERROR;
! if (param_count > apdopts->allocated)
! {
! SC_set_error(stmt, STMT_COUNT_FIELD_INCORRECT, "The # of binded parameters < the # of parameter markers");
! SC_set_sqlstate(stmt, "07002");
! return SQL_ERROR;
! }
!
! if (estmt->data_at_exec > param_count)
{
SC_set_error(stmt, STMT_SEQUENCE_ERROR, "Too many execution-time parameters were present");
SC_log_error(func, "", stmt);
***************
*** 870,876 ****
--- 888,896 ----
}
/* Done, now copy the params and then execute the statement */
+ /* Luf - I don't see why this is called
ipdopts = SC_get_IPDF(estmt);
+ */
if (estmt->data_at_exec == 0)
{
BOOL exec_end;
***************
*** 892,898 ****
i = estmt->current_exec_param >= 0 ? estmt->current_exec_param + 1 : 0;
/* At least 1 data at execution parameter, so Fill in the token value */
! for (; i < apdopts->allocated; i++)
{
if (apdopts->parameters[i].data_at_exec)
{
--- 912,918 ----
i = estmt->current_exec_param >= 0 ? estmt->current_exec_param + 1 : 0;
/* At least 1 data at execution parameter, so Fill in the token value */
! for (; i < param_count; i++)
{
if (apdopts->parameters[i].data_at_exec)
{
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: luf@pzkagis.cz, inoue@tpf.co.jp
Subject: Re: More strict bind param count checking
In-Reply-To: <20051217205047.GA28826@soptik.pzkagis.cz>
References: <20051214002452.GA9345@soptik.pzkagis.cz> <43A0EE2D.8090702@tpf.co.jp> <20051215051256.GA21336@soptik.pzkagis.cz> <43A10178.5070107@tpf.co.jp> <20051216172713.GB22756@soptik.pzkagis.cz> <43A3301A.5070406@tpf.co.jp> <20051217205047.GA28826@soptik.pzkagis.cz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox