template <class EventHandler>
const UInt_t AliMUONTriggerDDLDecoder<EventHandler>::fgkEndOfLocal = 0xCAFEFADE;
template <class EventHandler>
-const UInt_t AliMUONTriggerDDLDecoder<EventHandler>::fgkDisableWord = 0x010CDEAD;
+const UInt_t AliMUONTriggerDDLDecoder<EventHandler>::fgkDisableWord = 0x10CADEAD;
template <class EventHandler>
const UInt_t AliMUONTriggerDDLDecoder<EventHandler>::fgkDarcDefaultType = 0x6;
template <class EventHandler>
// Mark the DARC header, but check that we do not overrun the buffer.
const UInt_t* darcHeader = reinterpret_cast<const UInt_t*>(current);
current += sizeof(UInt_t);
- if (current > end)
+ if (current > end or current < start)
{
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
// DARC header set to 01b. Everything else is a software trigger
// of some sort.
if (reinterpret_cast<const UChar_t*>(expectedEndOfDarc+1) <= end and
+ reinterpret_cast<const UChar_t*>(expectedEndOfDarc+1) > start and
EventHandler::GetDarcEventType(*darcHeader) != 0x1
and *expectedEndOfDarc == fgkEndOfDarc
)
{
darcScalars = reinterpret_cast<const AliMUONDarcScalarsStruct*>(current);
current += sizeof(AliMUONDarcScalarsStruct);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
fHandler.OnError(EventHandler::kNoDarcScalars, darcScalars);
// Now check that the end of DARC header marker is OK.
const UInt_t* endOfDarc = reinterpret_cast<const UInt_t*>(current);
current += sizeof(UInt_t);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
fHandler.OnError(EventHandler::kNoEndOfDarc, endOfDarc);
const AliMUONGlobalHeaderStruct* globalHeader =
reinterpret_cast<const AliMUONGlobalHeaderStruct*>(current);
current += sizeof(AliMUONGlobalHeaderStruct);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
fHandler.OnError(EventHandler::kNoGlobalHeader, globalHeader);
{
globalScalars = reinterpret_cast<const AliMUONGlobalScalarsStruct*>(current);
current += sizeof(AliMUONGlobalScalarsStruct);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
fHandler.OnError(EventHandler::kNoGlobalScalars, globalScalars);
// Now check that the end of global header marker is OK.
const UInt_t* endOfGlobal = reinterpret_cast<const UInt_t*>(current);
current += sizeof(UInt_t);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
fHandler.OnError(EventHandler::kNoEndOfGlobal, endOfGlobal);
reinterpret_cast<const AliMUONRegionalHeaderStruct*>(current);
current += sizeof(AliMUONRegionalHeaderStruct);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return;
+
// So we only got part of a regional header, nothing to do but
// report the error and exit.
fHandler.OnError(EventHandler::kNoRegionalHeader, regionalHeader);
{
regionalScalars = reinterpret_cast<const AliMUONRegionalScalarsStruct*>(current);
current += sizeof(AliMUONRegionalScalarsStruct);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
fHandler.OnError(EventHandler::kNoRegionalScalars, regionalScalars);
// Now check that the end of regional header marker is OK.
const UInt_t* endOfRegional = reinterpret_cast<const UInt_t*>(current);
current += sizeof(UInt_t);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
fHandler.OnError(EventHandler::kNoEndOfRegional, endOfRegional);
// Tell the handler that we have a new regional block and decode it.
// When done, tell the handler again.
+ // We call both versions of OnNewRegionalStruct so that user event
+ // handlers can implement the one they prefer to use.
const UChar_t* startOfLocals = current;
fHandler.OnNewRegionalStruct(regionalHeader, regionalScalars, startOfLocals);
+ fHandler.OnNewRegionalStructV2(iReg, regionalHeader, regionalScalars, startOfLocals);
current = DecodeLocalStructs(current, end, scalarEvent);
fHandler.OnEndOfRegionalStruct(regionalHeader, regionalScalars, startOfLocals);
+ fHandler.OnEndOfRegionalStructV2(iReg, regionalHeader, regionalScalars, startOfLocals);
}
// Now just check that there is no extra rubbish at the end of the DDL.
reinterpret_cast<const AliMUONLocalInfoStruct*>(current);
current += sizeof(AliMUONLocalInfoStruct);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return end;
+
// So we only got part of a local structure, nothing to do but
// report the error and exit.
fHandler.OnError(EventHandler::kNoLocalStruct, localStruct);
{
localScalars = reinterpret_cast<const AliMUONLocalScalarsStruct*>(current);
current += sizeof(AliMUONLocalScalarsStruct);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return end;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already.
fHandler.OnError(EventHandler::kNoLocalScalars, localScalars);
// Now check that the end of regional header marker is OK.
const UInt_t* endOfLocal = reinterpret_cast<const UInt_t*>(current);
current += sizeof(UInt_t);
- if (current > end)
+ if (current > end or current < start)
{
+ // If we overflowed the pointer and already had an error then
+ // we are clearly lost so just stop decoding before we segfault.
+ if (current < start and fHadError) return end;
+
// Indicate we had an error and stop the decoding because we
// hit the end of the buffer already. We can however signal that
// we got a local structure, because the buffer contains enough
}
}
+ // Call both handlers for local structures so that the user decoder event
+ // handler class can implement the one it prefers to use.
fHandler.OnLocalStruct(localStruct, localScalars);
+ fHandler.OnLocalStructV2(iLocal, localStruct, localScalars);
}
return current;
/// \returns The location of the first occurance of key in the buffer,
/// otherwise NULL is returned if nothing was found.
+ if (end + sizeof(UInt_t) < start) return NULL; // check for pointer overflow.
const UChar_t* current = start;
while (current + sizeof(UInt_t) <= end)
{