@@ -225,14 +225,59 @@ Test(int direct)
225225 /* TODO test cancel inside SQLExecute */
226226}
227227
228+ static void
229+ TestOverflow (void )
230+ {
231+ SQLLEN ind ;
232+ SQLPOINTER ptr ;
233+
234+ odbc_command_with_result (odbc_stmt , "DROP TABLE #putdata" );
235+ odbc_command ("CREATE TABLE #putdata (c VARCHAR(255) NULL)" );
236+
237+ CHKBindParameter (1 , SQL_PARAM_INPUT , SQL_C_CHAR , SQL_VARCHAR , 30 , 0 , (SQLPOINTER ) 123 , 0 , & ind , "S" );
238+ /* length required */
239+ ind = SQL_DATA_AT_EXEC ;
240+
241+ CHKExecDirect (T ("INSERT INTO #putdata(c) VALUES(?)" ), SQL_NTS , "Ne" );
242+
243+ ptr = ((char * )0 ) + 0xdeadbeef ;
244+ CHKParamData (& ptr , "Ne" );
245+ if (ptr != (SQLPOINTER ) 123 ) {
246+ fprintf (stderr , "%p\n" , ptr );
247+ ODBC_REPORT_ERROR ("Wrong pointer from SQLParamData" );
248+ }
249+ CHKPutData ((void * )test_text , 25 , "S" );
250+ CHKPutData ((void * )test_text , 6 , "E" );
251+ odbc_read_error ();
252+ if (strcmp (odbc_sqlstate , "22001" ) != 0 ) {
253+ fprintf (stderr , "Unexpected sql state %s returned\n" , odbc_sqlstate );
254+ odbc_disconnect ();
255+ exit (1 );
256+ }
257+
258+ /* This error is reported by the Driver Manager */
259+ #ifndef TDS_NO_DM
260+ CHKParamData (& ptr , "E" );
261+ odbc_read_error ();
262+ if (strcmp (odbc_sqlstate , "HY010" ) != 0 ) {
263+ fprintf (stderr , "Unexpected sql state %s returned\n" , odbc_sqlstate );
264+ odbc_disconnect ();
265+ exit (1 );
266+ }
267+ #endif
268+ }
269+
228270int
229271main (void )
230272{
273+ odbc_use_version3 = 1 ;
231274 odbc_connect ();
232275
233276 Test (0 );
234277 Test (1 );
235278
279+ TestOverflow ();
280+
236281 odbc_disconnect ();
237282
238283 printf ("Done.\n" );
0 commit comments