mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-02-26 05:33:03 +08:00
Merge pull request #9 from nyalldawson/free_str
Fix incorrect early free of str when reading ole fields
This commit is contained in:
@@ -1649,14 +1649,19 @@ SQLRETURN SQL_API SQLGetData(
|
|||||||
return SQL_SUCCESS_WITH_INFO;
|
return SQL_SUCCESS_WITH_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(rgbValue, str + stmt->pos, MIN(len - stmt->pos, cbValueMax-1));
|
const int totalSizeRemaining = len - stmt->pos;
|
||||||
((char *)rgbValue)[MIN(len - stmt->pos, cbValueMax-1)] = '\0';
|
const int partsRemain = cbValueMax - 1 < totalSizeRemaining;
|
||||||
stmt->pos += MIN(len - stmt->pos, cbValueMax-1);
|
const int sizeToReadThisPart = partsRemain ? cbValueMax - 1 : totalSizeRemaining;
|
||||||
if (cbValueMax - 1 < len - stmt->pos) {
|
memcpy(rgbValue, str + stmt->pos, sizeToReadThisPart);
|
||||||
|
|
||||||
|
((char *)rgbValue)[sizeToReadThisPart] = '\0';
|
||||||
|
if (partsRemain) {
|
||||||
|
stmt->pos += cbValueMax - 1;
|
||||||
if (col->col_type != MDB_OLE) { free(str); str = NULL; }
|
if (col->col_type != MDB_OLE) { free(str); str = NULL; }
|
||||||
strcpy(sqlState, "01004"); // truncated
|
strcpy(sqlState, "01004"); // truncated
|
||||||
return SQL_SUCCESS_WITH_INFO;
|
return SQL_SUCCESS_WITH_INFO;
|
||||||
}
|
}
|
||||||
|
stmt->pos = len;
|
||||||
free(str);
|
free(str);
|
||||||
str = NULL;
|
str = NULL;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user