release compilation should never panic on bad user input, use DEBUG for testing

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2021-02-21 16:49:09 +03:00
parent f17e66cf8b
commit 76bf6321a6
24 changed files with 332 additions and 37 deletions

View File

@ -641,7 +641,7 @@ void PreCleanupRSDT()
// trim the RSDT tail before the XSDT starts
if ((UINTN)Rsdt < (UINTN)Xsdt && (UINTN)Rsdt + Rsdt->Header.Length > (UINTN)Xsdt) {
UINTN v = ((UINTN)Xsdt - (UINTN)Rsdt) & ~3;
if ( v > MAX_UINT32 ) panic("((UINTN)Xsdt - (UINTN)Rsdt) & ~3 > MAX_UINT32");
// if ( v > MAX_UINT32 ) panic("((UINTN)Xsdt - (UINTN)Rsdt) & ~3 > MAX_UINT32");
Rsdt->Header.Length = (UINT32)v;
DBG("Cropped Rsdt->Header.Length=%d\n", (UINT32)Rsdt->Header.Length);
}

View File

@ -145,7 +145,11 @@ LogDataHubXString8(IN EFI_GUID *TypeGuid,
IN CONST CHAR16 *Name,
const XString8& s)
{
#ifdef DEBUG
if ( s.sizeInBytesIncludingTerminator() > MAX_UINT32 ) panic("LogDataHub s.length > MAX_UINT32");
#else
if ( s.sizeInBytesIncludingTerminator() > MAX_UINT32 ) return EFI_OUT_OF_RESOURCES;
#endif
return LogDataHub(TypeGuid, Name, (void*)s.c_str(), (UINT32)s.sizeInBytesIncludingTerminator());
}
@ -154,7 +158,11 @@ LogDataHubXStringW(IN EFI_GUID *TypeGuid,
IN CONST CHAR16 *Name,
const XStringW& s)
{
#ifdef DEBUG
if ( s.sizeInBytesIncludingTerminator() > MAX_UINT32 ) panic("LogDataHub s.length > MAX_UINT32");
#else
if ( s.sizeInBytesIncludingTerminator() > MAX_UINT32 ) return EFI_OUT_OF_RESOURCES;
#endif
return LogDataHub(TypeGuid, Name, (void*)s.wc_str(), (UINT32)s.sizeInBytesIncludingTerminator());
}

View File

@ -1349,8 +1349,14 @@ INT32 FindBin (UINT8 *dsdt, UINT32 len, const UINT8* bin, UINT32 N)
return -1;
}
INT32 FindBin (UINT8 *dsdt, size_t len, const XBuffer<UINT8>& bin) {
#ifdef DEBUG
if ( len > MAX_INT32 ) panic("FindBin : len > MAX_INT32"); // check against INT32, even though parameter of FindBin is UINT32. Because return value is INT32, parameter should not be > MAX_INT32
if ( bin.size() > MAX_INT32 ) panic("FindBin : bin.size() > MAX_INT32");
#else
if ( len > MAX_INT32 ) return 0;
if ( bin.size() > MAX_INT32 ) return 0;
#endif
return FindBin(dsdt, (UINT32)len, bin.data(), (UINT32)bin.size());
}

View File

@ -45,20 +45,31 @@ EFI_STATUS Self::_initialize()
EFI_STATUS Status;
Status = gBS->HandleProtocol(m_SelfImageHandle, &gEfiLoadedImageProtocolGuid, (void **)&m_SelfLoadedImage);
#ifdef DEBUG
if ( EFI_ERROR(Status) ) panic("Cannot get SelfLoadedImage");
if ( m_SelfLoadedImage->DeviceHandle == NULL ) panic("m_SelfLoadedImage->DeviceHandle == NULL");
m_SelfDevicePath = DuplicateDevicePath(DevicePathFromHandle(m_SelfLoadedImage->DeviceHandle));
if ( m_SelfDevicePath == NULL ) panic("m_SelfDevicePath == NULL");
#else
if ( EFI_ERROR(Status) ) return Status;
if ( m_SelfLoadedImage->DeviceHandle == NULL ) return EFI_NOT_FOUND;
m_SelfDevicePath = DuplicateDevicePath(DevicePathFromHandle(m_SelfLoadedImage->DeviceHandle));
if ( m_SelfDevicePath == NULL ) return EFI_NOT_FOUND;
#endif
#ifdef JIEF_DEBUG
DBG("Self DevicePath()=%ls @%llX\n", FileDevicePathToXStringW(m_SelfDevicePath).wc_str(), (uintptr_t)m_SelfLoadedImage->DeviceHandle);
#endif
Status = gBS->HandleProtocol(m_SelfLoadedImage->DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, (void**)&m_SelfSimpleVolume);
#ifdef DEBUG
if ( EFI_ERROR(Status) ) panic("Cannot get m_SelfSimpleVolume");
Status = m_SelfSimpleVolume->OpenVolume(m_SelfSimpleVolume, &m_SelfVolumeRootDir);
if ( EFI_ERROR(Status) ) panic("Cannot get m_SelfRootDir");
#else
if ( EFI_ERROR(Status) ) return Status;
Status = m_SelfSimpleVolume->OpenVolume(m_SelfSimpleVolume, &m_SelfVolumeRootDir);
if ( EFI_ERROR(Status) ) return Status;
#endif
// find the current directory
m_CloverDirFullPath = FileDevicePathToXStringW(m_SelfLoadedImage->FilePath);
@ -77,13 +88,21 @@ EFI_STATUS Self::_initialize()
if ( m_CloverDirFullPath.equalIC("\\EFI\\Boot\\BootX64.efi") ) {
m_CloverDirFullPath.takeValueFrom("\\EFI\\CLOVER\\CloverX64.efi");
}
#ifdef DEBUG
if ( m_CloverDirFullPath.isEmpty() ) panic("m_CloverDirFullPath.isEmpty()");
#else
if ( m_CloverDirFullPath.isEmpty() ) return EFI_NOT_FOUND;
#endif
m_SelfDevicePath = FileDevicePath(m_SelfLoadedImage->DeviceHandle, m_CloverDirFullPath);
m_SelfDevicePathAsXStringW = FileDevicePathToXStringW(m_SelfDevicePath);
#ifdef DEBUG
if ( m_CloverDirFullPath.lastChar() == U'\\' ) panic("m_CloverDirFullPath.lastChar() == U'\\'");
//if ( m_CloverDirFullPath.endsWith('\\') ) panic("m_CloverDirFullPath.endsWith('\\')");
#else
if ( m_CloverDirFullPath.lastChar() == U'\\' ) return EFI_NOT_FOUND;
#endif
size_t i = m_CloverDirFullPath.rindexOf(U'\\', SIZE_T_MAX-1);
if ( i != SIZE_T_MAX && i > 0 ) m_CloverDirFullPath.deleteCharsAtPos(i, SIZE_T_MAX);

View File

@ -58,9 +58,11 @@ public:
bool isInitialized() const { return m_CloverDir != NULL; }
void checkInitialized() const
{
#ifdef DEBUG
if ( !isInitialized() ) {
panic("Self in not initialized");
}
#endif
}
EFI_HANDLE getSelfImageHandle() { checkInitialized(); return m_SelfImageHandle; }

View File

@ -134,9 +134,11 @@ EFI_STATUS SelfOem::_initialize()
assert( m_OemFulPath.notEmpty() );
}
#ifdef DEBUG
if ( m_KextsDir != NULL ) panic("%s : Kexts dir != NULL.", __FUNCTION__);
#else
if ( m_KextsDir != NULL ) return EFI_SUCCESS;
#endif
if ( oemDirExists() ) {
Status = m_OemDir->Open(m_OemDir, &m_KextsDir, KEXTS_DIRNAME.wc_str(), EFI_FILE_MODE_READ, 0);
if ( !EFI_ERROR(Status) ) {
@ -200,8 +202,9 @@ EFI_STATUS SelfOem::initialize(const XString8& confName, bool isFirmwareClover,
void SelfOem::unInitialize()
{
//DBG("%s : enter.\n", __FUNCTION__);
#ifdef DEBUG
if ( m_ConfName.isEmpty() ) panic("%s : Already uninitiialized.", __FUNCTION__);
#endif
closeHandle();
m_ConfName.setEmpty();
//DBG("%s : leave.\n", __FUNCTION__);
@ -210,15 +213,20 @@ void SelfOem::unInitialize()
EFI_STATUS SelfOem::reInitialize()
{
//DBG("%s : enter.\n", __FUNCTION__);
#ifdef DEBUG
if ( m_ConfName.isEmpty() ) panic("%s : initialize() must called once first", __FUNCTION__);
#endif
closeHandle();
// No need to call _setOemPathRelToSelfDir again, but need to open m_OemDir, if it exists
if ( oemDirExists() ) {
EFI_STATUS Status = self.getCloverDir().Open(&self.getCloverDir(), &m_OemDir, m_OemPathRelToSelfDir.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) {
#ifdef DEBUG
panic("Impossible to reopen dir '%ls\\%ls', although it was opened the first time : %s", self.getCloverDirFullPath().wc_str(), m_OemPathRelToSelfDir.wc_str(), efiStrError(Status));
#else
return Status;
#endif
}
}
EFI_STATUS Status = _initialize();

View File

@ -7801,11 +7801,26 @@ const XString8& SETTINGS_DATA::getUUID(EFI_GUID *uuid)
{
if ( CustomUuid.notEmpty() ) {
EFI_STATUS Status = StrToGuidLE(CustomUuid, uuid);
#ifdef DEBUG
if ( EFI_ERROR(Status) ) panic("CustomUuid(%s) is not valid", CustomUuid.c_str()); // we panic, because it's a bug. Validity is checked when imported from settings
#else
if ( EFI_ERROR(Status) ) {
DBG("CustomUuid(%s) is not valid\n", CustomUuid.c_str());
return nullUUID;
}
#endif
return CustomUuid;
}
EFI_STATUS Status = StrToGuidLE(SmUUID, uuid);
if ( EFI_ERROR(Status) ) panic("CustomUuid(%s) is not valid", CustomUuid.c_str()); // same as before
#ifdef DEBUG
if ( EFI_ERROR(Status) ) panic("SmUUID(%s) is not valid", SmUUID.c_str()); // same as before
#else
if ( EFI_ERROR(Status) ) {
DBG("SmUUID(%s) is not valid\n", SmUUID.c_str());
return nullUUID;
}
#endif
return SmUUID;
}

View File

@ -109,13 +109,13 @@ UINT8 *Base64DecodeClover(IN CONST CHAR8 *EncodedData, UINTN EncodedSize, OUT UI
base64_init_decodestate(&state_in);
DecodedSizeInternal = base64_decode_block(EncodedData, (const int)EncodedSize, (char*) DecodedData, &state_in);
if ( DecodedSizeInternal == 0 ) {
if ( DecodedSizeInternal <= 0 ) {
FreePool(DecodedData);
DecodedData = NULL;
}
if (DecodedSize != NULL) {
if ( DecodedSizeInternal < 0 ) panic("Base64DecodeClover : DecodedSizeInternal < 0");
// if ( DecodedSizeInternal < 0 ) panic("Base64DecodeClover : DecodedSizeInternal < 0");
*DecodedSize = (UINTN)DecodedSizeInternal;
}

View File

@ -116,7 +116,11 @@ void TagArray::FreeTag()
const TagStruct* TagArray::elementAt(size_t idx) const
{
if ( idx >= _arrayContent.size() ) {
#ifdef DEBUG
panic("TagArray::elementAt(%zu) -> trying to access element at %zu, but array has only %zu element(s)\n", idx, idx, _arrayContent.size());
#else
return 0;
#endif
}
return &_arrayContent[idx];
}
@ -126,7 +130,11 @@ const TagDict* TagArray::dictElementAt(size_t idx, const XString8& currentTag) c
{
const TagStruct* tag = elementAt(idx);
if ( !tag->isDict() ) {
#ifdef DEBUG
panic("MALFORMED PLIST in '%s' : TagArray::dictElementAt(%zu) -> trying to get a dict element at %zu, but element is %s\n", currentTag.c_str(), idx, idx, tag->getTypeAsXString8().c_str());
#else
return 0;
#endif
}
return _arrayContent[idx].getDict();
}
@ -135,7 +143,11 @@ const TagArray* TagArray::arrayElementAt(size_t idx, const XString8& currentTag)
{
const TagStruct* tag = elementAt(idx);
if ( !tag->isArray() ) {
#ifdef DEBUG
panic("MALFORMED PLIST in '%s' : TagArray::dictElementAt(%zu) -> trying to get a array element at %zu, but element is %s\n", currentTag.c_str(), idx, idx, tag->getTypeAsXString8().c_str());
#else
return 0;
#endif
}
return _arrayContent[idx].getArray();
}
@ -144,7 +156,11 @@ const TagDict* TagArray::dictElementAt(size_t idx) const
{
const TagStruct* tag = elementAt(idx);
if ( !tag->isDict() ) {
#ifdef DEBUG
panic("MALFORMED PLIST : TagArray::dictElementAt(%zu) -> trying to get a dict element at %zu, but element is %s\n", idx, idx, tag->getTypeAsXString8().c_str());
#else
return 0;
#endif
}
return _arrayContent[idx].getDict();
}
@ -153,7 +169,11 @@ const TagArray* TagArray::arrayElementAt(size_t idx) const
{
const TagStruct* tag = elementAt(idx);
if ( !tag->isArray() ) {
#ifdef DEBUG
panic("MALFORMED PLIST : TagArray::dictElementAt(%zu) -> trying to get a array element at %zu, but element is %s\n", idx, idx, tag->getTypeAsXString8().c_str());
#else
return 0;
#endif
}
return _arrayContent[idx].getArray();
}

View File

@ -55,8 +55,13 @@ public:
}
void setDataValue(UINT8* data, UINTN dataLen)
{
#ifdef DEBUG
if ( data == NULL && dataLen != 0 ) panic("TagData::setDataValue() : data == NULL && dataLen != 0 ");
if ( data != NULL && dataLen == 0 ) panic("TagData::setDataValue() : data != NULL && dataLen == 0 ");
#else
if ( data == NULL && dataLen != 0 ) return;
if ( data != NULL && dataLen == 0 ) return;
#endif
dataBuffer.stealValueFrom(data, dataLen);
}

View File

@ -44,7 +44,8 @@ public:
}
void setDateValue(const XString8& xstring)
{
if ( xstring.isEmpty() ) panic("TagDate::setDateValue() : xstring.isEmpty() ");
// if ( xstring.isEmpty() ) panic("TagDate::setDateValue() : xstring.isEmpty() ");
if ( xstring.isEmpty() ) return; //do nothing rather then assign empty date
string = xstring;
}

View File

@ -114,7 +114,11 @@ bool TagDict::debugIsEqual(const TagStruct& other, const XString8& label) const
INTN TagDict::dictKeyCount() const
{
#ifdef DEBUG
if ( !isDict() ) panic("TagStruct::dictKeyCount() : !isDict() ");
#else
if ( !isDict() ) return 0;
#endif
INTN count = 0;
for (size_t tagIdx = 0 ; tagIdx + 1 < _dictContent.size() ; tagIdx++ ) { // tagIdx + 1 because a key as a last element cannot have value and is ignored. Can't do size()-1, because it's unsigned.
if ( _dictContent[tagIdx].isKey() && !_dictContent[tagIdx+1].isKey() ) { // if this key is followed by another key, it'll be ignored
@ -168,6 +172,7 @@ const TagDict* TagDict::dictPropertyForKey(const CHAR8* key) const
if ( tag == NULL ) return NULL;
if ( !tag->isDict() ) {
// panic("MALFORMED PLIST : Property value for key %s must be a dict\n", key);
// no, we will test if this is dict or something else
return NULL;
}
return tag->getDict();
@ -179,6 +184,7 @@ const TagArray* TagDict::arrayPropertyForKey(const CHAR8* key) const
if ( tag == NULL ) return NULL;
if ( !tag->isArray() ) {
// panic("MALFORMED PLIST : Property value for key %s must be an array\n", key);
// no, we will test if this is array or something else
return NULL;
}
return tag->getArray();

View File

@ -40,12 +40,16 @@ public:
*/
const XObjArray<TagStruct>& dictContent() const
{
#ifdef DEBUG
if ( !isDict() ) panic("TagDict::dictContent() : !isDict() ");
#endif
return _dictContent;
}
XObjArray<TagStruct>& dictContent()
{
#ifdef DEBUG
if ( !isDict() ) panic("TagDict::dictContent() : !isDict() ");
#endif
return _dictContent;
}
INTN dictKeyCount() const;

View File

@ -49,7 +49,11 @@ public:
}
void setKeyValue(const XString8& xstring)
{
#ifdef DEBUG
if ( xstring.isEmpty() ) panic("TagKey::setKeyValue() : xstring.isEmpty() ");
#else
if ( xstring.isEmpty() ) return; //don't change
#endif
_string = xstring;
}

View File

@ -70,7 +70,7 @@ public:
virtual void sprintf(unsigned int ident, XString8* s) const = 0;
void printf(unsigned int ident) const;
virtual void printf() const { printf(0); }
#ifdef DEBUG
virtual const TagDict* getDict() const { panic("getDict() called on a tag of type %s.", this->getTypeAsXString8().c_str()); }
virtual const TagKey* getKey() const { panic("getKey() called on a tag of type %s.", this->getTypeAsXString8().c_str()); }
virtual const TagString* getString() const { panic("getString() called on a tag of type %s.", this->getTypeAsXString8().c_str()); }
@ -90,6 +90,28 @@ public:
virtual TagData* getData() { panic("getData() called on a tag of type %s.", this->getTypeAsXString8().c_str()); }
virtual TagDate* getDate() { panic("getDate() called on a tag of type %s.", this->getTypeAsXString8().c_str()); }
virtual TagArray* getArray() { panic("getArray() called on a tag of type %s.", this->getTypeAsXString8().c_str()); }
#else
virtual const TagDict* getDict() const { return NULL; }
virtual const TagKey* getKey() const { return NULL;}
virtual const TagString* getString() const { return NULL; }
virtual const TagInt64* getInt64() const { return NULL; }
virtual const TagFloat* getFloat() const { return NULL; }
virtual const TagBool* getBool() const { return NULL; }
virtual const TagData* getData() const { return NULL; }
virtual const TagDate* getDate() const { return NULL; }
virtual const TagArray* getArray() const { return NULL; }
virtual TagDict* getDict() { return NULL; }
virtual TagKey* getKey() { return NULL; }
virtual TagString* getString() { return NULL; }
virtual TagInt64* getInt64() { return NULL; }
virtual TagFloat* getFloat() { return NULL; }
virtual TagBool* getBool() { return NULL; }
virtual TagData* getData() { return NULL; }
virtual TagDate* getDate() { return NULL; }
virtual TagArray* getArray() { return NULL; }
#endif
virtual bool isDict() const { return false; }
virtual bool isKey() const { return false; }

View File

@ -184,7 +184,9 @@ void XArray<TYPE>::CheckSize(size_t nNewSize, size_t nGrowBy)
nNewSize += nGrowBy;
m_data = (TYPE *)Xrealloc((void *)m_data, nNewSize * sizeof(TYPE), m_allocatedSize * sizeof(TYPE) );
if ( !m_data ) {
#ifdef DEBUG
panic("XArray<TYPE>::CheckSize(nNewSize=%zu, nGrowBy=%zu) : Xrealloc(%zu, %lu, %" PRIuPTR ") returned NULL. System halted\n", nNewSize, nGrowBy, m_allocatedSize, nNewSize*sizeof(TYPE), (uintptr_t)m_data);
#endif
}
// memset(&_Data[_Size], 0, (nNewSize-_Size) * sizeof(TYPE)); // Could help for debugging, but zeroing in not needed.
m_allocatedSize = nNewSize;
@ -216,11 +218,11 @@ void XArray<TYPE>::setSize(size_t l)
template<class TYPE>
TYPE &XArray<TYPE>::ElementAt(size_t index)
{
// #ifdef _DEBUG
#ifdef DEBUG
if ( index >= m_len ) {
panic("XArray::ElementAt(size_t) -> Operator [] : index > m_len");
}
// #endif
#endif
return m_data[index];
}
@ -228,11 +230,11 @@ TYPE &XArray<TYPE>::ElementAt(size_t index)
template<class TYPE>
const TYPE& XArray<TYPE>::ElementAt(size_t index) const
{
// #ifdef _DEBUG
#ifdef DEBUG
if ( index >= m_len ) {
panic("XArray::ElementAt(size_t) const -> Operator [] : index > m_len");
}
// #endif
#endif
return m_data[index];
}
@ -240,14 +242,14 @@ const TYPE& XArray<TYPE>::ElementAt(size_t index) const
template<class TYPE>
TYPE &XArray<TYPE>::ElementAt(int index)
{
// #ifdef _DEBUG
#ifdef DEBUG
if ( index < 0 ) {
panic("XArray::ElementAt(int) -> Operator [] : index < 0");
}
if ( (unsigned int)index >= m_len ) { // cast safe, index > 0
panic("XArray::ElementAt(int) -> Operator [] : index > m_len");
}
// #endif
#endif
return m_data[index];
}
@ -255,14 +257,14 @@ TYPE &XArray<TYPE>::ElementAt(int index)
template<class TYPE>
const TYPE& XArray<TYPE>::ElementAt(int index) const
{
// #ifdef _DEBUG
#ifdef DEBUG
if ( index < 0 ) {
panic("XArray::ElementAt(int) const -> Operator [] : index < 0");
}
if ( (unsigned int)index >= m_len ) { // cast ok as index > 0. Ideally cast would be like '(unsigned __typeof__(index))'
panic("XArray::ElementAt(int) const -> Operator [] : index > m_len");
}
// #endif
#endif
return m_data[index];
}

View File

@ -37,7 +37,11 @@ class XBuffer : public XBuffer_Super
template<typename IntegralType, enable_if(is_integral(IntegralType))>
void stealValueFrom(T* p, IntegralType count) {
if ( count < 0 ) {
#ifdef DEBUG
panic("XBuffer::stealValueFrom : count < 0. System halted\n");
#else
return;
#endif
}
if( _WData ) free(_WData);
Initialize(p, count, 0);
@ -61,7 +65,11 @@ class XBuffer : public XBuffer_Super
template<typename IntegralType, enable_if(is_integral(IntegralType))>
T* dataSized(IntegralType size) {
if ( size < 0 ) {
#ifdef DEBUG
panic("XBuffer::dataSized : size < 0. System halted\n");
#else
return NULL;
#endif
}
CheckSize(size, 0);
return data();
@ -80,8 +88,13 @@ class XBuffer : public XBuffer_Super
template<typename IntegralType, enable_if(is_integral(IntegralType))>
void setSize(IntegralType size) {
#ifdef DEBUG
if ( size<0 ) panic("XBuffer::setSize() -> i < 0");
if ( (unsigned_type(IntegralType))size > MAX_XSIZE ) panic("XBuffer::setSize() -> i > MAX_XSIZE");
#else
if ( size<0 ) return;
if ( (unsigned_type(IntegralType))size > MAX_XSIZE ) return;
#endif
CheckSize((unsigned_type(IntegralType))size);
XBuffer_Super::m_size = (unsigned_type(IntegralType))size;
};
@ -100,15 +113,26 @@ class XBuffer : public XBuffer_Super
template<typename IntegralType, enable_if(is_integral(IntegralType))>
T& operator [](IntegralType i)
{
#ifdef DEBUG
if (i < 0) panic("XBuffer::[] : i < 0. System halted\n");
if ( (unsigned_type(IntegralType))i >= size() ) panic("XBuffer::[] : i > _Len. System halted\n");
#else
if (i < 0) return 0;
if ( (unsigned_type(IntegralType))i >= size() ) return 0;
#endif
return _WData[(unsigned_type(IntegralType))i];
}
template<typename IntegralType, enable_if(is_integral(IntegralType))>
const T& operator [](IntegralType i) const
{
#ifdef DEBUG
if (i < 0) panic("XBuffer::[] : i < 0. System halted\n");
if ( (unsigned_type(IntegralType))i >= size() ) panic("XBuffer::[] : i > _Len. System halted\n");
#else
if (i < 0) return 0;
if ( (unsigned_type(IntegralType))i >= size() ) return 0;
#endif
return _WData[(unsigned_type(IntegralType))i];
}
@ -121,16 +145,26 @@ class XBuffer : public XBuffer_Super
template<typename IntegralType, enable_if(is_integral(IntegralType))>
void memset(unsigned char c, IntegralType count) {
#ifdef DEBUG
if (count < 0) panic("XBuffer::memset : count < 0. System halted\n");
#else
if (count < 0) return;
#endif
if ( (unsigned_type(IntegralType))count >= size() ) setSize(count);
::memset(_WData, c, count);
}
template<typename IntegralType1, typename IntegralType2, enable_if( is_integral(IntegralType1) && is_integral(IntegralType2) )>
void memsetAtPos(IntegralType1 pos, unsigned char c, IntegralType2 count) {
#ifdef DEBUG
if (pos < 0) panic("XBuffer::memset : pos < 0. System halted\n");
if (count < 0) panic("XBuffer::memset : count < 0. System halted\n");
#else
if (pos < 0) return;
if (count < 0) return;
#endif
if ( (size_t)pos + (unsigned_type(IntegralType2))count >= size() ) setSize((size_t)pos + (unsigned_type(IntegralType2))count);
::memset(_WData, c, count);
}
@ -181,7 +215,11 @@ void XBuffer<T>::Initialize(const T* p, size_t count, size_t index)
m_allocatedSize = count;
_WData = (unsigned char*)malloc(m_allocatedSize);
if ( !_WData ) {
#ifdef DEBUG
panic("XBuffer<T>::Initialize(%zu) : malloc returned NULL. System halted\n", count);
#else
return;
#endif
}
memcpy(_WData, p, count);
XRBuffer<T>::_RData = _WData;
@ -208,7 +246,12 @@ void XBuffer<T>::CheckSize(size_t nNewSize, size_t nGrowBy)
nNewSize += nGrowBy;
_WData = (unsigned char*)Xrealloc(_WData, nNewSize, m_allocatedSize);
if ( !_WData ) {
#ifdef DEBUG
panic("XBuffer<T>::CheckSize(%zu, %zu) : Xrealloc(%" PRIuPTR " %zu, %zu) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(_WData), nNewSize, m_allocatedSize);
#else
m_allocatedSize = 0;
return;
#endif
}
XRBuffer<T>::_RData = _WData;
m_allocatedSize = nNewSize;

View File

@ -63,10 +63,18 @@ class XObjArrayNC
const TYPE &ElementAt(IntegralType nIndex) const
{
if (nIndex < 0) {
#ifdef DEBUG
panic("XObjArrayNC::ElementAt() : i < 0. System halted\n");
#else
nIndex = 0;
#endif
}
if ( (unsigned_type(IntegralType))nIndex >= _Len ) {
#ifdef DEBUG
panic("XObjArrayNC::ElementAt() -> operator [] - index (%zu) greater than length (%zu)\n", (size_t)nIndex, _Len);
#else
nIndex = 0;
#endif
}
return *((TYPE *)(_Data[nIndex].Object));
}
@ -75,10 +83,19 @@ class XObjArrayNC
TYPE &ElementAt(IntegralType nIndex)
{
if (nIndex < 0) {
#ifdef DEBUG
panic("XObjArrayNC::ElementAt() : i < 0. System halted\n");
#else
nIndex = 0;
#endif
}
if ( (unsigned_type(IntegralType))nIndex >= _Len ) {
#ifdef DEBUG
panic("XObjArrayNC::ElementAt() const -> operator [] - index (%zu) greater than length (%zu)\n", (size_t)nIndex, _Len);
#else
nIndex = 0;
#endif
}
return *((TYPE *)(_Data[nIndex].Object));
}
@ -449,7 +466,12 @@ void XObjArrayNC<TYPE>::CheckSize(size_t nNewSize, size_t nGrowBy)
nNewSize += nGrowBy + 1;
_Data = (XObjArrayEntry<TYPE> *)Xrealloc((void *)_Data, sizeof(XObjArrayEntry<TYPE>) * nNewSize, sizeof(XObjArrayEntry<TYPE>) * m_allocatedSize);
if ( !_Data ) {
#ifdef DEBUG
panic("XObjArrayNC<TYPE>::CheckSize(nNewSize=%zu, nGrowBy=%zu) : Xrealloc(%zu, %zu, %" PRIuPTR ") returned NULL. System halted\n", nNewSize, nGrowBy, m_allocatedSize, sizeof(XObjArrayEntry<TYPE>) * nNewSize, (uintptr_t)_Data);
#else
m_allocatedSize = 0;
return;
#endif
}
// memset(&_Data[m_allocatedSize], 0, (nNewSize-m_allocatedSize) * sizeof(XObjArrayEntry<TYPE>));
m_allocatedSize = nNewSize;
@ -668,7 +690,11 @@ template<class TYPE>
void XObjArrayNC<TYPE>::RemoveAtIndex(size_t nIndex)
{
if ( nIndex >= XObjArrayNC<TYPE>::_Len ) {
#if defined(_DEBUG)
panic("void XObjArrayNC<TYPE>::RemoveAtIndex(size_t nIndex) : BUG nIndex (%zu) is > length(). System halted\n", nIndex);
#else
return;
#endif
}
if ( _Data[nIndex].FreeIt )
{

View File

@ -65,7 +65,11 @@ class XRBuffer
void setIndex(IntegralType Idx)
{
if (Idx < 0) {
panic("XBuffer::setIndex : Idx >= m_size. System halted\n");
#ifdef DEBUG
panic("XBuffer::setIndex : Idx < 0. System halted\n");
#else
return;
#endif
}
_Index = Idx;
}
@ -82,10 +86,18 @@ class XRBuffer
T& operator [](IntegralType i)
{
if (i < 0) {
#ifdef DEBUG
panic("XRBuffer::operator [] : i < 0. System halted\n");
#else
return 0;
#endif
}
if ( (unsigned_type(IntegralType))i >= m_size ) {
panic("XRBuffer::operator [] : index > len. System halted\n");
#ifdef DEBUG
panic("XRBuffer::operator [] : index >= m_size. System halted\n");
#else
return 0;
#endif
}
return _RData[i];
} // underflow ? overflow ?
@ -93,10 +105,18 @@ class XRBuffer
const T& operator [](IntegralType i) const
{
if (i < 0) {
#ifdef DEBUG
panic("XRBuffer::operator [] : i < 0. System halted\n");
#else
return 0;
#endif
}
if ( (unsigned_type(IntegralType))i >= m_size ) {
#ifdef DEBUG
panic("XRBuffer::operator [] : index > len. System halted\n");
#else
return 0;
#endif
}
return _RData[i];
} // underflow ? overflow ?

View File

@ -244,7 +244,12 @@ protected:
template<typename IntegralType, enable_if(is_integral(IntegralType))>
T* _data(IntegralType pos) const
{
#ifdef DEBUG
if ( pos<0 ) panic("T* data(int i) -> i < 0");
#else
if ( pos<0 ) return 0;
#endif
size_t offset = size_of_utf_string_len(m_data, (unsigned_type(IntegralType))pos); // If pos is too big, size_of_utf_string_len returns the end of the string
return m_data + offset;
}
@ -293,7 +298,11 @@ public:
char32_t char32At(IntegralType i) const
{
if (i < 0) {
#ifdef DEBUG
panic("__String<T>::char32At(size_t i) : i < 0. System halted\n");
#else
return 0;
#endif
}
size_t nb = 0;
const T *p = m_data;
@ -301,8 +310,12 @@ public:
do {
p = get_char32_from_string(p, &char32);
if (!char32) {
#ifdef DEBUG
if ( (unsigned_type(IntegralType))i == nb ) return 0; // no panic if we want to access the null terminator
panic("__String::char32At(size_t i) : i >= length(). System halted\n");
#else
return 0;
#endif
}
nb += 1;
} while (nb <= (unsigned_type(IntegralType))i);
@ -516,7 +529,13 @@ public:
template<typename IntegralType, typename O, class OtherXStringClass>
bool equalAtIC(IntegralType pos, const __String<O, OtherXStringClass>& S) const
{
#ifdef DEBUG
if ( pos < 0 ) panic("XString::equalAtIC -> i < 0");
#else
if ( pos < 0 ) return false;
#endif
if ( (unsigned_type(IntegralType))pos > length() - S.length() ) return false;
return XStringAbstract__ncompare(m_data + (unsigned_type(IntegralType))pos, S.s(), S.length(), true) == 0;
}
@ -728,7 +747,13 @@ class XStringAbstract : public __String<T, ThisXStringClass>
m_data = (T*)Xrealloc(m_data, nNewSize*sizeof(T), m_allocatedSize*sizeof(T));
}
if ( !m_data ) {
#ifdef DEBUG
panic("XStringAbstract::Alloc(%zu) : Xrealloc(%" PRIuPTR ", %lu, %zd) returned NULL. System halted\n", nNewSize, uintptr_t(m_data), nNewSize*sizeof(T), m_allocatedSize*sizeof(T));
#else
m_allocatedSize = 0;
return;
#endif
}
m_allocatedSize = nNewSize;
}
@ -822,7 +847,12 @@ public:
protected:
ThisXStringClass& takeValueFromLiteral(const T* s)
{
#ifdef DEBUG
if ( m_allocatedSize > 0 ) panic("XStringAbstract::takeValueFromLiteral -> m_allocatedSize > 0");
#else
if ( m_allocatedSize < 0 ) return 0;
#endif
m_data = (T*)s;
return *((ThisXStringClass*)this);
}
@ -848,8 +878,14 @@ public:
template<typename IntegralType, enable_if(is_integral(IntegralType))>
T* dataSized(IntegralType size)
{
#ifdef DEBUG
if ( size<0 ) panic("T* dataSized() -> i < 0");
if ( (unsigned_type(IntegralType))size > MAX_XSIZE ) panic("T* dataSized() -> i > MAX_XSIZE");
#else
if ( size<0 ) return 0;
if ( (unsigned_type(IntegralType))size > MAX_XSIZE ) return 0;
#endif
CheckSize((unsigned_type(IntegralType))size);
return __String<T, ThisXStringClass>::_data(0);
}

View File

@ -73,7 +73,7 @@ void AddSecureBootTool(void)
if (!gSettings.Boot.SecureBoot && !gSettings.Boot.SecureBootSetupMode) {
return;
}
panic("not done yet");
//panic("not done yet");
// if (gSettings.Boot.SecureBoot) {
// Entry = new REFIT_MENU_ENTRY_SECURE_BOOT();
// Entry->Title.SWPrintf("Clover Secure Boot Configuration");
@ -86,12 +86,14 @@ panic("not done yet");
//// Entry->Tag = TAG_SECURE_BOOT;
// Entry->Image = ThemeX.GetIcon(BUILTIN_ICON_FUNC_SECURE_BOOT);
// }
Entry->Row = 1;
//----- not done yet ----------
// Entry->Row = 1;
//actions
Entry->AtClick = ActionSelect;
Entry->AtDoubleClick = ActionEnter;
Entry->AtRightClick = ActionHelp;
MainMenu.AddMenuEntry(Entry);
// Entry->AtClick = ActionSelect;
// Entry->AtDoubleClick = ActionEnter;
// Entry->AtRightClick = ActionHelp;
// MainMenu.AddMenuEntry(Entry);
}

View File

@ -95,7 +95,11 @@ public:
{
if ( includeHidden ) return XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::operator [] (nIndex);
if (nIndex < 0) {
#ifdef DEBUG
panic("EntryArray::operator[] : i < 0. System halted\n");
#else
return 0;
#endif
}
size_t size = 0;
for ( size_t i=0 ; i < XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size() ; i++ ) {
@ -104,7 +108,13 @@ public:
size++;
}
}
#ifdef DEBUG
panic("EntryArray::operator[] nIndex > size()");
#else
return 0;
#endif
}
template<typename IntegralType, enable_if(is_integral(IntegralType))>
@ -112,7 +122,11 @@ public:
{
if ( includeHidden ) return XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::operator [] (nIndex);
if (nIndex < 0) {
#ifdef DEBUG
panic("EntryArray::operator[] : i < 0. System halted\n");
#else
return 0;
#endif
}
size_t size = 0;
for ( size_t i=0 ; i < XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size() ; i++ ) {
@ -121,7 +135,11 @@ public:
size++;
}
}
#ifdef DEBUG
panic("EntryArray::operator[] nIndex > size()");
#else
return 0;
#endif
}
size_t getIdx(const REFIT_ABSTRACT_MENU_ENTRY* entry)
@ -201,10 +219,18 @@ public:
template<typename IntegralType1, typename IntegralType2, enable_if(is_integral(IntegralType1) && is_integral(IntegralType2))>
void moveBefore(IntegralType1 idxFrom, IntegralType2 idxTo)
{
#ifdef DEBUG
if (idxFrom < 0) panic("EntryArray::move(IntegralType1, IntegralType2) : idxFrom < 0. System halted\n");
if ((unsigned_type(IntegralType1))idxFrom >= XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size()) panic("EntryArray::move(IntegralType1, IntegralType2) : idxFrom > size(). System halted\n");
if (idxTo < 0) panic("EntryArray::move(IntegralType1, IntegralType2) : idxTo < 0. System halted\n");
if ((unsigned_type(IntegralType2))idxTo >= XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size()) panic("EntryArray::move(IntegralType1, IntegralType2) : idxTo > size(). System halted\n");
#else
if (idxFrom < 0) return;
if ((unsigned_type(IntegralType1))idxFrom >= XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size()) return;
if (idxTo < 0) return;
if ((unsigned_type(IntegralType2))idxTo >= XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size()) return;
#endif
REFIT_ABSTRACT_MENU_ENTRY* entry = &ElementAt(idxFrom);
RemoveWithoutFreeingAtIndex(idxFrom);
@ -218,10 +244,17 @@ public:
template<typename IntegralType1, typename IntegralType2, enable_if(is_integral(IntegralType1) && is_integral(IntegralType2))>
void moveAfter(IntegralType1 idxFrom, IntegralType2 idxTo)
{
#ifdef DEBUG
if (idxFrom < 0) panic("EntryArray::move(IntegralType1, IntegralType2) : idxFrom < 0. System halted\n");
if ((unsigned_type(IntegralType1))idxFrom >= XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size()) panic("EntryArray::move(IntegralType1, IntegralType2) : idxFrom > size(). System halted\n");
if (idxTo < 0) panic("EntryArray::move(IntegralType1, IntegralType2) : idxTo < 0. System halted\n");
if ((unsigned_type(IntegralType2))idxTo >= XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size()) panic("EntryArray::move(IntegralType1, IntegralType2) : idxTo > size(). System halted\n");
#else
if (idxFrom < 0) return;
if ((unsigned_type(IntegralType1))idxFrom >= XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size()) return;
if (idxTo < 0) return;
if ((unsigned_type(IntegralType2))idxTo >= XObjArray<REFIT_ABSTRACT_MENU_ENTRY>::size()) return;
#endif
REFIT_ABSTRACT_MENU_ENTRY* entry = &ElementAt(idxFrom);
RemoveWithoutFreeingAtIndex(idxFrom);

View File

@ -4736,7 +4736,11 @@ static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecompressSetting
if(!error) {
if(decoded.size) {
info->iccp_profile_size = (__typeof__(info->iccp_profile_size))decoded.size; // Unsafe cast
#ifdef DEBUG
if ( info->iccp_profile_size != decoded.size ) panic("info->iccp_profile_size != decoded.size"); // Check the cast
#else
if ( info->iccp_profile_size != decoded.size ) return 100; /*invalid ICC profile size*/
#endif
info->iccp_profile = (unsigned char*)lodepng_malloc(decoded.size);
if(info->iccp_profile) {
lodepng_memcpy(info->iccp_profile, decoded.data, decoded.size);

View File

@ -576,7 +576,11 @@ size_t setKextAtPos(XObjArray<SIDELOAD_KEXT>* kextArrayPtr, const XString8& kext
for (size_t kextIdx = 0 ; kextIdx < kextArray.size() ; kextIdx++ ) {
if ( kextArray[kextIdx].FileName.contains(kextName) ) {
#ifdef DEBUG
if ( pos >= kextArray.size() ) panic("pos >= kextArray.size()");
#else
//it is impossible
#endif
if ( pos == kextIdx ) return pos+1;
if ( pos > kextIdx ) pos -= 1;
SIDELOAD_KEXT* kextToMove = &kextArray[kextIdx];
@ -595,7 +599,7 @@ static XStringW getDriversPath()
if (FileExists(&self.getCloverDir(), L"drivers\\BIOS")) {
return L"drivers\\BIOS"_XSW;
} else {
return L"drivers64"_XSW;
return L"drivers64"_XSW; //backward compatibility
}
} else
if (FileExists(&self.getCloverDir(), L"drivers\\UEFI")) {
@ -608,6 +612,7 @@ static XStringW getDriversPath()
#endif
}
#ifdef DEBUG
void debugStartImageWithOC()
{
MsgLog("debugStartImageWithOC\n");
@ -677,7 +682,7 @@ MsgLog("debugStartImageWithOC\n");
MsgLog("debugStartImageWithOC : not found\n");
}
}
#endif
void LOADER_ENTRY::DelegateKernelPatches()
{
XObjArray<KEXT_PATCH> selectedPathArray;
@ -815,7 +820,11 @@ void LOADER_ENTRY::StartLoader()
EFI_HANDLE Interface = NULL;
Status = gBS->LocateProtocol(&gAptioMemoryFixProtocolGuid, NULL, &Interface );
if ( !EFI_ERROR(Status) ) {
#ifdef DEBUG
panic("Remove AptioMemoryFix.efi and OcQuirks.efi from your driver folder\n");
#else
DBG("Remove AptioMemoryFix.efi and OcQuirks.efi from your driver folder\n");
#endif
}
}