未验证 提交 fe0f600e 编写于 作者: R Ravi Kumar 提交者: GitHub

Port Access violation occurring in...

Port Access violation occurring in System.DirectoryServices.ActiveDirectory.ForestTrustRelationshipInformation fix from .netfx to .net-core (#66726)

* foresttrust port from dotnetfx

* fixed nullable reference error
上级 631389fb
......@@ -15,6 +15,7 @@ public class ForestTrustRelationshipInformation : TrustRelationshipInformation
private StringCollection _excludedNames = new StringCollection();
private ForestTrustDomainInfoCollection _domainInfo = new ForestTrustDomainInfoCollection();
private ArrayList _binaryData = new ArrayList();
private ArrayList _binaryRecordType = new ArrayList();
private Hashtable _excludedNameTime = new Hashtable();
private ArrayList _binaryDataTime = new ArrayList();
internal bool retrieved;
......@@ -97,20 +98,14 @@ public void Save()
int toplevelNamesCount = TopLevelNames.Count;
int excludedNamesCount = ExcludedTopLevelNames.Count;
int trustedDomainCount = TrustedDomainInformation.Count;
int binaryDataCount = 0;
int binaryDataCount = _binaryData.Count;
checked
{
count += toplevelNamesCount;
count += excludedNamesCount;
count += trustedDomainCount;
if (_binaryData.Count != 0)
{
binaryDataCount = _binaryData.Count;
// for the ForestTrustRecordTypeLast record
count++;
count += binaryDataCount;
}
count += binaryDataCount;
// allocate the memory for all the records
records = Marshal.AllocHGlobal(count * IntPtr.Size);
......@@ -212,43 +207,31 @@ public void Save()
currentCount++;
}
if (binaryDataCount > 0)
for (int i = 0; i < binaryDataCount; i++)
{
// now begin to construct ForestTrustRecordTypeLast
LSA_FOREST_TRUST_RECORD lastRecord = new LSA_FOREST_TRUST_RECORD();
lastRecord.Flags = 0;
lastRecord.ForestTrustType = LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustRecordTypeLast;
LSA_FOREST_TRUST_RECORD record = new LSA_FOREST_TRUST_RECORD();
record.Flags = 0;
record.Time = (LARGE_INTEGER)_binaryDataTime[i]!;
record.Data.Length = ((byte[])_binaryData[i]!).Length;
record.ForestTrustType = (LSA_FOREST_TRUST_RECORD_TYPE)_binaryRecordType[i]!;
record.Data = new LSA_FOREST_TRUST_BINARY_DATA();
if (record.Data.Length == 0)
{
record.Data.Buffer = (IntPtr)0;
}
else
{
record.Data.Buffer = Marshal.AllocHGlobal(record.Data.Length);
ptrList.Add(record.Data.Buffer);
Marshal.Copy((byte[])_binaryData[i]!, 0, record.Data.Buffer, record.Data.Length);
}
tmpPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LSA_FOREST_TRUST_RECORD)));
ptrList.Add(tmpPtr);
Marshal.StructureToPtr(lastRecord, tmpPtr, false);
Marshal.WriteIntPtr(records, IntPtr.Size * currentCount, tmpPtr);
currentCount++;
for (int i = 0; i < binaryDataCount; i++)
{
// now begin to construct excluded top leve name record
LSA_FOREST_TRUST_RECORD record = new LSA_FOREST_TRUST_RECORD();
record.Flags = 0;
record.Time = (LARGE_INTEGER)_binaryDataTime[i]!;
record.Data.Length = ((byte[])_binaryData[i]!).Length;
if (record.Data.Length == 0)
{
record.Data.Buffer = (IntPtr)0;
}
else
{
record.Data.Buffer = Marshal.AllocHGlobal(record.Data.Length);
ptrList.Add(record.Data.Buffer);
Marshal.Copy((byte[])_binaryData[i]!, 0, record.Data.Buffer, record.Data.Length);
}
tmpPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LSA_FOREST_TRUST_RECORD)));
ptrList.Add(tmpPtr);
Marshal.StructureToPtr(record, tmpPtr, false);
Marshal.StructureToPtr(record, tmpPtr, false);
Marshal.WriteIntPtr(records, IntPtr.Size * currentCount, tmpPtr);
Marshal.WriteIntPtr(records, IntPtr.Size * currentCount, tmpPtr);
currentCount++;
}
currentCount++;
}
// finally construct the LSA_FOREST_TRUST_INFORMATION
......@@ -350,6 +333,7 @@ private void GetForestTrustInfoHelper()
ArrayList tmpBinaryData = new ArrayList();
Hashtable tmpExcludedNameTime = new Hashtable();
ArrayList tmpBinaryDataTime = new ArrayList();
ArrayList tmpBinaryRecordType = new ArrayList();
try
{
......@@ -412,16 +396,15 @@ private void GetForestTrustInfoHelper()
}
else if (record.ForestTrustType == LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustDomainInfo)
{
IntPtr myPtr = IntPtr.Add(addr, 16);
Marshal.PtrToStructure(myPtr, record.DomainInfo!);
ForestTrustDomainInformation dom = new ForestTrustDomainInformation(record.Flags, record.DomainInfo!, record.Time);
tmpDomainInformation.Add(dom);
}
else if (record.ForestTrustType == LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustRecordTypeLast)
{
// enumeration is done, but we might still have some unrecognized entries after that
continue;
}
else
{
IntPtr myPtr = IntPtr.Add(addr, 16);
Marshal.PtrToStructure(myPtr, record.Data);
int length = record.Data.Length;
byte[] byteArray = new byte[length];
if ((record.Data.Buffer != (IntPtr)0) && (length != 0))
......@@ -430,6 +413,7 @@ private void GetForestTrustInfoHelper()
}
tmpBinaryData.Add(byteArray);
tmpBinaryDataTime.Add(record.Time);
tmpBinaryRecordType.Add((int)record.ForestTrustType);
}
}
}
......@@ -446,6 +430,7 @@ private void GetForestTrustInfoHelper()
_binaryData = tmpBinaryData;
_excludedNameTime = tmpExcludedNameTime;
_binaryDataTime = tmpBinaryDataTime;
_binaryRecordType = tmpBinaryRecordType;
// mark it as retrieved
retrieved = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册