Merge pull request #9 from nyalldawson/free_str

Fix incorrect early free of str when reading ole fields
This commit is contained in:
Evan Miller 2020-08-11 20:03:01 -04:00 committed by GitHub
commit ef3a9f99a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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 = len;
free(str);
str = NULL;
break;