Re: [BUGS] BUG #14023: pq odbc driver crashed while get data from boolean column

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: suzhengchun(at)gmail(dot)com
Cc: PostgreSQL mailing lists <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #14023: pq odbc driver crashed while get data from boolean column
Date: 2016-03-15 16:04:48
Message-ID: CAB7nPqT7FKechq=NxFTyMZM2JCQhdRjReYdQF9RdzYp748A8ew@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-odbc

On Tue, Mar 15, 2016 at 11:24 AM, <suzhengchun(at)gmail(dot)com> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 14023
> Logged by: suzhengchun
> Email address: suzhengchun(at)gmail(dot)com
> PostgreSQL version: 9.3.3
> Operating system: debian 8.2 x64
> Description:
>
> Hello, there:
> I met a problem recently with pq odbc driver, when there's a boolean
> column,
> the program just crashed.
>
> The database is in the attachment "test.db".
>
>
> My system/db is:
> szc(at)szc:20160315 15:49:28:qttest$ uname -a
> Linux szc 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04)
> x86_64 GNU/Linux
> szc(at)szc:20160315 17:24:35:qttest$ lsb_release -a
> No LSB modules are available.
> Distributor ID: Debian
> Description: Debian GNU/Linux 8.2 (jessie)
> Release: 8.2
> Codename: jessie
> szc(at)szc:20160315 17:24:38:qttest$ dpkg -l postgresql-9.4
> ....
> +++-==============-============-============-==================================
> ii postgresql-9.4 9.4.4-0+deb8 amd64 object-relational SQL database,
> ve
> szc(at)szc:20160315 17:24:54:qttest$
>
> I used unixodbc and qsql which from qt to do my work, their version are:
> szc(at)szc:20160315 17:29:23:qttest$ dpkg -l unixodbc
> ....
> ||/ Name Version Architecture Description
> +++-===============-============-============-===================================
> ii unixodbc 2.3.1-3 amd64 Basic ODBC tools
>
> Qt's version is 5.5.
> postgresql odbc version is 9.3.3.
> (In fact, 9.1.1 on my debian 7.8 has the same problem.)
>
>
> The output from my program:
> ------------------------------------------------------------------------------
> 5 fields in "person"
> Field: 0 , field: QSqlField("id", int, length: 10, required: no,
> generated:
> yes, typeID: 4, autoValue: false, readOnly: false)
> Field type: QVariant::int
> Field: 1 , field: QSqlField("name", QString, length: 40, required: no,
> generated: yes, autoValue: false, readOnly: false)
> Field type: QVariant::QString
> Field: 2 , field: QSqlField("sex", QString, length: 40, required: no,
> generated: yes, autoValue: false, readOnly: false)
> Field type: QVariant::QString
> Field: 3 , field: QSqlField("age", int, length: 10, required: no,
> generated: yes, typeID: 4, autoValue: false, readOnly: false)
> Field type: QVariant::int
> Field: 4 , field: QSqlField("open", QString, length: 5, required: no,
> generated: yes, typeID: 12, autoValue: false, readOnly: false)
> Field type: QVariant::QString
> size(): -1
> QVariant(int, 1)
> QVariant(QString, "aaa")
> QVariant(QString, "m")
> QVariant(int, 10)
> Segmentation fault (core dumped) 139
> szc(at)szc:20160315 16:52:38:qttest$
> ------------------------------------------------------------------------------
>
>
> The call stacks in the core is:
> Program terminated with signal SIGSEGV, Segmentation fault.
> #0 strlen () at ../sysdeps/x86_64/strlen.S:106
> 106 ../sysdeps/x86_64/strlen.S: No such file or directory.
> (gdb) bt
> #0 strlen () at ../sysdeps/x86_64/strlen.S:106
> #1 0x00007efbf71e39de in __GI___strdup (s=0x0) at strdup.c:41
> #2 0x00007efbf30377a4 in copy_and_convert_field (stmt=0x15294e0,
> field_type=16, atttypmod=-1, valuei=0x1518b00, fCType=-8, precision=-1,
> rgbValue=0x0, cbValueMax=0, pcbValue=0x7ffc2c305b68,
> pIndicator=0x7ffc2c305b68) at convert.c:1457
> #3 0x00007efbf305a819 in PGAPI_GetData (hstmt=0x15294e0, icol=4, fCType=-8,
> rgbValue=0x0, cbValueMax=0, pcbValue=0x7ffc2c305b68) at results.c:1076
> #4 0x00007efbf307c5f2 in SQLGetData (StatementHandle=0x15294e0,
> ColumnNumber=5, TargetType=-8, TargetValue=0x0, BufferLength=0,
> StrLen_or_Ind=0x7ffc2c305b68) at odbcapi.c:540
> #5 0x00007efbf3f0ffb0 in SQLGetData (statement_handle=0x14e7780,
> column_number=5, target_type=-8, target_value=0x0, buffer_length=0,
> strlen_or_ind=0x7ffc2c305b68) at SQLGetData.c:443
> #6 0x00007efbf417b513 in qGetStringData (hStmt=0x14e7780, column=4,
> colSize=6, unicode=true) at ../../../sql/drivers/odbc/qsql_odbc.cpp:383
> #7 0x00007efbf417f71e in QODBCResult::data (this=0x151d860, field=4) at
> ../../../sql/drivers/odbc/qsql_odbc.cpp:1219
> #8 0x00007efbf7daf55b in QSqlQuery::value (this=0x7ffc2c305f80, index=4) at
> kernel/qsqlquery.cpp:424
> #9 0x0000000000403bcc in OpenDatabase () at pq.cpp:129
> #10 0x000000000040272a in main (argc=1, argv=0x7ffc2c306908) at pq.cpp:22
> (gdb) f 2
> #2 0x00007efbf30377a4 in copy_and_convert_field (stmt=0x15294e0,
> field_type=16, atttypmod=-1, valuei=0x1518b00, fCType=-8, precision=-1,
> rgbValue=0x0, cbValueMax=0, pcbValue=0x7ffc2c305b68,
> pIndicator=0x7ffc2c305b68) at convert.c:1457
> 1457 char *str = strdup(rgbValueBindRow);
> (gdb) p rgbValueBindRow
> $1 = 0x0
> (gdb)
>
>
>
> I debugged this a lot, and finally found the problem, by default postgresql
> odbc treats boolean as char/string. That's showed in the call stack.
> After I added this to postgresql odbc dsn:
> BoolsAsChar = 0
> postgresql odbc driver will treat boolean values as SQL_BIT values, qt
> treats
> this as integer, then everything is fine.
> I don't care the type of the data, I just need to read it out, as default
> BoolsAsChar is enabled, it should work, but my program crashed, I think
> maybe
> it's a bug.
> Hoping this will help the others who meet the same problem.
>
> Thanks.

This is a bug related to the ODBC driver, so pgsql-odbc is more
adapted to report that.
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Teodor Sigaev 2016-03-15 17:01:39 Re: BUG #13440: unaccent does not remove all diacritics
Previous Message David G. Johnston 2016-03-15 15:13:31 Re: BUG #14020: row_number() over(partition by order by) - weird behavior

Browse pgsql-odbc by date

  From Date Subject
Next Message 苏正春 2016-03-16 11:26:53 Re: [BUGS] BUG #14023: pq odbc driver crashed while get data from boolean column
Previous Message Laerte Antonio de Almeida Giraldelli 2016-03-15 14:35:50 Re: Problems installing Postgresql ODBC driver 32bits on Redhat 6.5