}
+static
+BOOL
+IsValidDeviceInstanceID(
+ _In_ PWSTR pszDeviceInstanceID)
+{
+ INT nPartLength[3] = {0, 0, 0};
+ INT nLength = 0, nParts = 0;
+ PWCHAR p;
+
+ DPRINT("IsValidDeviceInstanceID(%S)\n",
+ pszDeviceInstanceID);
+
+ if (pszDeviceInstanceID == NULL)
+ {
+ DPRINT("Device instance ID is NULL!\n");
+ return FALSE;
+ }
+
+ p = pszDeviceInstanceID;
+ while (*p != UNICODE_NULL)
+ {
+ if (*p == L'\\')
+ {
+ nParts++;
+ if (nParts >= 3)
+ {
+ DPRINT("Too many separators: %d\n", nParts);
+ return FALSE;
+ }
+ }
+ else
+ {
+ nPartLength[nParts]++;
+ }
+
+ nLength++;
+ if (nLength >= MAX_DEVICE_ID_LEN)
+ {
+ DPRINT("Too long: %d\n", nLength);
+ return FALSE;
+ }
+
+ p++;
+ }
+
+ if (nParts != 2)
+ {
+ DPRINT("Invalid number of separtors: %d\n", nParts);
+ return FALSE;
+ }
+
+ if ((nPartLength[0] == 0) ||
+ (nPartLength[1] == 0) ||
+ (nPartLength[2] == 0))
+ {
+ DPRINT("Invalid part lengths: %d %d %d\n",
+ nPartLength[0], nPartLength[1], nPartLength[2]);
+ return FALSE;
+ }
+
+ DPRINT("Valid device instance ID!\n");
+
+ return TRUE;
+}
+
+
/* PUBLIC FUNCTIONS **********************************************************/
/* Function 0 */
DPRINT("PNP_ValidateDeviceInstance(%S %lx) called\n",
pDeviceID, ulFlags);
+ if (!IsValidDeviceInstanceID(pDeviceID))
+ return CR_INVALID_DEVINST;
+
if (RegOpenKeyExW(hEnumKey,
pDeviceID,
0,
DPRINT(" Relationship %ld\n", ulRelationship);
DPRINT(" DeviceId %S\n", pDeviceID);
+ if (!IsValidDeviceInstanceID(pDeviceID))
+ return CR_INVALID_DEVINST;
+
RtlInitUnicodeString(&PlugPlayData.TargetDeviceInstance,
pDeviceID);
DPRINT("PNP_GetDepth() called\n");
+ if (!IsValidDeviceInstanceID(pszDeviceID))
+ return CR_INVALID_DEVINST;
+
RtlInitUnicodeString(&PlugPlayData.DeviceInstance,
pszDeviceID);
goto done;
}
- /* FIXME: Check pDeviceID */
+ /* Check pDeviceID */
+ if (!IsValidDeviceInstanceID(pDeviceID))
+ {
+ ret = CR_INVALID_DEVINST;
+ goto done;
+ }
if (*pulLength < *pulTransferLen)
*pulLength = *pulTransferLen;
DPRINT("DataType: %lu\n", ulDataType);
DPRINT("Length: %lu\n", ulLength);
+ if (!IsValidDeviceInstanceID(pDeviceId))
+ return CR_INVALID_DEVINST;
+
switch (ulProperty)
{
case CM_DRP_DEVICEDESC:
DPRINT("PNP_GetClassInstance(%p %S %p %lu)\n",
hBinding, pDeviceId, pszClassInstance, ulLength);
+ if (!IsValidDeviceInstanceID(pDeviceId))
+ return CR_INVALID_DEVINST;
+
ulTransferLength = ulLength;
ret = PNP_GetDeviceRegProp(hBinding,
pDeviceId,
UNREFERENCED_PARAMETER(hBinding);
+ if (!IsValidDeviceInstanceID(pszDeviceID))
+ return CR_INVALID_DEVINST;
+
RtlInitUnicodeString(&PlugPlayData.DeviceInstance,
pszDeviceID);
DPRINT("PNP_GetInterfaceDeviceListSize() called\n");
+ if (!IsValidDeviceInstanceID(pszDeviceID))
+ return CR_INVALID_DEVINST;
+
RtlInitUnicodeString(&PlugPlayData.DeviceInstance,
pszDeviceID);
DPRINT("PNP_GetDeviceStatus(%p %S %p %p)\n",
hBinding, pDeviceID, pulStatus, pulProblem, ulFlags);
+ if (!IsValidDeviceInstanceID(pDeviceID))
+ return CR_INVALID_DEVINST;
+
return GetDeviceStatus(pDeviceID, pulStatus, pulProblem);
}
if (ulFlags & ~CM_REMOVE_BITS)
return CR_INVALID_FLAG;
+ if (!IsValidDeviceInstanceID(pszDeviceID))
+ return CR_INVALID_DEVINST;
+
if (pVetoType != NULL)
*pVetoType = PNP_VetoTypeUnknown;
if (ulFlags != 0)
return CR_INVALID_FLAG;
+ if (!IsValidDeviceInstanceID(pszDeviceID))
+ return CR_INVALID_DEVINST;
+
if (pVetoType != NULL)
*pVetoType = PNP_VetoTypeUnknown;
DPRINT("PNP_HwProfFlags() called\n");
+ if (!IsValidDeviceInstanceID(pDeviceID))
+ return CR_INVALID_DEVINST;
+
if (ulConfig == 0)
{
wcscpy(szKeyName,
goto done;
}
+ if (!IsValidDeviceInstanceID(pDeviceID))
+ return CR_INVALID_DEVINST;
+
if (*pulLength < *pulTransferLen)
*pulLength = *pulTransferLen;