psqlodbc.git / summary / log / commit / refs

commit    7f4e81ca7ac0cff95a107bd01f2bd701f491fc6a
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Fri Sep 05 14:55:22 2014 +0000

    Fix buffer overflow in SQLGetData.
    
    If a PostgreSQL timestamp column is fetched using SQLGetData, into a
    SQL_C_CHAR output variable, with size of 20-22 bytes, the driver might
    overrun the buffer by a few bytes with unusual timestamp values, with
    year < 0 or > 10000.
    
    While at it, fix the truncation behavior for date/time/timestamp values
    so that if the output buffer is too small, we still write what fits and
    truncate, instead of writing nothing. This is something that one might
    do on purpose, e.g. if you only want to fetch the year part of a date,
    you might call SQLGetData() on a date column, with only 4 bytes long
    output buffer. (although we haven't heard any complaints from the field).
    
    Also, if the output buffer is of type SQL_C_WCHAR, but the buffer length
    is odd, and we have to truncate, we didn't NULL-terminate the string.
    Using an odd-sized buffer with SQL_C_WCHAR is a pretty unlikely thing to
    do, but nevertheless I think this is more correct behavior.
    
    Add test cases for the bugs fixed.


convert.c | 135 +++++++++++++++--------------- test/expected/result-conversions.out | 24 ++++-- test/src/result-conversions-test.c | 155 ++++++++++++++++++++++++++++++++--- 3 files changed, 232 insertions(+), 82 deletions(-) diff --git a/convert.c b/convert.c index e7cc4d15..5003a3e5 100644 --- a/convert.c +++ b/convert.c @@ -343,8 +343,9 @@ timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL *bZone, int *zone) return TRUE; } -static BOOL -stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision) +static int +stime2timestamp(const SIMPLE_TIME *st, char *str, size_t bufsize, BOOL bZone, + int precision) { char precstr[16], zonestr[16]; @@ -353,17 +354,15 @@ stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision) precstr[0] = '\0'; if (st->infinity > 0) { - strcpy(str, INFINITY_STRING); - return TRUE; + return snprintf(str, bufsize, "%s", INFINITY_STRING); } else if (st->infinity < 0) { - strcpy(str, MINFINITY_STRING); - return TRUE; + return snprintf(str, bufsize, "%s", MINFINITY_STRING); } if (precision > 0 && st->fr) { - sprintf(precstr, ".%09d", st->fr); + snprintf(precstr, sizeof(precstr), ".%09d", st->fr); if (precision < 9) precstr[precision + 1] = '\0'; for (i = precision; i > 0; i--) @@ -398,16 +397,15 @@ stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision) zoneint -= 3600; } if (zoneint > 0) - sprintf(zonestr, "-%02d", (int) zoneint / 3600); + snprintf(zonestr, sizeof(zonestr), "-%02d", (int) zoneint / 3600); else - sprintf(zonestr, "+%02d", -(int) zoneint / 3600); + snprintf(zonestr, sizeof(zonestr), "+%02d", -(int) zoneint / 3600); } #endif /* TIMEZONE_GLOBAL */ if (st->y < 0) - sprintf(str, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s BC", -st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); + return snprintf(str, bufsize, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s BC", -st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); else - sprintf(str, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s", st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); - return TRUE; + return snprintf(str, bufsize, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s", st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); } #if (ODBCVER >= 0x0300) @@ -797,6 +795,7 @@ copy_and_convert_field(StatementClass *stmt, #if (ODBCVER >= 0x0350) SQLGUID g; #endif + int i; if (stmt->current_col >= 0) { @@ -1158,8 +1157,7 @@ inolog("2stime fr=%d\n", std_time.fr); if (text_handling) { #ifdef WIN_UNICODE_SUPPORT - if (SQL_C_CHAR == fCType - || SQL_C_BINARY == fCType) + if (SQL_C_CHAR == fCType || SQL_C_BINARY == fCType) localize_needed = TRUE; #endif /* WIN_UNICODE_SUPPORT */ } @@ -1176,52 +1174,45 @@ inolog("2stime fr=%d\n", std_time.fr); switch (field_type) { case PG_TYPE_DATE: - len = 10; - if (cbValueMax > len) - sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d", std_time.y, std_time.m, std_time.d); + len = snprintf(rgbValueBindRow, cbValueMax, "%.4d-%.2d-%.2d", std_time.y, std_time.m, std_time.d); + if (len + 1 > cbValueMax) + result = COPY_RESULT_TRUNCATED; break; case PG_TYPE_TIME: - len = 8; - if (cbValueMax > len) - sprintf(rgbValueBindRow, "%.2d:%.2d:%.2d", std_time.hh, std_time.mm, std_time.ss); + len = snprintf(rgbValueBindRow, cbValueMax, "%.2d:%.2d:%.2d", std_time.hh, std_time.mm, std_time.ss); + if (len + 1 > cbValueMax) + result = COPY_RESULT_TRUNCATED; break; case PG_TYPE_ABSTIME: case PG_TYPE_DATETIME: case PG_TYPE_TIMESTAMP_NO_TMZONE: case PG_TYPE_TIMESTAMP: - len = 19; - if (cbValueMax > len) - { - /* sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", - std_time.y, std_time.m, std_time.d, std_time.hh, std_time.mm, std_time.ss); */ - stime2timestamp(&std_time, rgbValueBindRow, FALSE, - PG_VERSION_GE(conn, 7.2) ? (int) cbValueMax - len - 2 : 0); - len = strlen(rgbValueBindRow); - } + /* sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", + std_time.y, std_time.m, std_time.d, std_time.hh, std_time.mm, std_time.ss); */ + len = stime2timestamp(&std_time, rgbValueBindRow, cbValueMax, FALSE, + PG_VERSION_GE(conn, 7.2) ? (int) cbValueMax - len - 2 : 0); + if (len + 1 > cbValueMax) + result = COPY_RESULT_TRUNCATED; break; case PG_TYPE_BOOL: - len = strlen(neut_str); - if (cbValueMax > len) - { - strcpy(rgbValueBindRow, neut_str); - mylog("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n", rgbValueBindRow); - } + len = snprintf(rgbValueBindRow, cbValueMax, "%s", neut_str); + if (len + 1 > cbValueMax) + result = COPY_RESULT_TRUNCATED; + mylog("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n", rgbValueBindRow); break; case PG_TYPE_UUID: len = strlen(neut_str); - if (cbValueMax > len) - { - int i; - - for (i = 0; i < len; i++) - rgbValueBindRow[i] = toupper((UCHAR) neut_str[i]); + for (i = 0; i < len && i < cbValueMax - 1; i++) + rgbValueBindRow[i] = toupper((UCHAR) neut_str[i]); + if (cbValueMax > 0) rgbValueBindRow[i] = '\0'; - mylog("PG_TYPE_UUID: rgbValueBindRow = '%s'\n", rgbValueBindRow); - } + if (len + 1 > cbValueMax) + result = COPY_RESULT_TRUNCATED; + mylog("PG_TYPE_UUID: rgbValueBindRow = '%s'\n", rgbValueBindRow); break; /* @@ -1309,8 +1300,8 @@ inolog("2stime fr=%d\n", std_time.fr); #endif /* WIN_UNICODE_SUPPORT */ /* convert linefeeds to carriage-return/linefeed */ len = convert_linefeeds(neut_str, NULL, 0, lf_conv, &changed); - if (cbValueMax == 0) /* just returns length - * info */ + /* just returns length info */ + if (cbValueMax == 0) { result = COPY_RESULT_TRUNCATED; #ifdef WIN_UNICODE_SUPPORT @@ -1319,6 +1310,19 @@ inolog("2stime fr=%d\n", std_time.fr); #endif /* WIN_UNICODE_SUPPORT */ break; } +#ifdef UNICODE_SUPPORT + if (cbValueMax == 1 && fCType == SQL_C_WCHAR) + { + rgbValueBindRow[0] = '\0'; + result = COPY_RESULT_TRUNCATED; +#ifdef WIN_UNICODE_SUPPORT + if (allocbuf) + free(allocbuf); +#endif /* WIN_UNICODE_SUPPORT */ + break; + } +#endif + if (!pgdc->ttlbuf) pgdc->ttlbuflen = 0; needbuflen = len; @@ -1414,33 +1418,37 @@ inolog("2stime fr=%d\n", std_time.fr); if (cbValueMax > 0) { BOOL already_copied = FALSE; + int terminatorlen; if (fCType == SQL_C_BINARY) - copy_len = (len > cbValueMax) ? cbValueMax : len; - else - copy_len = (len >= cbValueMax) ? (cbValueMax - 1) : len; + { + terminatorlen = 0; + } #ifdef UNICODE_SUPPORT - if (fCType == SQL_C_WCHAR) + else if (fCType == SQL_C_WCHAR) { - copy_len /= WCLEN; - copy_len *= WCLEN; + terminatorlen = WCLEN; + /* make sure the output buffer size is divisible by two */ + cbValueMax = (cbValueMax / WCLEN) * WCLEN; } -#endif /* UNICODE_SUPPORT */ +#endif + else + { + terminatorlen = 1; + } + + if (len + terminatorlen > cbValueMax) + copy_len = cbValueMax - terminatorlen; + else + copy_len = len; + if (!already_copied) { /* Copy the data */ memcpy(rgbValueBindRow, ptr, copy_len); /* Add null terminator */ -#ifdef UNICODE_SUPPORT - if (fCType == SQL_C_WCHAR) - { - if (copy_len + WCLEN <= cbValueMax) - memset(rgbValueBindRow + copy_len, 0, WCLEN); - } - else -#endif /* UNICODE_SUPPORT */ - if (copy_len < cbValueMax) - rgbValueBindRow[copy_len] = '\0'; + for (i = 0; i < terminatorlen && copy_len + i < cbValueMax; i++) + rgbValueBindRow[copy_len + i] = '\0'; } /* Adjust data_left for next time */ if (stmt->current_col >= 0) @@ -1462,7 +1470,6 @@ inolog("2stime fr=%d\n", std_time.fr); } } - if (SQL_C_WCHAR == fCType) mylog(" SQL_C_WCHAR, default: len = %d, cbValueMax = %d, rgbValueBindRow = '%s'\n", len, cbValueMax, rgbValueBindRow); else if (SQL_C_BINARY == fCType) @@ -4658,7 +4665,7 @@ mylog("buf=%p flag=%d\n", buf, qb->flags); * st.m, st.d, st.hh, st.mm, st.ss); */ /* Time zone stuff is unreliable */ - stime2timestamp(&st, tmp, USE_ZONE, PG_VERSION_GE(conn, 7.2) ? 6 : 0); + stime2timestamp(&st, tmp, sizeof(tmp), USE_ZONE, PG_VERSION_GE(conn, 7.2) ? 6 : 0); lastadd = "::timestamp"; CVT_APPEND_STR(qb, tmp); diff --git a/test/expected/result-conversions.out b/test/expected/result-conversions.out index 696c315e..851cd9fc 100644 --- a/test/expected/result-conversions.out +++ b/test/expected/result-conversions.out @@ -1346,10 +1346,22 @@ Result set: 'foocur' (refcursor) as SQL_C_INTERVAL_HOUR_TO_SECOND: interval sign: 0 unknown interval type: 0 'foocur' (refcursor) as SQL_C_INTERVAL_MINUTE_TO_SECOND: interval sign: 0 unknown interval type: 0 '543c5e21-435a-440b-943c-64af1ad571f1' (text) as SQL_C_GUID: d1: 543C5E21 d2: 435A d3: 440B d4: 943C64AF1AD571F1 -'2011-02-13' (date) as SQL_C_DATE: unknown SQL C type: 9 -'2011-02-13' (date) as SQL_C_TIMESTAMP: unknown SQL C type: 11 -'2011-02-15 15:49:18' (timestamp) as SQL_C_DATE: unknown SQL C type: 9 -'2011-02-15 15:49:18' (timestamp) as SQL_C_TIMESTAMP: unknown SQL C type: 11 -'2011-02-16 17:49:18+03' (timestamptz) as SQL_C_DATE: unknown SQL C type: 9 -'2011-02-16 17:49:18+03' (timestamptz) as SQL_C_TIMESTAMP: unknown SQL C type: 11 +'2011-02-13' (date) as SQL_C_DATE: y: 2011 m: 2 d: 13 +'2011-02-13' (date) as SQL_C_TIMESTAMP: y: 2011 m: 2 d: 13 h: 0 m: 0 s: 0 f: 0 +'2011-02-15 15:49:18' (timestamp) as SQL_C_DATE: y: 2011 m: 2 d: 15 +'2011-02-15 15:49:18' (timestamp) as SQL_C_TIMESTAMP: y: 2011 m: 2 d: 15 h: 15 m: 49 s: 18 f: 0 +'2011-02-16 17:49:18+03' (timestamptz) as SQL_C_DATE: y: 2011 m: 2 d: 16 +'2011-02-16 17:49:18+03' (timestamptz) as SQL_C_TIMESTAMP: y: 2011 m: 2 d: 16 h: 6 m: 49 s: 18 f: 0 +'foobar' (text) as SQL_C_CHAR: foob (truncated) +'foobar' (text) as SQL_C_CHAR: fooba (truncated) +'foobar' (text) as SQL_C_CHAR: foobar +'foobar' (text) as SQL_C_WCHAR: foob (truncated) +'foobar' (text) as SQL_C_WCHAR: foob (truncated) +'foobar' (text) as SQL_C_WCHAR: fooba (truncated) +'foobar' (text) as SQL_C_WCHAR: fooba (truncated) +'foobar' (text) as SQL_C_WCHAR: foobar +'' (text) as SQL_C_CHAR: +'' (text) as SQL_C_WCHAR: \FF00\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF\FFFF (truncated) +'2011-02-15 15:49:18' (timestamp) as SQL_C_CHAR: 2011-02-15 15:49:1 (truncated) +'2011-02-15 15:49:18 BC' (timestamp) as SQL_C_CHAR: 2011-02-15 15:49:18 (truncated) disconnecting diff --git a/test/src/result-conversions-test.c b/test/src/result-conversions-test.c index 47eb74de..4864dd39 100644 --- a/test/src/result-conversions-test.c +++ b/test/src/result-conversions-test.c @@ -111,13 +111,21 @@ static HSTMT hstmt = SQL_NULL_HSTMT; void printwchar(SQLWCHAR *wstr) { - while(*wstr) + int i; + /* + * a backstop to make sure we terminate if the string isn't null-terminated + * properly + */ + int MAXLEN = 50; + + while(*wstr && i < MAXLEN) { if (isprint(*wstr)) printf("%c", *wstr); else printf("\\%4X", *wstr); wstr++; + i++; } } @@ -314,21 +322,101 @@ print_sql_type(int sql_c_type, void *buf, SQLLEN strlen_or_ind) } } + +/* + * Get the size of fixed-length data types, or -1 for var-length types + */ +int +get_sql_type_size(int sql_c_type) +{ + switch(sql_c_type) + { + case SQL_C_CHAR: + return -1; + case SQL_C_WCHAR: + return -1; + case SQL_C_SSHORT: + return sizeof(short); + case SQL_C_USHORT: + return sizeof(unsigned short); + case SQL_C_SLONG: + /* always 32-bits, regardless of native 'long' type */ + return sizeof(SQLINTEGER); + case SQL_C_ULONG: + return sizeof(SQLUINTEGER); + case SQL_C_FLOAT: + return sizeof(SQLREAL); + case SQL_C_DOUBLE: + return sizeof(SQLDOUBLE); + case SQL_C_BIT: + return sizeof(unsigned char); + case SQL_C_STINYINT: + return sizeof(signed char); + case SQL_C_UTINYINT: + return sizeof(unsigned char); + case SQL_C_SBIGINT: + return sizeof(SQLBIGINT); + case SQL_C_UBIGINT: + return sizeof(SQLUBIGINT); + case SQL_C_BINARY: + return -1; + /* SQL_C_BOOKMARK has same value as SQL_C_UBIGINT */ + /* SQL_C_VARBOOKMARK has same value as SQL_C_BINARY */ + case SQL_C_TYPE_DATE: + return sizeof(DATE_STRUCT); + case SQL_C_TYPE_TIME: + return sizeof(TIME_STRUCT); + case SQL_C_TYPE_TIMESTAMP: + return sizeof(TIMESTAMP_STRUCT); + case SQL_C_NUMERIC: + return sizeof(SQL_NUMERIC_STRUCT); + case SQL_C_GUID: + return sizeof(SQLGUID); + case SQL_C_INTERVAL_YEAR: + case SQL_C_INTERVAL_MONTH: + case SQL_C_INTERVAL_DAY: + case SQL_C_INTERVAL_HOUR: + case SQL_C_INTERVAL_MINUTE: + case SQL_C_INTERVAL_SECOND: + case SQL_C_INTERVAL_YEAR_TO_MONTH: + case SQL_C_INTERVAL_DAY_TO_HOUR: + case SQL_C_INTERVAL_DAY_TO_MINUTE: + case SQL_C_INTERVAL_DAY_TO_SECOND: + case SQL_C_INTERVAL_HOUR_TO_MINUTE: + case SQL_C_INTERVAL_HOUR_TO_SECOND: + case SQL_C_INTERVAL_MINUTE_TO_SECOND: + return sizeof(SQL_INTERVAL_STRUCT); + default: + printf("unknown SQL C type: %u", sql_c_type); + return -1; + } +} + static char *resultbuf = NULL; void -test_conversion(const char *pgtype, const char *pgvalue, int sqltype, const char *sqltypestr) +test_conversion(const char *pgtype, const char *pgvalue, int sqltype, const char *sqltypestr, int buflen) { char sql[500]; SQLRETURN rc; SQLLEN len_or_ind; + int fixed_len; + + printf("'%s' (%s) as %s: ", pgvalue, pgtype, sqltypestr); if (resultbuf == NULL) resultbuf = malloc(500); memset(resultbuf, 0xFF, 500); - printf("'%s' (%s) as %s: ", pgvalue, pgtype, sqltypestr); + fixed_len = get_sql_type_size(sqltype); + if (fixed_len != -1) + buflen = fixed_len; + if (buflen == -1) + { + printf("no buffer length given!"); + exit(1); + } snprintf(sql, sizeof(sql), "SELECT '%s'::%s AS %s_col /* convert to %s */", @@ -340,11 +428,27 @@ test_conversion(const char *pgtype, const char *pgvalue, int sqltype, const char rc = SQLFetch(hstmt); CHECK_STMT_RESULT(rc, "SQLFetch failed", hstmt); - rc = SQLGetData(hstmt, 1, sqltype, resultbuf, 100, &len_or_ind); + rc = SQLGetData(hstmt, 1, sqltype, resultbuf, buflen, &len_or_ind); if (SQL_SUCCEEDED(rc)) { print_sql_type(sqltype, resultbuf, len_or_ind); + + if (rc == SQL_SUCCESS_WITH_INFO) + { + char sqlstate[10]; + + rc = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, sqlstate, NULL, NULL, 0, NULL); + CHECK_STMT_RESULT(rc, "SQLGetDiagRec failed", hstmt); + if (memcmp(sqlstate, "01004", 5) == 0) + printf(" (truncated)"); + else + print_diag("SQLGetData success with info", SQL_HANDLE_STMT, hstmt); + } + printf("\n"); + /* Check that the driver didn't write past the buffer */ + if ((unsigned char) resultbuf[buflen] != 0xFF) + printf("Driver wrote byte %02X past result buffer of size %d!\n", (unsigned char) resultbuf[buflen], buflen); } else { @@ -354,6 +458,8 @@ test_conversion(const char *pgtype, const char *pgvalue, int sqltype, const char rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + fflush(stdout); } int main(int argc, char **argv) @@ -394,7 +500,7 @@ int main(int argc, char **argv) int sqltype = sqltypes[sqltype_i].sqltype; const char *sqltypestr = sqltypes[sqltype_i].str; - test_conversion(pgtype, value, sqltype, sqltypestr); + test_conversion(pgtype, value, sqltype, sqltypestr, 100); } } @@ -404,15 +510,40 @@ int main(int argc, char **argv) */ /* Conversion to GUID throws error if the string is not of correct form */ - test_conversion("text", "543c5e21-435a-440b-943c-64af1ad571f1", SQL_C_GUID, "SQL_C_GUID"); + test_conversion("text", "543c5e21-435a-440b-943c-64af1ad571f1", SQL_C_GUID, "SQL_C_GUID", -1); /* Date/timestamp tests of non-date input depends on current date */ - test_conversion("date", "2011-02-13", SQL_C_DATE, "SQL_C_DATE"); - test_conversion("date", "2011-02-13", SQL_C_TIMESTAMP, "SQL_C_TIMESTAMP"); - test_conversion("timestamp", "2011-02-15 15:49:18", SQL_C_DATE, "SQL_C_DATE"); - test_conversion("timestamp", "2011-02-15 15:49:18", SQL_C_TIMESTAMP, "SQL_C_TIMESTAMP"); - test_conversion("timestamptz", "2011-02-16 17:49:18+03", SQL_C_DATE, "SQL_C_DATE"); - test_conversion("timestamptz", "2011-02-16 17:49:18+03", SQL_C_TIMESTAMP, "SQL_C_TIMESTAMP"); + test_conversion("date", "2011-02-13", SQL_C_TYPE_DATE, "SQL_C_DATE", -1); + test_conversion("date", "2011-02-13", SQL_C_TYPE_TIMESTAMP, "SQL_C_TIMESTAMP", -1); + test_conversion("timestamp", "2011-02-15 15:49:18", SQL_C_TYPE_DATE, "SQL_C_DATE", -1); + test_conversion("timestamp", "2011-02-15 15:49:18", SQL_C_TYPE_TIMESTAMP, "SQL_C_TIMESTAMP", -1); + test_conversion("timestamptz", "2011-02-16 17:49:18+03", SQL_C_TYPE_DATE, "SQL_C_DATE", -1); + test_conversion("timestamptz", "2011-02-16 17:49:18+03", SQL_C_TYPE_TIMESTAMP, "SQL_C_TIMESTAMP", -1); + + /* + * Test for truncations. + */ + test_conversion("text", "foobar", SQL_C_CHAR, "SQL_C_CHAR", 5); + test_conversion("text", "foobar", SQL_C_CHAR, "SQL_C_CHAR", 6); + test_conversion("text", "foobar", SQL_C_CHAR, "SQL_C_CHAR", 7); + test_conversion("text", "foobar", SQL_C_WCHAR, "SQL_C_WCHAR", 10); + test_conversion("text", "foobar", SQL_C_WCHAR, "SQL_C_WCHAR", 11); + test_conversion("text", "foobar", SQL_C_WCHAR, "SQL_C_WCHAR", 12); + test_conversion("text", "foobar", SQL_C_WCHAR, "SQL_C_WCHAR", 13); + test_conversion("text", "foobar", SQL_C_WCHAR, "SQL_C_WCHAR", 14); + + test_conversion("text", "", SQL_C_CHAR, "SQL_C_CHAR", 1); + test_conversion("text", "", SQL_C_WCHAR, "SQL_C_WCHAR", 1); + + test_conversion("timestamp", "2011-02-15 15:49:18", SQL_C_CHAR, "SQL_C_CHAR", 19); + + /* + * Test for a specific bug, where the driver used to overrun the output + * buffer because it assumed that a timestamp value is always max 20 bytes + * long (not true for BC values, or with years > 10000) + */ + test_conversion("timestamp", "2011-02-15 15:49:18 BC", SQL_C_CHAR, "SQL_C_CHAR", 20); + /* Clean up */ test_disconnect(); [parent: d1fe3e2e89f9]