[BUGS] There is a case in which psqlodbc-09.03.0400 returns unterminated strings on Windows.

From: Naoya Anzai <nao-anzai(at)xc(dot)jp(dot)nec(dot)com>
To: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Cc: Akio Iwaasa <aki-iwaasa(at)vt(dot)jp(dot)nec(dot)com>
Subject: [BUGS] There is a case in which psqlodbc-09.03.0400 returns unterminated strings on Windows.
Date: 2015-09-16 02:20:26
Message-ID: 116262CF971C844FB6E793F8809B51C6EF245E@BPXM02GP.gisp.nec.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

Hi,

I found a bug which psqlODBC returns a string without null-terminated when SQLFetch is executed on Windows.
IMHO, it seems to be caused by differences of snprintf function between Windows and Linux.
You have changed sprintf into snprintf at psqlodbc-09.03.0400 release.
But snprintf on Windows(_snprintf) doesn't include a terminating character(\0) when a copy buffer length is less than an original buffer length; besides this returns -1.
Their behavior are different from that of Linux but psqlODBC does not currently make allowances for their differences.

As you can confirm this bug, I attached a program(test.cpp) which reproduces a bug.

This result is following.

----
Please Enter key...

SQLAllocHandle() OK
SQLAllocHandle() ok
SQLConnect ok
data-length=24
length=-1 //invalid length
2015-09-15 17:48:44.7300フフフフフフフフフフフフフフフフ・ //unterminated string
no data
---

To fix this behavior, copy_and_convert_field function and stime2timestamp function need to repair at least.

I tried to fix it up and attached a patch on this mail.
Could you confirm this?

Best Regards
---
Naoya Anzai
Engineering Department
NEC Solution Inovetors, Ltd.
E-Mail: nao-anzai(at)xc(dot)jp(dot)nec(dot)com
---

Attachment Content-Type Size
convert.bugfix.patch application/octet-stream 3.0 KB
test.cpp text/plain 2.3 KB

Responses

Browse pgsql-odbc by date

  From Date Subject
Next Message Heikki Linnakangas 2015-09-16 12:36:45 Re: Bug in the SQLGetDiagRec function of psqlodbc
Previous Message prabhu seeni 2015-09-11 05:18:37 Re: Reg:Postgres ODBC driver for 9.4.1 version