X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 75BF49DC8AA for ; Tue, 13 Dec 2005 20:24:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78466-07-8 for ; Tue, 13 Dec 2005 20:24:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.pzkagis.cz (gis6.netbox.cz [83.240.30.214]) by postgresql.org (Postfix) with ESMTP id 5BF1E9DC8DF for ; Tue, 13 Dec 2005 20:24:48 -0400 (AST) Received: (from luf@localhost) by smtp.pzkagis.cz (8.11.6/8.11.6) id jBE0Oqn09369 for pgsql-odbc@postgresql.org; Wed, 14 Dec 2005 01:24:52 +0100 Date: Wed, 14 Dec 2005 01:24:52 +0100 From: Ludek Finstrle To: pgsql-odbc@postgresql.org Subject: More strict bind param count checking Message-ID: <20051214002452.GA9345@soptik.pzkagis.cz> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="AhhlLboLdkugWU4S" Content-Disposition: inline User-Agent: Mutt/1.4i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/163 X-Sequence-Number: 6642 --AhhlLboLdkugWU4S Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, I attach patch for more strict bind parameters count checking. It could avoid some bad behaviour (driver doesn't fail in some situations). Please review and comment Luf --AhhlLboLdkugWU4S Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="psqlodbc-strict_bind_param_count.diff" diff -c psqlodbc.orig\convert.c psqlodbc\convert.c *** psqlodbc.orig\convert.c Mon Dec 05 20:20:53 2005 --- psqlodbc\convert.c Wed Dec 14 00:58:24 2005 *************** *** 1858,1866 **** QB_Destructor(qb); return SQL_ERROR; } ! if (marker_count > 0) { ! if (ipdopts && (ipdopts->allocated == marker_count)) { CVT_APPEND_CHAR(qb, '('); for (i = 0; i < marker_count; i++) --- 1858,1866 ---- QB_Destructor(qb); return SQL_ERROR; } ! if (ipdopts->allocated == marker_count) { ! if (marker_count > 0) { CVT_APPEND_CHAR(qb, '('); for (i = 0; i < marker_count; i++) *************** *** 1871,1883 **** } CVT_APPEND_CHAR(qb, ')'); } ! else ! { ! SC_set_error(stmt, STMT_COUNT_FIELD_INCORRECT, "The # of binded parameters < the # of parameter markers"); ! SC_set_sqlstate(stmt, "07002"); ! QB_Destructor(qb); ! return SQL_ERROR; ! } } CVT_APPEND_STR(qb, " as "); for (qp->opos = 0; qp->opos < qp->stmt_len; qp->opos++) --- 1871,1884 ---- } CVT_APPEND_CHAR(qb, ')'); } ! } ! else ! { ! CC_clear_error(stmt->hdbc); ! SC_set_error(stmt, STMT_COUNT_FIELD_INCORRECT, "The # of binded parameters < the # of parameter markers"); ! SC_set_sqlstate(stmt, "07002"); ! QB_Destructor(qb); ! return SQL_ERROR; } CVT_APPEND_STR(qb, " as "); for (qp->opos = 0; qp->opos < qp->stmt_len; qp->opos++) diff -c psqlodbc.orig\execute.c psqlodbc\execute.c *** psqlodbc.orig\execute.c Tue Dec 06 21:53:30 2005 --- psqlodbc\execute.c Wed Dec 14 01:18:40 2005 *************** *** 136,141 **** --- 136,143 ---- StatementClass *stmt = (StatementClass *) hstmt; RETCODE result; CSTR func = "PGAPI_ExecDirect"; + IPDFields *ipdopts; + SWORD marker_count; mylog("%s: entering...\n", func); *************** *** 156,161 **** --- 158,175 ---- mylog("**** %s: hstmt=%u, statement='%s'\n", func, hstmt, stmt->statement); + /* Check bind parameters count */ + if (SQL_SUCCESS != PGAPI_NumParams(stmt, &marker_count)) + return SQL_ERROR; + ipdopts = SC_get_IPDF(stmt); + if (ipdopts->allocated != marker_count) + { + CC_clear_error(stmt->hdbc); + 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 an SQLPrepare was performed prior to this, but was left in the * premature state because an error occurred prior to SQLExecute then *************** *** 196,206 **** --- 210,234 ---- APDFields *apdopts; IPDFields *ipdopts; BOOL prepare_before_exec = FALSE; + SWORD marker_count; + *exec_end = FALSE; conn = SC_get_conn(stmt); mylog("%s: copying statement params: trans_status=%d, len=%d, stmt='%s'\n", func, conn->transact_status, strlen(stmt->statement), stmt->statement); + /* Check bind parameters count */ + if (SQL_SUCCESS != PGAPI_NumParams(stmt, &marker_count)) + return SQL_ERROR; + ipdopts = SC_get_IPDF(stmt); + if (ipdopts->allocated != marker_count) + { + CC_clear_error(stmt->hdbc); + SC_set_error(stmt, STMT_COUNT_FIELD_INCORRECT, "The # of binded parameters < the # of parameter markers"); + SC_set_sqlstate(stmt, "07002"); + return SQL_ERROR; + } + /* save the cursor's info before the execution */ cursor_type = stmt->options.cursor_type; scroll_concurrency = stmt->options.scroll_concurrency; --AhhlLboLdkugWU4S--