Improve data string check (must be hex digits).

This commit is contained in:
jief666 2022-04-14 18:02:47 +02:00
parent c650742514
commit 016794a82e

View File

@ -320,13 +320,19 @@ XBool XmlData::parseFromXmlLite(XmlLiteParser* xmlLiteParser, const XString8& xm
#ifdef JIEF_DEBUG #ifdef JIEF_DEBUG
if ( xmlPath.startWithOrEqualToIC("/KernelAndKextPatches/KernelToPatch[0]/Find") ) { if ( xmlPath.startWithOrEqualToIC("/KernelAndKextPatches/KernelToPatch[0]/Find") ) {
int i=0; (void)i; NOP;
} }
#endif #endif
XmlParserPosition pos = xmlLiteParser->getPosition(); XmlParserPosition pos = xmlLiteParser->getPosition();
RETURN_IF_FALSE( xmlLiteParser->getSimpleTag(&tag, &tagLength, &value, &valueLength, NULL, generateErrors) ); RETURN_IF_FALSE( xmlLiteParser->getSimpleTag(&tag, &tagLength, &value, &valueLength, NULL, generateErrors) );
if ( strnIsEqual(tag, tagLength, "string") ) { if ( strnIsEqual(tag, tagLength, "string") ) {
for ( size_t i=0 ; i<valueLength ; ++i ) {
if ( !IS_HEX(value[i]) && !IS_DIGIT(value[i]) ) {
xmlLiteParser->addError(generateErrors, S8Printf("Expecting hex digits following key '%s' at line %d.", xmlPath.c_str(), pos.getLine()));
return false;
}
}
size_t allocatedSize = valueLength/2; // number of hex digits size_t allocatedSize = valueLength/2; // number of hex digits
uint8_t *Data = (uint8_t*)malloc(allocatedSize); uint8_t *Data = (uint8_t*)malloc(allocatedSize);
size_t hexLen = hex2bin(value, valueLength, Data, allocatedSize); size_t hexLen = hex2bin(value, valueLength, Data, allocatedSize);