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

From Naoya Anzai
Subject [BUGS] There is a case in which psqlodbc-09.03.0400 returns unterminated strings on Windows.
Date
Msg-id 116262CF971C844FB6E793F8809B51C6EF245E@BPXM02GP.gisp.nec.co.jp
Whole thread Raw
Responses Re: [BUGS] There is a case in which psqlodbc-09.03.0400 returns unterminated strings on Windows.  (Heikki Linnakangas <hlinnaka@iki.fi>)
List 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
anoriginal 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@xc.jp.nec.com
---



Attachment

pgsql-odbc by date:

Previous
From: prabhu seeni
Date:
Subject: Re: Reg:Postgres ODBC driver for 9.4.1 version
Next
From: Heikki Linnakangas
Date:
Subject: Re: Bug in the SQLGetDiagRec function of psqlodbc