[ODBC-78] SQLGetData would not return SQL_NO_DATA for BLOB/TEXT columns if the buffer size is larger than the column data. Created: 2017-01-05  Updated: 2017-02-23  Resolved: 2017-02-23

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: None
Affects Version/s: 2.0.13
Fix Version/s: 2.0.14, 3.0.1

Type: Bug Priority: Major
Reporter: Yuriy Vasylchenko Assignee: Lawrin Novitsky
Resolution: Fixed Votes: 0
Labels: None


 Description   

The standard prescribes that SQLGetData() returns SQL_NO_DATA after retrieving the last portion of the column data.
Currently, the driver does not return that error nor returns it zero length in the indicator (StrLen_or_IndPtr) argument if the whole data can be fetched to the buffer at once.
The code relying upon the described above behavior may enter an unbound loop reading the (same) data indefinitely (until the process crashes).

--- ./ma_statement.c.ori        2016-12-05 18:34:45.956616000 -0800
+++ ./ma_statement.c    2016-12-14 18:25:59.371718000 -0800
@@ -2607,9 +2607,7 @@
       }
       if (StrLen_or_IndPtr)
         *StrLen_or_IndPtr= *Bind.length - Stmt->CharOffset[Offset];
-      /* Increase Offset only when the buffer wasn't fetched completely */
-      if (*Bind.length > (Bind.buffer_length - ZeroTerminated))
-        Stmt->CharOffset[Offset]+= MIN((unsigned long)BufferLength - ZeroTerminated, *Bind.length);
+      Stmt->CharOffset[Offset]+= MIN((unsigned long)BufferLength - ZeroTerminated, *Bind.length);
       if ((BufferLength - ZeroTerminated) && Stmt->Lengths[Offset] > Stmt->CharOffset[Offset])
       {
         MADB_SetError(&Stmt->Error, MADB_ERR_01004, NULL, 0);

The behavior triggered by the line ma_statement.c:2566 (Stmt->CharOffset[Offset]= 0;) is also questionable.



 Comments   
Comment by Lawrin Novitsky [ 2017-02-23 ]

The fix and the testcase have been pushed(only to odbc-2.0 so far) as rev f185440c17db1f80ac369b4dab54fdbe1487a882

Generated at Thu Feb 08 03:26:04 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.