Skip to content

Commit

Permalink
[0DBC-110] Fix and testcase of the crash in case of columns unbinding…
Browse files Browse the repository at this point in the history
… after stmt execution and before fetching data.

The reason was free-ing of 2 internal arrays, that are allocated during execution, and reset at each fetch.
SQLFreeStmt(SQL_UNBIND) just shouldn't free them.
  • Loading branch information
lawrinn committed Aug 28, 2017
1 parent 2569534 commit 860e7f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 0 additions & 2 deletions ma_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ SQLRETURN MADB_StmtFree(MADB_Stmt *Stmt, SQLUSMALLINT Option)
break;
case SQL_UNBIND:
MADB_FREE(Stmt->result);
MADB_FREE(Stmt->CharOffset);
MADB_FREE(Stmt->Lengths);
ResetMetadata(&Stmt->metadata, NULL);
MADB_DescFree(Stmt->Ard, TRUE);
break;
Expand Down
2 changes: 1 addition & 1 deletion ma_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ int InitClientCharset(Client_Charset *cc, const char * name)
return 1;
}

cc->CodePage= cc->cs_info->codepage;/*madb_get_windows_cp(name);*/
cc->CodePage= cc->cs_info->codepage;

return 0;
}
Expand Down
24 changes: 23 additions & 1 deletion test/scroll.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2013 MontyProgram AB
2013, 2017 MariaDB Corporation AB
The MySQL Connector/ODBC is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
Expand Down Expand Up @@ -1212,6 +1212,27 @@ ODBC_TEST(t_absolute_2)
return OK;
}

/*{{{ t_unbind_before_fetch */
/**
ODBC-110: Unbinding columns before fetching new result causes crash in the connector whilie fetching the row
Crash would occur also if ordinary SQLFetch was used. But it had been SQLFetchScroll, when the bug was observed for the 1st time
Affectts Microsoft ODBC test tool
*/
ODBC_TEST(t_unbind_before_fetch)
{
SQLUINTEGER dummy;

OK_SIMPLE_STMT(Stmt, "SELECT 1");

CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_UNBIND));

CHECK_STMT_RC(Stmt, SQLBindCol(Stmt, 1, SQL_C_ULONG, &dummy, 0, NULL));

CHECK_STMT_RC(Stmt, SQLFetchScroll(Stmt, SQL_FETCH_NEXT, 1));

return OK;
}
/*}}}*/

MA_ODBC_TESTS my_tests[]=
{
Expand All @@ -1221,6 +1242,7 @@ MA_ODBC_TESTS my_tests[]=
{t_array_relative_2, "t_array_relative_2"},
{t_absolute_1,"t_absolute_1"},
{t_absolute_2, "t_absolute_2"},
{t_unbind_before_fetch, "t_odbc_110_unbind_before_fetch"},
{NULL, NULL}
};

Expand Down

0 comments on commit 860e7f8

Please sign in to comment.