Fix incorrect early free of str when reading ole fields

This commit is contained in:
Nyall Dawson 2020-08-12 08:48:32 +10:00
parent b25eb73648
commit 2567e57faa

View File

@ -1649,14 +1649,19 @@ SQLRETURN SQL_API SQLGetData(
return SQL_SUCCESS_WITH_INFO;
}
memcpy(rgbValue, str + stmt->pos, MIN(len - stmt->pos, cbValueMax-1));
((char *)rgbValue)[MIN(len - stmt->pos, cbValueMax-1)] = '\0';
stmt->pos += MIN(len - stmt->pos, cbValueMax-1);
if (cbValueMax - 1 < len - stmt->pos) {
const int totalSizeRemaining = len - stmt->pos;
const int partsRemain = cbValueMax - 1 < totalSizeRemaining;
const int sizeToReadThisPart = partsRemain ? cbValueMax - 1 : totalSizeRemaining;
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; }
strcpy(sqlState, "01004"); // truncated
return SQL_SUCCESS_WITH_INFO;
}
stmt->pos = 0;
free(str);
str = NULL;
break;