1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0029574: Protection of attributes retrieval against zero ID in Ocaf XML.

//Impacts attributes supporting user defined IDs.
This commit is contained in:
szy 2018-03-19 18:43:04 +03:00 committed by bugmaster
parent 9b74e2071c
commit cbc4faa980
11 changed files with 130 additions and 130 deletions

View File

@ -93,28 +93,6 @@ Standard_Boolean XmlMDataStd_BooleanArrayDriver::Paste(const XmlObjMgt_Persisten
} }
Handle(TDataStd_BooleanArray) aBooleanArray = Handle(TDataStd_BooleanArray)::DownCast(theTarget); Handle(TDataStd_BooleanArray) aBooleanArray = Handle(TDataStd_BooleanArray)::DownCast(theTarget);
aBooleanArray->Init(aFirstInd, aLastInd);
Standard_Integer length = aLastInd - aFirstInd + 1;
Handle(TColStd_HArray1OfByte) hArr = new TColStd_HArray1OfByte(0, length >> 3);
TColStd_Array1OfByte& arr = hArr->ChangeArray1();
Standard_Integer i = 0, upper = arr.Upper();
Standard_CString aValueStr = Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
for (; i <= upper; i++)
{
if (!XmlObjMgt::GetInteger(aValueStr, aValue))
{
TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve integer member"
" for BooleanArray attribute as \"")
+ aValueStr + "\"";
myMessageDriver->Send (aMessageString, Message_Fail);
return Standard_False;
}
arr.SetValue(i, (Standard_Byte) aValue);
}
aBooleanArray->SetInternalArray(hArr);
// attribute id // attribute id
Standard_GUID aGUID; Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString()); XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
@ -123,6 +101,29 @@ Standard_Boolean XmlMDataStd_BooleanArrayDriver::Paste(const XmlObjMgt_Persisten
else else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aBooleanArray->SetID(aGUID); aBooleanArray->SetID(aGUID);
aBooleanArray->Init(aFirstInd, aLastInd);
Standard_Integer length = aLastInd - aFirstInd + 1;
Handle(TColStd_HArray1OfByte) hArr = new TColStd_HArray1OfByte(0, length >> 3);
TColStd_Array1OfByte& arr = hArr->ChangeArray1();
Standard_Integer i = 0, upper = arr.Upper();
Standard_CString aValueStr = Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
for (; i <= upper; i++)
{
if (!XmlObjMgt::GetInteger(aValueStr, aValue))
{
TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve integer member"
" for BooleanArray attribute as \"")
+ aValueStr + "\"";
myMessageDriver->Send (aMessageString, Message_Warning);
aValue = 0;
}
arr.SetValue(i, (Standard_Byte) aValue);
}
aBooleanArray->SetInternalArray(hArr);
return Standard_True; return Standard_True;
} }

View File

@ -85,19 +85,29 @@ Standard_Boolean XmlMDataStd_BooleanListDriver::Paste(const XmlObjMgt_Persistent
} }
const Handle(TDataStd_BooleanList) aBooleanList = Handle(TDataStd_BooleanList)::DownCast(theTarget); const Handle(TDataStd_BooleanList) aBooleanList = Handle(TDataStd_BooleanList)::DownCast(theTarget);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_BooleanList::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aBooleanList->SetID(aGUID);
if(aLastInd == 0) aFirstInd = 0; if(aLastInd == 0) aFirstInd = 0;
if (aFirstInd == aLastInd && aLastInd > 0) if (aFirstInd == aLastInd && aLastInd > 0)
{ {
Standard_Integer anInteger; if (!XmlObjMgt::GetStringValue(anElement).GetInteger(aValue))
if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger))
{ {
TCollection_ExtendedString aMessageString = TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve integer member" TCollection_ExtendedString("Cannot retrieve integer member"
" for BooleanList attribute as \""); " for BooleanList attribute as \"");
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False; aValue = 0;
} }
aBooleanList->Append(anInteger ? Standard_True : Standard_False); aBooleanList->Append(aValue ? Standard_True : Standard_False);
} }
else if(aLastInd >= 1) else if(aLastInd >= 1)
{ {
@ -110,23 +120,13 @@ Standard_Boolean XmlMDataStd_BooleanListDriver::Paste(const XmlObjMgt_Persistent
TCollection_ExtendedString("Cannot retrieve integer member" TCollection_ExtendedString("Cannot retrieve integer member"
" for BooleanList attribute as \"") " for BooleanList attribute as \"")
+ aValueStr + "\""; + aValueStr + "\"";
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False; aValue = 0;
} }
aBooleanList->Append(aValue ? Standard_True : Standard_False); aBooleanList->Append(aValue ? Standard_True : Standard_False);
} }
} }
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_BooleanList::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aBooleanList->SetID(aGUID);
return Standard_True; return Standard_True;
} }

View File

@ -96,6 +96,17 @@ Standard_Boolean XmlMDataStd_ByteArrayDriver::Paste(const XmlObjMgt_Persistent&
Handle(TDataStd_ByteArray) aByteArray = Handle(TDataStd_ByteArray)::DownCast(theTarget); Handle(TDataStd_ByteArray) aByteArray = Handle(TDataStd_ByteArray)::DownCast(theTarget);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ByteArray::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aByteArray->SetID(aGUID);
Handle(TColStd_HArray1OfByte) hArr = new TColStd_HArray1OfByte(aFirstInd, aLastInd); Handle(TColStd_HArray1OfByte) hArr = new TColStd_HArray1OfByte(aFirstInd, aLastInd);
TColStd_Array1OfByte& arr = hArr->ChangeArray1(); TColStd_Array1OfByte& arr = hArr->ChangeArray1();
@ -109,8 +120,8 @@ Standard_Boolean XmlMDataStd_ByteArrayDriver::Paste(const XmlObjMgt_Persistent&
TCollection_ExtendedString("Cannot retrieve integer member" TCollection_ExtendedString("Cannot retrieve integer member"
" for ByteArray attribute as \"") " for ByteArray attribute as \"")
+ aValueStr + "\""; + aValueStr + "\"";
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False; aValue = 0;
} }
arr.SetValue(i, (Standard_Byte) aValue); arr.SetValue(i, (Standard_Byte) aValue);
} }
@ -138,16 +149,6 @@ Standard_Boolean XmlMDataStd_ByteArrayDriver::Paste(const XmlObjMgt_Persistent&
#endif #endif
aByteArray->SetDelta(aDelta); aByteArray->SetDelta(aDelta);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ByteArray::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aByteArray->SetID(aGUID);
return Standard_True; return Standard_True;
} }

View File

@ -115,6 +115,16 @@ Standard_Boolean XmlMDataStd_ExtStringArrayDriver::Paste
Handle(TDataStd_ExtStringArray)::DownCast(theTarget); Handle(TDataStd_ExtStringArray)::DownCast(theTarget);
aExtStringArray->Init(aFirstInd, aLastInd); aExtStringArray->Init(aFirstInd, aLastInd);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ExtStringArray::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aExtStringArray->SetID(aGUID);
// Read string values. // Read string values.
if ( !separator.Length() && anElement.hasChildNodes() ) if ( !separator.Length() && anElement.hasChildNodes() )
{ {
@ -205,16 +215,6 @@ Standard_Boolean XmlMDataStd_ExtStringArrayDriver::Paste
#endif #endif
aExtStringArray->SetDelta(aDelta); aExtStringArray->SetDelta(aDelta);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ExtStringArray::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aExtStringArray->SetID(aGUID);
return Standard_True; return Standard_True;
} }

View File

@ -87,13 +87,22 @@ Standard_Boolean XmlMDataStd_ExtStringListDriver::Paste(const XmlObjMgt_Persiste
} }
const Handle(TDataStd_ExtStringList) anExtStringList = Handle(TDataStd_ExtStringList)::DownCast(theTarget); const Handle(TDataStd_ExtStringList) anExtStringList = Handle(TDataStd_ExtStringList)::DownCast(theTarget);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ExtStringList::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
anExtStringList->SetID(aGUID);
if(aLastInd > 0) { if(aLastInd > 0) {
if (!anElement.hasChildNodes()) if (!anElement.hasChildNodes())
{ {
TCollection_ExtendedString aMessageString = TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve a list of extended strings"); TCollection_ExtendedString("Cannot retrieve a list of extended strings");
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False;
} }
LDOM_Node aCurNode = anElement.getFirstChild(); LDOM_Node aCurNode = anElement.getFirstChild();
@ -110,15 +119,6 @@ Standard_Boolean XmlMDataStd_ExtStringListDriver::Paste(const XmlObjMgt_Persiste
XmlObjMgt::GetExtendedString( *aCurElement, aValueStr ); XmlObjMgt::GetExtendedString( *aCurElement, aValueStr );
anExtStringList->Append(aValueStr); anExtStringList->Append(aValueStr);
} }
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ExtStringList::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
anExtStringList->SetID(aGUID);
return Standard_True; return Standard_True;
} }

View File

@ -89,16 +89,24 @@ Standard_Boolean XmlMDataStd_IntegerArrayDriver::Paste
Handle(TDataStd_IntegerArray)::DownCast(theTarget); Handle(TDataStd_IntegerArray)::DownCast(theTarget);
anIntArray->Init(aFirstInd, aLastInd); anIntArray->Init(aFirstInd, aLastInd);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_IntegerArray::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
anIntArray->SetID(aGUID);
if(aFirstInd == aLastInd) { if(aFirstInd == aLastInd) {
Standard_Integer anInteger; if(!XmlObjMgt::GetStringValue(anElement).GetInteger( aValue)) {
if(!XmlObjMgt::GetStringValue(anElement).GetInteger( anInteger)) {
TCollection_ExtendedString aMessageString = TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve integer member" TCollection_ExtendedString("Cannot retrieve integer member"
" for IntegerArray attribute as \""); " for IntegerArray attribute as \"");
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False; aValue = 0;
} }
anIntArray->SetValue(aFirstInd, anInteger); anIntArray->SetValue(aFirstInd, aValue);
} }
else { else {
@ -113,8 +121,8 @@ Standard_Boolean XmlMDataStd_IntegerArrayDriver::Paste
TCollection_ExtendedString("Cannot retrieve integer member" TCollection_ExtendedString("Cannot retrieve integer member"
" for IntegerArray attribute as \"") " for IntegerArray attribute as \"")
+ aValueStr + "\""; + aValueStr + "\"";
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False; aValue = 0;
} }
anIntArray->SetValue(ind, aValue); anIntArray->SetValue(ind, aValue);
} }
@ -141,16 +149,6 @@ Standard_Boolean XmlMDataStd_IntegerArrayDriver::Paste
#endif #endif
anIntArray->SetDelta(aDelta); anIntArray->SetDelta(aDelta);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_IntegerArray::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
anIntArray->SetID(aGUID);
return Standard_True; return Standard_True;
} }

View File

@ -58,8 +58,8 @@ Standard_Boolean XmlMDataStd_IntegerDriver::Paste
TCollection_ExtendedString aMessageString = TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve Integer attribute from \"") TCollection_ExtendedString("Cannot retrieve Integer attribute from \"")
+ anIntStr + "\""; + anIntStr + "\"";
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False; aValue = 0;
} }
Handle(TDataStd_Integer) anInt= Handle(TDataStd_Integer)::DownCast(theTarget); Handle(TDataStd_Integer) anInt= Handle(TDataStd_Integer)::DownCast(theTarget);

View File

@ -85,19 +85,29 @@ Standard_Boolean XmlMDataStd_IntegerListDriver::Paste(const XmlObjMgt_Persistent
} }
const Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theTarget); const Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theTarget);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_IntegerList::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
anIntList->SetID(aGUID);
if(aLastInd == 0) aFirstInd = 0; if(aLastInd == 0) aFirstInd = 0;
if (aFirstInd == aLastInd && aLastInd > 0) if (aFirstInd == aLastInd && aLastInd > 0)
{ {
Standard_Integer anInteger; if (!XmlObjMgt::GetStringValue(anElement).GetInteger(aValue))
if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger))
{ {
TCollection_ExtendedString aMessageString = TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve integer member" TCollection_ExtendedString("Cannot retrieve integer member"
" for IntegerList attribute as \""); " for IntegerList attribute as \"");
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False; aValue = 0;
} }
anIntList->Append(anInteger); anIntList->Append(aValue);
} }
else if(aLastInd >= 1) else if(aLastInd >= 1)
{ {
@ -110,23 +120,13 @@ Standard_Boolean XmlMDataStd_IntegerListDriver::Paste(const XmlObjMgt_Persistent
TCollection_ExtendedString("Cannot retrieve integer member" TCollection_ExtendedString("Cannot retrieve integer member"
" for IntegerList attribute as \"") " for IntegerList attribute as \"")
+ aValueStr + "\""; + aValueStr + "\"";
myMessageDriver->Send (aMessageString, Message_Fail); myMessageDriver->Send (aMessageString, Message_Warning);
return Standard_False; aValue = 0;
} }
anIntList->Append(aValue); anIntList->Append(aValue);
} }
} }
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_IntegerList::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
anIntList->SetID(aGUID);
return Standard_True; return Standard_True;
} }

View File

@ -89,6 +89,16 @@ Standard_Boolean XmlMDataStd_ReferenceArrayDriver::Paste(const XmlObjMgt_Persist
Handle(TDataStd_ReferenceArray) aReferenceArray = Handle(TDataStd_ReferenceArray)::DownCast(theTarget); Handle(TDataStd_ReferenceArray) aReferenceArray = Handle(TDataStd_ReferenceArray)::DownCast(theTarget);
aReferenceArray->Init(aFirstInd, aLastInd); aReferenceArray->Init(aFirstInd, aLastInd);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ReferenceArray::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aReferenceArray->SetID(aGUID);
if (!anElement.hasChildNodes()) if (!anElement.hasChildNodes())
{ {
TCollection_ExtendedString aMessageString = TCollection_ExtendedString aMessageString =
@ -153,16 +163,6 @@ Standard_Boolean XmlMDataStd_ReferenceArrayDriver::Paste(const XmlObjMgt_Persist
} }
aReferenceArray->SetValue(i, tLab); aReferenceArray->SetValue(i, tLab);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ReferenceArray::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aReferenceArray->SetID(aGUID);
return Standard_True; return Standard_True;
} }

View File

@ -88,6 +88,15 @@ Standard_Boolean XmlMDataStd_ReferenceListDriver::Paste(const XmlObjMgt_Persiste
} }
const Handle(TDataStd_ReferenceList) aReferenceList = Handle(TDataStd_ReferenceList)::DownCast(theTarget); const Handle(TDataStd_ReferenceList) aReferenceList = Handle(TDataStd_ReferenceList)::DownCast(theTarget);
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ReferenceList::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aReferenceList->SetID(aGUID);
if(aLastInd > 0) { if(aLastInd > 0) {
if (!anElement.hasChildNodes()) if (!anElement.hasChildNodes())
{ {
@ -151,15 +160,6 @@ Standard_Boolean XmlMDataStd_ReferenceListDriver::Paste(const XmlObjMgt_Persiste
} }
aReferenceList->Append(tLab); aReferenceList->Append(tLab);
} }
// attribute id
Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::AttributeIDString());
if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
aGUID = TDataStd_ReferenceList::GetID(); //default case
else
aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString())); // user defined case
aReferenceList->SetID(aGUID);
return Standard_True; return Standard_True;
} }