List:Commits« Previous MessageNext Message »
From:bdegtyariov Date:September 3 2007 4:56pm
Subject:Connector/ODBC 3.51 commit: r735 - in trunk: . driver test
View as plain text  
Modified:
   trunk/ChangeLog
   trunk/driver/execute.c
   trunk/test/my_prepare.c
Log:
SQLSetParam() caused memory allocation errors due to driver manager's mapping of
deprecated functions (buffer length -1). (Bug#29871)

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-09-03 00:31:34 UTC (rev 734)
+++ trunk/ChangeLog	2007-09-03 16:56:00 UTC (rev 735)
@@ -5,6 +5,8 @@
   Bugs fixed:
   * SQLGetData() will now always return SQL_NO_DATA_FOUND on second call
     when no data left, even if requested size is 0. (Bug#30520)
+  * SQLSetParam() caused memory allocation errors due to driver manager's 
+    mapping of deprecated functions (buffer length -1). (Bug#29871)
 
 ----
 

Modified: trunk/driver/execute.c
===================================================================
--- trunk/driver/execute.c	2007-09-03 00:31:34 UTC (rev 734)
+++ trunk/driver/execute.c	2007-09-03 16:56:00 UTC (rev 735)
@@ -262,9 +262,14 @@
             else if ( param->ValueMax )
             {
 #ifndef strnlen
-                length=strlen(data);
-                if ( length > param->ValueMax )
-                    length = param->ValueMax;
+                length= strlen(data);
+                /* 
+                  For safety reasons add checking for SQL_SETPARAM_VALUE_MAX (-1)
+                  The negative length can be passed through the deprecated 
+                  function SQLSetParam 
+                */
+                if (length != SQL_SETPARAM_VALUE_MAX && length >
param->ValueMax)
+                    length= param->ValueMax;
 #else
                 length=strnlen(data,param->ValueMax);
 #endif

Modified: trunk/test/my_prepare.c
===================================================================
--- trunk/test/my_prepare.c	2007-09-03 00:31:34 UTC (rev 734)
+++ trunk/test/my_prepare.c	2007-09-03 16:56:00 UTC (rev 735)
@@ -1034,6 +1034,27 @@
 }
 
 
+DECLARE_TEST(t_bug29871)
+{
+  SQLCHAR *param= "1";
+
+  ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug29871");
+  ok_sql(hstmt, "CREATE TABLE t_bug29871 (a INT)");
+  
+  /* The bug is related to calling deprecated SQLSetParam */
+  ok_stmt(hstmt, SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_INTEGER, 10, 0, 
+                             param, 0));
+  ok_stmt(hstmt, SQLExecDirect(hstmt,"INSERT INTO t_bug29871 VALUES (?)",
+	                       SQL_NTS));
+  ok_stmt(hstmt, SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_INTEGER, 10, 0, 
+                             param, 0));
+  ok_stmt(hstmt, SQLExecDirect(hstmt,"SELECT * FROM t_bug29871 WHERE a=?",
+	                       SQL_NTS));
+  ok_sql(hstmt, "DROP TABLE t_bug29871");
+  return OK;
+}
+
+
 BEGIN_TESTS
   ADD_TEST(t_prep_basic)
   ADD_TEST(t_prep_buffer_length)
@@ -1048,6 +1069,7 @@
   ADD_TEST(tmysql_bindcol)
   ADD_TEST(tmysql_bindparam)
   ADD_TEST(t_acc_update)
+  ADD_TEST(t_bug29871)
 END_TESTS
 
 

Thread
Connector/ODBC 3.51 commit: r735 - in trunk: . driver testbdegtyariov3 Sep