Skip to content

Commit bc10af4

Browse files
committed
Add defensive checks
1 parent b20d765 commit bc10af4

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

src/njs/src/njsConnection.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,13 @@ NAN_METHOD(Connection::Execute)
442442
NJS_GET_CALLBACK ( callback, info );
443443

444444
connection = Nan::ObjectWrap::Unwrap<Connection>(info.This());
445+
446+
/* If connection is invalid from JS, then throw an exception */
447+
NJS_CHECK_OBJECT_VALID2 ( connection, info ) ;
448+
445449
eBaton *executeBaton = new eBaton ( connection->DBCount (), callback );
446450

447451
NJS_CHECK_NUMBER_OF_ARGS ( executeBaton->error, info, 2, 4, exitExecute );
448-
NJS_CHECK_OBJECT_VALID3( connection, executeBaton->error, exitExecute );
449452

450453
if(!connection->isValid_)
451454
{
@@ -2599,10 +2602,13 @@ NAN_METHOD(Connection::Release)
25992602
ConnectionBusyStatus connStat;
26002603

26012604
connection = Nan::ObjectWrap::Unwrap<Connection>(info.This());
2605+
2606+
/* If connection is invalide from JS, then throw an exception */
2607+
NJS_CHECK_OBJECT_VALID2 ( connection, info ) ;
2608+
26022609
eBaton *releaseBaton = new eBaton ( connection->DBCount (), callback );
26032610

26042611
NJS_CHECK_NUMBER_OF_ARGS ( releaseBaton->error, info, 1, 1, exitRelease );
2605-
NJS_CHECK_OBJECT_VALID3(connection, releaseBaton->error, exitRelease);
26062612
if(!connection->isValid_)
26072613
{
26082614
releaseBaton->error = NJSMessages::getErrorMsg ( errInvalidConnection );
@@ -2722,10 +2728,13 @@ NAN_METHOD(Connection::Commit)
27222728
NJS_GET_CALLBACK ( callback, info );
27232729

27242730
connection = Nan::ObjectWrap::Unwrap<Connection>(info.This());
2731+
2732+
/* if connection is invalid from JS, then throw an exception */
2733+
NJS_CHECK_OBJECT_VALID2 ( connection, info ) ;
2734+
27252735
eBaton *commitBaton = new eBaton ( connection->DBCount (), callback );
27262736

27272737
NJS_CHECK_NUMBER_OF_ARGS ( commitBaton->error, info, 1, 1, exitCommit );
2728-
NJS_CHECK_OBJECT_VALID3 ( connection, commitBaton->error, exitCommit );
27292738
if(!connection->isValid_)
27302739
{
27312740
commitBaton->error = NJSMessages::getErrorMsg ( errInvalidConnection );
@@ -2826,9 +2835,11 @@ NAN_METHOD(Connection::Rollback)
28262835
NJS_GET_CALLBACK ( callback, info );
28272836

28282837
connection = Nan::ObjectWrap::Unwrap<Connection>(info.This());
2838+
/* if connection is invalid from JS, then throw an exception */
2839+
NJS_CHECK_OBJECT_VALID2 ( connection, info );
2840+
28292841
eBaton *rollbackBaton = new eBaton ( connection->DBCount (), callback );
28302842
NJS_CHECK_NUMBER_OF_ARGS ( rollbackBaton->error, info, 1, 1, exitRollback );
2831-
NJS_CHECK_OBJECT_VALID3 ( connection, rollbackBaton->error, exitRollback );
28322843

28332844
if(!connection->isValid_)
28342845
{
@@ -2927,10 +2938,13 @@ NAN_METHOD(Connection::Break)
29272938
NJS_GET_CALLBACK ( callback, info );
29282939

29292940
connection = Nan::ObjectWrap::Unwrap<Connection>(info.This());
2941+
2942+
/* If connection is invalid from JS, then throw an exception */
2943+
NJS_CHECK_OBJECT_VALID2 ( connection, info );
2944+
29302945
eBaton *breakBaton = new eBaton ( connection->DBCount (), callback );
29312946

29322947
NJS_CHECK_NUMBER_OF_ARGS ( breakBaton->error, info, 1, 1, exitBreak );
2933-
NJS_CHECK_OBJECT_VALID3 ( connection, breakBaton->error, exitBreak );
29342948

29352949
if(!connection->isValid_)
29362950
{

src/njs/src/njsIntLob.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,14 @@ NAN_METHOD(ILob::Read)
835835

836836
NJS_GET_CALLBACK(callback, info);
837837
iLob = Nan::ObjectWrap::Unwrap<ILob>(info.This());
838+
839+
/* If iLob object is invalid from JS, then throw an exception */
840+
NJS_CHECK_OBJECT_VALID2 (iLob, info);
841+
838842
LobBaton *lobBaton = new LobBaton ( iLob->njsconn_->LOBCount (), callback );
839843

840844
NJS_CHECK_NUMBER_OF_ARGS (lobBaton->error, info, 1, 1, exitRead);
841845

842-
NJS_CHECK_OBJECT_VALID3(iLob, lobBaton->error, exitRead);
843-
844846
if(!iLob->isValid_)
845847
{
846848
lobBaton->error = NJSMessages::getErrorMsg(errInvalidLob);
@@ -1032,11 +1034,14 @@ NAN_METHOD(ILob::Write)
10321034

10331035
NJS_GET_CALLBACK(callback, info);
10341036
iLob = Nan::ObjectWrap::Unwrap<ILob>(info.This());
1037+
1038+
/* If iLob is invalid from JS, then throw an exception */
1039+
NJS_CHECK_OBJECT_VALID2 ( iLob, info );
1040+
10351041
LobBaton *lobBaton = new LobBaton ( iLob->njsconn_->LOBCount (), callback );
10361042

10371043
NJS_CHECK_NUMBER_OF_ARGS (lobBaton->error, info, 2, 2, exitWrite);
10381044

1039-
NJS_CHECK_OBJECT_VALID3 ( iLob, lobBaton->error, exitWrite);
10401045
if(!iLob->isValid_)
10411046
{
10421047
lobBaton->error = NJSMessages::getErrorMsg(errInvalidLob);

src/njs/src/njsResultSet.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,14 @@ NAN_METHOD(ResultSet::GetRow)
244244
NJS_GET_CALLBACK ( callback, info );
245245

246246
ResultSet *njsResultSet = Nan::ObjectWrap::Unwrap<ResultSet>(info.This());
247+
248+
/* If njsResultSet is invalid from JS, then throw an exception */
249+
NJS_CHECK_OBJECT_VALID2 ( njsResultSet, info );
250+
247251
rsBaton *getRowsBaton = new rsBaton ( njsResultSet->njsconn_->RSCount (),
248252
callback );
249253
getRowsBaton->njsRS = njsResultSet;
250254

251-
if ( !njsResultSet )
252-
{
253-
getRowsBaton->error = NJSMessages::getErrorMsg ( errInvalidJSObject ) ;
254-
// donot alter the state while exiting
255-
getRowsBaton->errOnActiveOrInvalid = true;
256-
goto exitGetRow;
257-
}
258255
if(njsResultSet->state_ == INVALID)
259256
{
260257
getRowsBaton->error = NJSMessages::getErrorMsg ( errInvalidResultSet );
@@ -295,17 +292,14 @@ NAN_METHOD(ResultSet::GetRows)
295292
NJS_GET_CALLBACK ( callback, info );
296293

297294
ResultSet *njsResultSet = Nan::ObjectWrap::Unwrap<ResultSet>(info.This());
295+
296+
/* If njsResultSet is invalid from JS, then throw an exception */
297+
NJS_CHECK_OBJECT_VALID2 ( njsResultSet, info );
298+
298299
rsBaton *getRowsBaton = new rsBaton ( njsResultSet->njsconn_->RSCount (),
299300
callback );
300301
getRowsBaton->njsRS = njsResultSet;
301302

302-
if ( !njsResultSet )
303-
{
304-
getRowsBaton->error = NJSMessages::getErrorMsg ( errInvalidJSObject );
305-
getRowsBaton->errOnActiveOrInvalid = true;
306-
goto exitGetRows;
307-
}
308-
309303
if(njsResultSet->state_ == INVALID)
310304
{
311305
getRowsBaton->error = NJSMessages::getErrorMsg ( errInvalidResultSet );
@@ -564,18 +558,14 @@ NAN_METHOD(ResultSet::Close)
564558
NJS_GET_CALLBACK ( callback, info );
565559

566560
ResultSet *njsResultSet = Nan::ObjectWrap::Unwrap<ResultSet>(info.This());
561+
562+
/* If njsResultSet is invalid from JS, then throw an exception */
563+
NJS_CHECK_OBJECT_VALID2 ( njsResultSet, info );
564+
567565
rsBaton *closeBaton = new rsBaton ( njsResultSet->njsconn_->RSCount (),
568566
callback );
569567
closeBaton->njsRS = njsResultSet;
570568

571-
if ( !njsResultSet )
572-
{
573-
closeBaton->error = NJSMessages::getErrorMsg ( errInvalidJSObject );
574-
// donot alter the state while exiting
575-
closeBaton->errOnActiveOrInvalid = true;
576-
goto exitClose;
577-
}
578-
579569
if(njsResultSet->state_ == INVALID)
580570
{
581571
closeBaton->error = NJSMessages::getErrorMsg ( errInvalidResultSet );

0 commit comments

Comments
 (0)