Received: from localhost (pluto.hub.org [200.46.204.4]) by postgresql.org (Postfix) with ESMTP id 439069FA372 for ; Mon, 6 Nov 2006 21:10:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.4]) (amavisd-new, port 10024) with ESMTP id 29963-04 for ; Mon, 6 Nov 2006 21:10:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sd.tpf.co.jp (sd.tpf.co.jp [210.161.239.34]) by postgresql.org (Postfix) with SMTP id D74219F946B for ; Mon, 6 Nov 2006 21:10:21 -0400 (AST) Received: (qmail 17779 invoked from network); 7 Nov 2006 10:10:18 +0900 Received: from unknown (HELO ?100.0.32.170?) (100.0.32.170) by sd2.tpf-fw-c.co.jp with SMTP; 7 Nov 2006 10:10:18 +0900 Message-ID: <454FDCFA.2030108@tpf.co.jp> Date: Tue, 07 Nov 2006 10:10:18 +0900 From: Hiroshi Inoue User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: Peter Eisentraut CC: pgsql-odbc@postgresql.org, 396218-forwarded@bugs.debian.org Subject: Re: Fwd: Bug#396218: bind.c: bad handling of SQL_LEN_DATA_AT_EXEC References: <200611062046.16284.peter_e@gmx.net> In-Reply-To: <200611062046.16284.peter_e@gmx.net> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/10 X-Sequence-Number: 8392 Peter Eisentraut wrote: > A Debian bug report ... Enrico is right at the point that the evaluation of *pcbValue here is dangerous and has no meaning. So in my version I already invalidated the code(#ifdef NOT_USED). Unfortunately his patch seems to have no meaning. regards, Hiroshi Inoue > ---------- Forwarded Message ---------- > > Subject: Bug#396218: bind.c: bad handling of SQL_LEN_DATA_AT_EXEC breaks > passing char buffer length at SQLExec time > Date: Monday 30 October 2006 17:00 > From: Enrico Zini > To: Debian Bug Tracking System > > Package: odbc-postgresql > Version: 1:08.01.0200-2 > Severity: normal > Tags: patch > > Hello, > > thanks for maintaining odbc-postgresql. > > In my package dballe (apt-get source dballe) I optimize some frequent > query by preparing the ODBC statement for them and binding the input > parameters, so that when I need the results I can just set some of the > bound variables and call SQLExecute. > > This is an example of such variable bind code: > > SQLBindParameter(res->istm, 3, SQL_PARAM_INPUT, SQL_C_CHAR, > SQL_CHAR, 0, 0, &(res->value), 0, &(res->value_ind)); > > Note that I'm passing a pointer to the variable that will hold the > string length as the last parameter, instead of using SQL_NTS. > > Now, this call eventually ends up in this code, found at bind.c:118: > > /* Data at exec macro only valid for C char/binary data */ > if (pcbValue && (*pcbValue == SQL_DATA_AT_EXEC || > *pcbValue <= > SQL_LEN_DATA_AT_EXEC_OFFSET)) apdopts->parameters[ipar].data_at_exec = > TRUE; > else > apdopts->parameters[ipar].data_at_exec = FALSE; > > This code tries to dereferenciate the (still uninitialised) pointer I > pass it ( that &(res->value_ind) ) and fails. The test should be like > this instead: > > /* Data at exec macro only valid for C char/binary data */ > if (pcbValue && (pcbValue == SQL_DATA_AT_EXEC || > pcbValue <= > SQL_LEN_DATA_AT_EXEC_OFFSET)) apdopts->parameters[ipar].data_at_exec = > TRUE; > else > apdopts->parameters[ipar].data_at_exec = FALSE; > > ODBC has this dirty habit of passing negative integers as special > values for pointers, and SQL_DATA_AT_EXEC is one of those: > > from /usr/include/sql.h:29: > > #define SQL_NULL_DATA (-1) > #define SQL_DATA_AT_EXEC (-2) > > same goes for the handling of SQL_LEN_DATA_AT_EXEC_OFFSET. > > I regret I can't test the patch with code that uses SQL_DATA_AT_EXEC, > because that is an ODBC feature that I do not use. However, with the > patch my SQLBindParameter above works fine. > > > Ciao, > > Enrico