Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T7PJo-0002NY-1E for pgsql-odbc@postgresql.org; Fri, 31 Aug 2012 11:23:20 +0000 Received: from [87.118.86.135] (helo=km31432.keymachine.de) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T7PJh-0002Nw-Ph for pgsql-odbc@postgresql.org; Fri, 31 Aug 2012 11:23:19 +0000 Received: from localhost.localdomain (unknown [87.242.12.45]) by km31432.keymachine.de (Postfix) with ESMTPSA id 23F503900523; Fri, 31 Aug 2012 11:21:41 +0000 (UTC) Message-ID: <50409E40.10803@cybertec.at> Date: Fri, 31 Aug 2012 13:21:36 +0200 From: Boszormenyi Zoltan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0 MIME-Version: 1.0 To: Hiroshi Saito , pgsql-odbc@postgresql.org CC: =?ISO-8859-2?Q?Hans-J=FCrgen_Sch=F6nig?= Subject: Error reporting goes into an infinite loop when compiled --with-odbcver=0x0250 Content-Type: multipart/mixed; boundary="------------000403050607080409080003" X-Host-Lookup-Failed: Reverse DNS lookup failed for 87.118.86.135 (deferred) X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201208/30 X-Sequence-Number: 10939 This is a multi-part message in MIME format. --------------000403050607080409080003 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: quoted-printable Hi, we had to recently test psqlODBC with an older application which doesn't expect ODBC 3.x. The problem is that the client locks up as soon as it encounters an error of any kind, like restarting the server from under the client or simply executing a bad query. After debugging the problem and reading the code of both unixODBC 2.3.1 and psqlODBC (version 09.00.0310 and 09.01.0200), I discovered that the DriverManager calls the driver's SQLError() and SQLGetDiagRec() in a loop and expects it to return the error message in pieces and when there is nothing left to return, these driver methods must return some SQL error instead of SQL_SUCCESS[_WITH_INFO]. SQLGetDiagRec() does this properly because the DriverManager keeps track of the pieces via the RecNumber argument but SQLError() calls PGAPI_StmtError() with RecNumber =3D=3D -1 every time. Instead, it uses the internal error structure to keep track of the string left to return. SQLError() calls PGAPI_StmtError() with flag =3D PODBC_ALLOW_PARTIAL_EXTRACT | PODBC_ERROR_CLEAR which means that ER_ReturnError() may free the error structure. The interaction between the looping and the freeing of the error structure is buggy, the error makes it go into an infinite loop. The attached patch fixes this problem. Though, I am not sure about whether the (stapos > msglen) and (error->errorpos >=3D msglen) checks are redundant or not. Best regards, Zolt=E1n B=F6sz=F6rm=E9nyi --=20 ---------------------------------- Zolt=E1n B=F6sz=F6rm=E9nyi Cybertec Sch=F6nig & Sch=F6nig GmbH Gr=F6hrm=FChlgasse 26 A-2700 Wiener Neustadt, Austria Web: http://www.postgresql-support.de http://www.postgresql.at/ --------------000403050607080409080003 Content-Type: text/x-patch; name="psqlodbc-odbc2.5-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="psqlodbc-odbc2.5-fix.patch" diff -durpN psqlodbc-09.01.0200.orig/environ.c psqlodbc-09.01.0200/environ.c --- psqlodbc-09.01.0200.orig/environ.c 2010-08-21 08:29:19.000000000 +0200 +++ psqlodbc-09.01.0200/environ.c 2012-08-31 12:50:53.877651778 +0200 @@ -226,7 +226,17 @@ ER_ReturnError(PG_ErrorInfo **pgerror, } stapos = (RecNumber - 1) * error->recsize; if (stapos > msglen) + { + if (clear_str) + { + if (error->errorpos >= msglen) + { + ER_Destructor(error); + *pgerror = NULL; + } + } return SQL_NO_DATA_FOUND; + } pcblen = wrtlen = msglen - stapos; if (pcblen > error->recsize) pcblen = error->recsize; @@ -259,15 +269,9 @@ ER_ReturnError(PG_ErrorInfo **pgerror, strncpy_null(szSqlState, error->sqlstate, 6); mylog(" szSqlState = '%s',len=%d, szError='%s'\n", szSqlState, pcblen, szErrorMsg); - if (clear_str) - { - error->errorpos = stapos + wrtlen; - if (error->errorpos >= msglen) - { - ER_Destructor(error); - *pgerror = NULL; - } - } + + error->errorpos = stapos + wrtlen; + if (wrtlen == 0) return SQL_SUCCESS_WITH_INFO; else --------------000403050607080409080003--