if (!EFI_ERROR (Status)) {\r
PageLength = (SupportedVpdPages->PageLength2 << 8)\r
| SupportedVpdPages->PageLength1;\r
+\r
+ //\r
+ // Sanity checks for coping with broken devices\r
+ //\r
+ if (PageLength > sizeof SupportedVpdPages->SupportedVpdPageList) {\r
+ DEBUG ((EFI_D_WARN,\r
+ "%a: invalid PageLength (%u) in Supported VPD Pages page\n",\r
+ __FUNCTION__, (UINT32)PageLength));\r
+ PageLength = 0;\r
+ }\r
+\r
+ if ((PageLength > 0) &&\r
+ (SupportedVpdPages->SupportedVpdPageList[0] !=\r
+ EFI_SCSI_PAGE_CODE_SUPPORTED_VPD)) {\r
+ DEBUG ((EFI_D_WARN,\r
+ "%a: Supported VPD Pages page doesn't start with code 0x%02x\n",\r
+ __FUNCTION__, EFI_SCSI_PAGE_CODE_SUPPORTED_VPD));\r
+ PageLength = 0;\r
+ }\r
+\r
+ //\r
+ // Locate the code for the Block Limits VPD page\r
+ //\r
for (Index = 0; Index < PageLength; Index++) {\r
+ //\r
+ // Sanity check\r
+ //\r
+ if ((Index > 0) &&\r
+ (SupportedVpdPages->SupportedVpdPageList[Index] <=\r
+ SupportedVpdPages->SupportedVpdPageList[Index - 1])) {\r
+ DEBUG ((EFI_D_WARN,\r
+ "%a: non-ascending code in Supported VPD Pages page @ %u\n",\r
+ __FUNCTION__, Index));\r
+ Index = 0;\r
+ PageLength = 0;\r
+ break;\r
+ }\r
+\r
if (SupportedVpdPages->SupportedVpdPageList[Index] == EFI_SCSI_PAGE_CODE_BLOCK_LIMITS_VPD) {\r
break;\r
}\r