Fix some usages of BStackOrHeapArray.

Validates the buffer with IsValid() before actually using it. Thanks Rene!
This commit is contained in:
Jérôme Duval 2018-04-14 17:52:35 +02:00 committed by Rene Gollent
parent 43f5f35a80
commit 1fb59be1d1
6 changed files with 17 additions and 0 deletions

View File

@ -210,6 +210,11 @@ VirtioSCSIController::ExecuteRequest(scsi_ccb *ccb)
uint32 inCount = (isIn ? ccb->sg_count : 0) + 1;
uint32 outCount = (isOut ? ccb->sg_count : 0) + 1;
BStackOrHeapArray<physical_entry, 16> entries(inCount + outCount);
if (!entries.IsValid()) {
fRequest->SetStatus(SCSI_REQ_INVALID);
fRequest->Finish(false);
return B_NO_MEMORY;
}
fRequest->FillRequest(inCount, outCount, entries);
{

View File

@ -638,6 +638,8 @@ send_fragments(ipv6_protocol* protocol, struct net_route* route,
return status;
BStackOrHeapArray<uint8, 128> data(bytesLeft);
if (!data.IsValid())
return B_NO_MEMORY;
status = gBufferModule->read(buffer, headersLength, data, bytesLeft);
if (status != B_OK)
return status;

View File

@ -524,6 +524,10 @@ MixerCore::_MixThread()
chan_info_list inputChanInfos[MAX_CHANNEL_TYPES];
BStackOrHeapArray<chan_info_list, 16> mixChanInfos(fMixBufferChannelCount);
// TODO: this does not support changing output channel count
if (!mixChanInfos.IsValid()) {
ERROR("MixerCore::_MixThread mixChanInfos allocation failed\n");
return;
}
fEventTime = timeBase;
int64 framePos = 0;

View File

@ -110,6 +110,8 @@ void
VUView::_RenderLoop()
{
BStackOrHeapArray<rgb_color[2], 64> levels(fLevelCount);
if (!levels.IsValid())
return;
for (int32 i = 0; i < fLevelCount; i++) {
levels[i][0] = levels[i][1] = back_color;

View File

@ -539,6 +539,8 @@ BasicTerminalBuffer::Find(const char* _pattern, const TermPos& start,
// convert pattern to UTF8Char array
BStackOrHeapArray<UTF8Char, 64> pattern(patternByteLen);
if (!pattern.IsValid())
return false;
int32 patternLen = 0;
while (*_pattern != '\0') {
int32 charLen = UTF8Char::ByteCount(*_pattern);

View File

@ -203,6 +203,8 @@ create_path(const char *path, mode_t mode)
return EINVAL;
BStackOrHeapArray<char, 128> buffer(pathLength + 1);
if (!buffer.IsValid())
return B_NO_MEMORY;
while (++i < pathLength) {
char *slash = strchr(&path[i], '/');