Remove non portable memory allocations and added check to make sure maxRows is > 0 for non-ResultSet queries
This commit is contained in:
parent
ab40f2467a
commit
52368d79df
|
@ -2,6 +2,10 @@
|
|||
|
||||
## node-oracledb v1.2.0 (DD Mon YYYY)
|
||||
|
||||
- Remove non-portable memory allocation for queries that return NULL.
|
||||
|
||||
- Added check to make sure maxRows is greater than zero for non-ResultSet queries.
|
||||
|
||||
- Fixed AIX-specific REF CURSOR related failures.
|
||||
|
||||
- Optimized CLOB memory allocation to account for different database-to-client character set expansions.
|
||||
|
|
|
@ -1386,6 +1386,13 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
|
|||
Define *defines = executeBaton->defines = new Define[numCols];
|
||||
int csratio = executeBaton->dpiconn->getByteExpansionRatio ();
|
||||
|
||||
// Check for maxRows must be greater than zero in case of non-resultSet
|
||||
if ( executeBaton->maxRows == 0 )
|
||||
{
|
||||
executeBaton->error = NJSMessages::getErrorMsg ( errInvalidmaxRows );
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned int col = 0; col < numCols; col++)
|
||||
{
|
||||
switch(meta[col].dbType)
|
||||
|
@ -1431,26 +1438,36 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
|
|||
* size expansion when data is converted from the DB character set
|
||||
* to AL32UTF8
|
||||
*/
|
||||
|
||||
defines[col].maxSize = (meta[col].dbSize) * csratio;
|
||||
|
||||
if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize,
|
||||
executeBaton->maxRows ) )
|
||||
if ( meta[col].dbSize != 0 )
|
||||
{
|
||||
executeBaton->error = NJSMessages::getErrorMsg( errResultsTooLarge );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
defines[col].buf = (char *)malloc( (size_t)defines[col].maxSize*
|
||||
executeBaton->maxRows );
|
||||
if( !defines[col].buf )
|
||||
/* dbSize will be zero in case of "select null from dual" and
|
||||
* malloc(0) behaves diffrently on different platforms, so avoiding it
|
||||
*/
|
||||
defines[col].maxSize = (meta[col].dbSize) * csratio;
|
||||
|
||||
if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize,
|
||||
executeBaton->maxRows ) )
|
||||
{
|
||||
executeBaton->error = NJSMessages::getErrorMsg(
|
||||
errInsufficientMemory );
|
||||
executeBaton->error = NJSMessages::getErrorMsg(
|
||||
errResultsTooLarge );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
defines[col].buf = (char *)malloc( (size_t)defines[col].maxSize*
|
||||
executeBaton->maxRows );
|
||||
if( !defines[col].buf )
|
||||
{
|
||||
executeBaton->error = NJSMessages::getErrorMsg(
|
||||
errInsufficientMemory );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* The null scenario will have indicator as -1, so memory allocation
|
||||
* not required.
|
||||
*/
|
||||
break;
|
||||
case dpi::DpiDate :
|
||||
case dpi::DpiTimestamp:
|
||||
|
|
|
@ -60,6 +60,7 @@ static const char *errMsg[] =
|
|||
"NJS-023: concurrent operations on LOB are not allowed",
|
||||
"NJS-024: memory allocation failed",
|
||||
"NJS-025: overflow when calculating results area size",
|
||||
"NJS-026: maxRows must be greater than zero",
|
||||
};
|
||||
|
||||
string NJSMessages::getErrorMsg ( NJSErrorType err, ... )
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef enum
|
|||
errBusyLob,
|
||||
errInsufficientMemory,
|
||||
errResultsTooLarge,
|
||||
errInvalidmaxRows,
|
||||
|
||||
// New ones should be added here
|
||||
|
||||
|
|
|
@ -254,10 +254,8 @@ describe('1. connection.js', function(){
|
|||
"SELECT * FROM oracledb_employees",
|
||||
{}, { maxRows: 0 },
|
||||
function(err, result){
|
||||
should.not.exist(err);
|
||||
should.exist(result);
|
||||
|
||||
(result.rows).should.have.length(0);
|
||||
should.exist(err);
|
||||
err.message.should.startWith('NJS-026:');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue