static __maybe_unused unsigned int get_last_capsule(void)
{
u16 value16[11]; /* "CapsuleXXXX": non-null-terminated */
- char value[11], *p;
+ char value[5];
efi_uintn_t size;
unsigned long index = 0xffff;
efi_status_t ret;
+ int i;
size = sizeof(value16);
ret = efi_get_variable_int(L"CapsuleLast", &efi_guid_capsule_report,
NULL, &size, value16, NULL);
- if (ret != EFI_SUCCESS || u16_strncmp(value16, L"Capsule", 7))
+ if (ret != EFI_SUCCESS || size != 22 ||
+ u16_strncmp(value16, L"Capsule", 7))
goto err;
+ for (i = 0; i < 4; ++i) {
+ u16 c = value16[i + 7];
- p = value;
- utf16_utf8_strcpy(&p, value16);
- strict_strtoul(&value[7], 16, &index);
+ if (!c || c > 0x7f)
+ goto err;
+ value[i] = c;
+ }
+ value[4] = 0;
+ if (strict_strtoul(value, 16, &index))
+ index = 0xffff;
err:
return index;
}