Skip to content

Commit 42e2b46

Browse files
committed
Merge fix for SQLPutData
2 parents b95ce1e + e39070f commit 42e2b46

File tree

6 files changed

+66
-7
lines changed

6 files changed

+66
-7
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dnl ------------------------------------------------------------
1111
# ------------------------------------------------------------
1212
# Initialization
1313
# ------------------------------------------------------------
14-
AC_INIT(FreeTDS, 1.5.6)
14+
AC_INIT(FreeTDS, 1.5.7)
1515
AC_CONFIG_SRCDIR(src/dblib/dblib.c)
1616
AC_PREREQ(2.53)
1717

include/freetds/iconv.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
#if HAVE_ICONV
2424
#include <iconv.h>
25+
/* avoid conflict with win-iconv library */
26+
#if defined(_LIBICONV_H) && defined(WINICONV_CONST)
27+
#undef libiconv_open
28+
#undef libiconv_close
29+
#undef libiconv
30+
#endif
2531
#else
2632
/* Define iconv_t for src/replacements/iconv.c. */
2733
#undef iconv_t

misc/appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ environment:
2323
# /E:ON and /V:ON options are not enabled in the batch script intepreter
2424
# See: http://stackoverflow.com/a/13751649/163740
2525
WITH_COMPILER: "cmd /E:ON /V:ON /C ..\\misc\\run_with_compiler.cmd"
26-
WIN_ICONV_VER: fixed
26+
WIN_ICONV_VER: master
2727

2828
matrix:
2929
- PLAT: Win64
@@ -80,14 +80,14 @@ install:
8080
- ren win-iconv-%WIN_ICONV_VER% iconv
8181
- mkdir iconv-build
8282
- cd iconv-build
83-
- "%WITH_COMPILER% cmake -G \"NMake Makefiles\" -DBUILD_STATIC=on -D BUILD_SHARED=off -DBUILD_EXECUTABLE=off -DBUILD_TEST=on -DCMAKE_BUILD_TYPE=Release ..\\iconv"
83+
- "%WITH_COMPILER% cmake -G \"NMake Makefiles\" -DWIN_ICONV_BUILD_STATIC=on -DWIN_ICONV_BUILD_SHARED=off -DWIN_ICONV_BUILD_EXECUTABLE=off -DWIN_ICONV_BUILD_TEST=on -DDISABLE_LOCALE_CHARSET=on -DCMAKE_BUILD_TYPE=Release ..\\iconv"
8484
- "%WITH_COMPILER% nmake"
8585
- win_iconv_test.exe
8686
- cd ..\iconv
8787
- mkdir include
8888
- mkdir lib
8989
- copy iconv.h include
90-
- copy ..\iconv-build\iconv.lib lib
90+
- copy ..\iconv-build\libiconv.lib lib\iconv.lib
9191
- cd ..
9292
# if cache doesn't have it, download it
9393
- >

src/odbc/prepare_query.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,10 @@ continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN St
364364
break;
365365
}
366366

367-
if (!blob && len > need_bytes)
368-
len = need_bytes;
367+
if (!blob && len > need_bytes) {
368+
odbc_errs_add(&stmt->errs, "22001", NULL);
369+
return SQL_ERROR;
370+
}
369371

370372
/* copy to destination */
371373
if (blob) {

src/odbc/sql2tds.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,16 @@ odbc_sql2tds(TDS_STMT * stmt, const struct _drecord *drec_ixd, const struct _dre
425425
len = SQL_LEN_DATA_AT_EXEC(sql_len);
426426
need_data = true;
427427

428-
/* dynamic length allowed only for BLOB fields */
428+
/* dynamic length allowed only for variable fields */
429429
switch (drec_ixd->sql_desc_concise_type) {
430+
case SQL_CHAR:
431+
case SQL_VARCHAR:
430432
case SQL_LONGVARCHAR:
433+
case SQL_WCHAR:
434+
case SQL_WVARCHAR:
431435
case SQL_WLONGVARCHAR:
436+
case SQL_BINARY:
437+
case SQL_VARBINARY:
432438
case SQL_LONGVARBINARY:
433439
break;
434440
default:

src/odbc/unittests/putdata.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
228270
int
229271
main(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

Comments
 (0)