Skip to content

Commit f225422

Browse files
committed
Merge branch 'odbc-3.1'. C/C has been moved to v3.4.8 as part of merge
2 parents 774cb49 + a5a7f08 commit f225422

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

driver/ma_api_internal.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,20 +1559,26 @@ SQLRETURN MA_SQLGetData(SQLHSTMT StatementHandle,
15591559
MADB_Stmt* Stmt= (MADB_Stmt*)StatementHandle;
15601560
unsigned int i;
15611561
MADB_DescRecord* IrdRec;
1562+
uint32_t columnCount= 0;
15621563

15631564
RESET_CANCELED(Stmt);
15641565
/* In case we don't have DM(it check for that) */
15651566
if (TargetValuePtr == NULL)
15661567
{
15671568
return MADB_SetError(&Stmt->Error, MADB_ERR_HY009, NULL, 0);
15681569
}
1569-
15701570
/* Bookmark */
15711571
if (Col_or_Param_Num == 0)
15721572
{
15731573
return MADB_GetBookmark(Stmt, TargetType, TargetValuePtr, BufferLength, StrLen_or_IndPtr);
15741574
}
1575-
1575+
/* This parameter validation has to be done before using it as array index
1576+
* To be on the safer side also checking if metadata is set, and if not - also treating it as index > max
1577+
*/
1578+
if (!Stmt->metadata || Col_or_Param_Num > (columnCount= Stmt->metadata->getColumnCount()))
1579+
{
1580+
return MADB_SetError(&Stmt->Error, MADB_ERR_07009, NULL, 0);
1581+
}
15761582
/* We don't need this to be checked in case of "internal" use of the GetData, i.e. for internal needs we should always get the data */
15771583
if (Stmt->CharOffset[Col_or_Param_Num - 1] > 0
15781584
&& Stmt->CharOffset[Col_or_Param_Num - 1] >= Stmt->Lengths[Col_or_Param_Num - 1])
@@ -1586,7 +1592,7 @@ SQLRETURN MA_SQLGetData(SQLHSTMT StatementHandle,
15861592
}
15871593

15881594
/* reset offsets for other columns. Doing that here since "internal" calls should not do that */
1589-
for (i= 0; i < Stmt->metadata->getColumnCount(); i++)
1595+
for (i= 0; i < columnCount; i++)
15901596
{
15911597
if (i != Col_or_Param_Num - 1)
15921598
{

driver/ma_statement.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,8 +2777,7 @@ SQLRETURN MADB_StmtGetData(SQLHSTMT StatementHandle,
27772777
IrdRec= MADB_DescGetInternalRecord(Stmt->Ird, Offset, MADB_DESC_READ);
27782778
if (!IrdRec)
27792779
{
2780-
MADB_SetError(&Stmt->Error, MADB_ERR_07009, NULL, 0);
2781-
return Stmt->Error.ReturnValue;
2780+
return MADB_SetError(&Stmt->Error, MADB_ERR_07009, NULL, 0);
27822781
}
27832782

27842783
switch (TargetType) {

libmariadb

test/param.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,8 @@ ODBC_TEST(t_bug59772)
977977
#undef ROWS_TO_INSERT
978978
}
979979

980-
980+
/* Enhanced it to also cover ODBC-479 SQLGetData with non-existent column index could crash
981+
the driver */
981982
ODBC_TEST(t_odbcoutparams)
982983
{
983984
SQLSMALLINT ncol, i;
@@ -986,6 +987,7 @@ ODBC_TEST(t_odbcoutparams)
986987
SQLSMALLINT type[]= {SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT};
987988
SQLCHAR str[20]= "initial value", buff[20];
988989
SQLHANDLE hdbc= NULL, hstmt;
990+
double dummy = .0;
989991

990992
CHECK_ENV_RC(Env, SQLAllocConnect(Env, &hdbc));
991993
hstmt= DoConnect(hdbc, FALSE, NULL, NULL, NULL, 0, NULL, NULL, NULL, "PSCACHESIZE=0");
@@ -1016,8 +1018,12 @@ ODBC_TEST(t_odbcoutparams)
10161018

10171019
/* Only 1 row always - we still can get them as a result */
10181020
CHECK_STMT_RC(hstmt, SQLFetch(hstmt));
1021+
EXPECT_STMT(hstmt, SQLGetData(hstmt, 133, SQL_C_DOUBLE, &dummy, sizeof(dummy), NULL), SQL_ERROR);
1022+
CHECK_SQLSTATE(hstmt, "07009");
10191023
is_num(my_fetch_int(hstmt, 1), 1300);
10201024
is_num(my_fetch_int(hstmt, 2), 300);
1025+
EXPECT_STMT(hstmt, SQLGetData(hstmt, 3, SQL_C_DOUBLE, &dummy, sizeof(dummy), NULL), SQL_ERROR);
1026+
CHECK_SQLSTATE(hstmt, "07009");
10211027
FAIL_IF(SQLFetch(hstmt) != SQL_NO_DATA_FOUND, "eof expected");
10221028

10231029
CHECK_STMT_RC(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
@@ -1759,7 +1765,7 @@ MA_ODBC_TESTS my_tests[]=
17591765
{t_bug49029, "t_bug49029"},
17601766
{t_bug56804, "t_bug56804"},
17611767
{t_bug59772, "t_bug59772"},
1762-
{t_odbcoutparams, "t_odbcoutparams"},
1768+
{t_odbcoutparams, "t_odbcoutparams-with_odbc-479"},
17631769
{t_bug14501952, "t_bug14501952"},
17641770
{t_bug14563386, "t_bug14563386"},
17651771
{t_bug14551229, "t_bug14551229"},

0 commit comments

Comments
 (0)