Skip to content

Commit 8ca2dcf

Browse files
Martin SköldMartin Sköld
authored andcommitted
Bug #33661024 Validation of Array Index
Added check of variable index before indexing array. Approved by: Frazer Clement <[email protected]>
1 parent c534f2e commit 8ca2dcf

File tree

1 file changed

+51
-50
lines changed

1 file changed

+51
-50
lines changed

storage/ndb/src/kernel/blocks/ndbfs/Ndbfs.cpp

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,64 +1003,65 @@ Ndbfs::execFSAPPENDREQ(Signal * signal)
10031003

10041004
FsRef::NdbfsErrorCodeType errorCode;
10051005

1006-
AsyncFile* openFile = theOpenFiles.find(filePointer);
1007-
const NewVARIABLE *myBaseAddrRef =
1008-
&getBat(blockNumber, instanceNumber)[fsReq->varIndex];
1009-
1010-
#ifdef ERROR_INSERT
1011-
if (ERROR_INSERTED(2002) && (c_error_insert_extra == fsReq->filePointer))
1012-
{
1013-
CLEAR_ERROR_INSERT_VALUE;
1014-
openFile->error_insert(FsRef::fsErrNoSpaceLeftOnDevice);
1015-
}
1016-
#endif
1017-
1018-
const Uint32* tWA = (const Uint32*)myBaseAddrRef->WA;
1019-
const Uint32 tSz = myBaseAddrRef->nrr;
1020-
const Uint32 offset = fsReq->offset;
1021-
const Uint32 size = fsReq->size;
1022-
const Uint32 synch_flag = fsReq->synch_flag;
10231006
Request *request = theRequestPool->get();
1024-
1025-
if (openFile == NULL) {
1026-
jam();
1027-
errorCode = FsRef::fsErrFileDoesNotExist;
1028-
goto error;
1029-
}
1030-
1031-
if (myBaseAddrRef == NULL) {
1032-
jam(); // Ensure that a valid variable is used
1033-
errorCode = FsRef::fsErrInvalidParameters;
1034-
goto error;
1035-
}
1036-
10371007
if (fsReq->varIndex >= getBatSize(blockNumber, instanceNumber)) {
10381008
jam();// Ensure that a valid variable is used
10391009
errorCode = FsRef::fsErrInvalidParameters;
10401010
goto error;
10411011
}
1042-
1043-
if(offset + size > tSz){
1044-
jam(); // Ensure that a valid variable is used
1045-
errorCode = FsRef::fsErrInvalidParameters;
1046-
goto error;
1047-
}
1012+
{
1013+
AsyncFile* openFile = theOpenFiles.find(filePointer);
1014+
const NewVARIABLE *myBaseAddrRef =
1015+
&getBat(blockNumber, instanceNumber)[fsReq->varIndex];
10481016

1049-
request->error = 0;
1050-
request->set(userRef, userPointer, filePointer);
1051-
request->file = openFile;
1052-
request->theTrace = signal->getTrace();
1053-
1054-
request->par.append.buf = (const char *)(tWA + offset);
1055-
request->par.append.size = size << 2;
1017+
#ifdef ERROR_INSERT
1018+
if (ERROR_INSERTED(2002) && (c_error_insert_extra == fsReq->filePointer))
1019+
{
1020+
CLEAR_ERROR_INSERT_VALUE;
1021+
openFile->error_insert(FsRef::fsErrNoSpaceLeftOnDevice);
1022+
}
1023+
#endif
10561024

1057-
if (!synch_flag)
1058-
request->action = Request::append;
1059-
else
1060-
request->action = Request::append_synch;
1061-
request->m_do_bind = false;
1062-
ndbrequire(forward(openFile, request));
1063-
return;
1025+
const Uint32* tWA = (const Uint32*)myBaseAddrRef->WA;
1026+
const Uint32 tSz = myBaseAddrRef->nrr;
1027+
const Uint32 offset = fsReq->offset;
1028+
const Uint32 size = fsReq->size;
1029+
const Uint32 synch_flag = fsReq->synch_flag;
1030+
1031+
if (openFile == NULL) {
1032+
jam();
1033+
errorCode = FsRef::fsErrFileDoesNotExist;
1034+
goto error;
1035+
}
1036+
1037+
if (myBaseAddrRef == NULL) {
1038+
jam(); // Ensure that a valid variable is used
1039+
errorCode = FsRef::fsErrInvalidParameters;
1040+
goto error;
1041+
}
1042+
1043+
if(offset + size > tSz){
1044+
jam(); // Ensure that a valid variable is used
1045+
errorCode = FsRef::fsErrInvalidParameters;
1046+
goto error;
1047+
}
1048+
1049+
request->error = 0;
1050+
request->set(userRef, userPointer, filePointer);
1051+
request->file = openFile;
1052+
request->theTrace = signal->getTrace();
1053+
1054+
request->par.append.buf = (const char *)(tWA + offset);
1055+
request->par.append.size = size << 2;
1056+
1057+
if (!synch_flag)
1058+
request->action = Request::append;
1059+
else
1060+
request->action = Request::append_synch;
1061+
request->m_do_bind = false;
1062+
ndbrequire(forward(openFile, request));
1063+
return;
1064+
}
10641065

10651066
error:
10661067
jam();

0 commit comments

Comments
 (0)