Skip to content

Commit 9f45e4c

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 85671c3 commit 9f45e4c

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
@@ -1074,64 +1074,65 @@ Ndbfs::execFSAPPENDREQ(Signal * signal)
10741074

10751075
FsRef::NdbfsErrorCodeType errorCode;
10761076

1077-
AsyncFile* openFile = theOpenFiles.find(filePointer);
1078-
const NewVARIABLE *myBaseAddrRef =
1079-
&getBat(blockNumber, instanceNumber)[fsReq->varIndex];
1080-
1081-
#ifdef ERROR_INSERT
1082-
if (ERROR_INSERTED(2002) && (c_error_insert_extra == fsReq->filePointer))
1083-
{
1084-
CLEAR_ERROR_INSERT_VALUE;
1085-
openFile->error_insert(FsRef::fsErrNoSpaceLeftOnDevice);
1086-
}
1087-
#endif
1088-
1089-
const Uint32* tWA = (const Uint32*)myBaseAddrRef->WA;
1090-
const Uint32 tSz = myBaseAddrRef->nrr;
1091-
const Uint32 offset = fsReq->offset;
1092-
const Uint32 size = fsReq->size;
1093-
const Uint32 synch_flag = fsReq->synch_flag;
10941077
Request *request = theRequestPool->get();
1095-
1096-
if (openFile == NULL) {
1097-
jam();
1098-
errorCode = FsRef::fsErrFileDoesNotExist;
1099-
goto error;
1100-
}
1101-
1102-
if (myBaseAddrRef == NULL) {
1103-
jam(); // Ensure that a valid variable is used
1104-
errorCode = FsRef::fsErrInvalidParameters;
1105-
goto error;
1106-
}
1107-
11081078
if (fsReq->varIndex >= getBatSize(blockNumber, instanceNumber)) {
11091079
jam();// Ensure that a valid variable is used
11101080
errorCode = FsRef::fsErrInvalidParameters;
11111081
goto error;
11121082
}
1113-
1114-
if(offset + size > tSz){
1115-
jam(); // Ensure that a valid variable is used
1116-
errorCode = FsRef::fsErrInvalidParameters;
1117-
goto error;
1118-
}
1083+
{
1084+
AsyncFile* openFile = theOpenFiles.find(filePointer);
1085+
const NewVARIABLE *myBaseAddrRef =
1086+
&getBat(blockNumber, instanceNumber)[fsReq->varIndex];
11191087

1120-
request->error = 0;
1121-
request->set(userRef, userPointer, filePointer);
1122-
request->file = openFile;
1123-
request->theTrace = signal->getTrace();
1124-
1125-
request->par.append.buf = (const char *)(tWA + offset);
1126-
request->par.append.size = size << 2;
1088+
#ifdef ERROR_INSERT
1089+
if (ERROR_INSERTED(2002) && (c_error_insert_extra == fsReq->filePointer))
1090+
{
1091+
CLEAR_ERROR_INSERT_VALUE;
1092+
openFile->error_insert(FsRef::fsErrNoSpaceLeftOnDevice);
1093+
}
1094+
#endif
11271095

1128-
if (!synch_flag)
1129-
request->action = Request::append;
1130-
else
1131-
request->action = Request::append_synch;
1132-
request->m_do_bind = false;
1133-
ndbrequire(forward(openFile, request));
1134-
return;
1096+
const Uint32* tWA = (const Uint32*)myBaseAddrRef->WA;
1097+
const Uint32 tSz = myBaseAddrRef->nrr;
1098+
const Uint32 offset = fsReq->offset;
1099+
const Uint32 size = fsReq->size;
1100+
const Uint32 synch_flag = fsReq->synch_flag;
1101+
1102+
if (openFile == NULL) {
1103+
jam();
1104+
errorCode = FsRef::fsErrFileDoesNotExist;
1105+
goto error;
1106+
}
1107+
1108+
if (myBaseAddrRef == NULL) {
1109+
jam(); // Ensure that a valid variable is used
1110+
errorCode = FsRef::fsErrInvalidParameters;
1111+
goto error;
1112+
}
1113+
1114+
if(offset + size > tSz){
1115+
jam(); // Ensure that a valid variable is used
1116+
errorCode = FsRef::fsErrInvalidParameters;
1117+
goto error;
1118+
}
1119+
1120+
request->error = 0;
1121+
request->set(userRef, userPointer, filePointer);
1122+
request->file = openFile;
1123+
request->theTrace = signal->getTrace();
1124+
1125+
request->par.append.buf = (const char *)(tWA + offset);
1126+
request->par.append.size = size << 2;
1127+
1128+
if (!synch_flag)
1129+
request->action = Request::append;
1130+
else
1131+
request->action = Request::append_synch;
1132+
request->m_do_bind = false;
1133+
ndbrequire(forward(openFile, request));
1134+
return;
1135+
}
11351136

11361137
error:
11371138
jam();

0 commit comments

Comments
 (0)