编辑:完整的源代码被请求。下面是一个用于复制bug的基本实现。内容枚举将被删除,但是,无论如何,第一个对象调用上的崩溃锁定。在本例中,WPD_DEVICE_OBJECT_ID对象。
与CPP的链接 (Bug开始于第103行)
链接到QMAKE.PRO (我正在使用Qt)
在我的项目中,我使用WPD API读取移动设备的内容。我遵循API到tee,并成功地实现了内容枚举。
但是,如果连接了USB驱动器,WPD有时也会将其检测为设备。无论如何,我的程序将继续并开始内容枚举。我不想这样。我只想列举一下移动设备。
问题是,在内容枚举期间,当我的程序试图检索USB驱动器上的对象的属性时,它会崩溃。以下是坠机细节:
Problem Event Name: BEX
Application Name: UniversalMC.exe
Application Version: 0.0.0.0
Application Timestamp: 5906a8a3
Fault Module Name: MSVCR100.dll
Fault Module Version: 10.0.40219.325
Fault Module Timestamp: 4df2be1e
Exception Offset: 0008af3e
Exception Code: c0000417
Exception Data: 00000000
OS Version: 6.1.7601.2.1.0.768.3
Locale ID: 1033
Additional Information 1: 185e
Additional Information 2: 185ef2beb7eb77a8e39d1dada57d0d11
Additional Information 3: a852
Additional Information 4: a85222a7fc0721be22726bd2ca6bc946崩溃发生在此调用中:
hr = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &objectName);hr返回失败,然后我的程序崩溃。
经过一些研究,我发现异常代码c0000417意味着发生了缓冲区溢出?如果我错了,请纠正我,但是,这是WPD中的漏洞吗?如果是这样的话,我怎么能提前发现这个设备不是移动设备呢?
耽误您时间,实在对不起!
发布于 2017-05-21 04:14:02
最后我付钱让人帮我找出问题所在。
问题是根对象(WPD_DEVICE_OBJECT_ID)无论如何都不会返回对象名(对于所有设备都不是真)。
解决方案是简单地从根对象开始内容枚举,并且只检查其子对象的名称。在我最初的实现中,我假设每个对象都有一个名称,但显然并非如此。根对象是异常。
下面是一个片段:
CComPtr<IEnumPortableDeviceObjectIDs> pEnumObjectIDs;
// Print the object identifier being used as the parent during enumeration.
//qDebug("%ws\n",pszObjectID);
// Get an IEnumPortableDeviceObjectIDs interface by calling EnumObjects with the
// specified parent object identifier.
hr = pContent->EnumObjects(0, // Flags are unused
WPD_DEVICE_OBJECT_ID, // Starting from the passed in object
NULL, // Filter is unused
&pEnumObjectIDs);
// Enumerate content starting from the "DEVICE" object.
if (SUCCEEDED(hr))
{
// Loop calling Next() while S_OK is being returned.
while(hr == S_OK)
{
DWORD cFetched = 0;
PWSTR szObjectIDArray[NUM_OBJECTS_TO_REQUEST] = {0};
hr = pEnumObjectIDs->Next(NUM_OBJECTS_TO_REQUEST, // Number of objects to request on each NEXT call
szObjectIDArray, // Array of PWSTR array which will be populated on each NEXT call
&cFetched); // Number of objects written to the PWSTR array
if (SUCCEEDED(hr))
{
// Traverse the results of the Next() operation and recursively enumerate
// Remember to free all returned object identifiers using CoTaskMemFree()
for (DWORD dwIndex = 0; dwIndex < cFetched; dwIndex++)
{
//RECURSIVE CONTENT ENUMERATION CONTINUES HERE
//OBJECT NAME CHECKING CONTINUES IN THE RECURSIVE FUNCTION
// Free allocated PWSTRs after the recursive enumeration call has completed.
CoTaskMemFree(szObjectIDArray[dwIndex]);
szObjectIDArray[dwIndex] = NULL;
}
}
}
}解决方案正是示例项目显示要做的,但是,我犯了一个错误,就是检查根对象的名称。所以别那么做。
发布于 2017-12-20 14:14:35
如果没有“原始文件名”,则获取对象名称。
hr = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &objectName);
if(FAILED(hr)) {
hr = pObjectProperties->GetStringValue(WPD_OBJECT_NAME, &objectName);
}https://stackoverflow.com/questions/43713994
复制相似问题