pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Boszormenyi Zoltan <zb@cybertec.at>
To: Hiroshi Saito <hiroshi@winpg.jp>
To: pgsql-odbc@postgresql.org
Cc: Hans-Jürgen Schönig <hs@cybertec.at>
Subject: Error reporting goes into an infinite loop when compiled --with-odbcver=0x0250
Date: Fri, 31 Aug 2012 13:21:36 +0200
Message-ID: <50409E40.10803@cybertec.at> (raw)

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 == -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 = 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 >= msglen)
checks are redundant or not.

Best regards,
Zoltán Böszörményi

-- 
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
      http://www.postgresql.at/

Attachments:

psqlodbc-odbc2.5-fix.patch (text/x-patch, 1.0K) download 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

view thread (6+ messages)  latest in thread

Message-ID: <50409E40.10803@cybertec.at>
Permalink:  ../50409E40.10803@cybertec.at/
Also on:    postgresql.org/message-id/50409E40.10803@cybertec.at

 ·  · 

reply

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: zb@cybertec.at, hiroshi@winpg.jp, hs@cybertec.at
  Subject: Re: Error reporting goes into an infinite loop when compiled --with-odbcver=0x0250
  In-Reply-To: <50409E40.10803@cybertec.at>
  References: <50409E40.10803@cybertec.at>

* 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