On 1/27/23 05:07, Jean-Philippe Brucker wrote:
+static int rme_parse_rpv(uint8_t *out, const char *in, Error **errp) +{ + int ret; + size_t in_len = strlen(in); + + /* Two chars per byte */ + if (in_len > KVM_CAP_ARM_RME_RPV_SIZE * 2) { + error_setg(errp, "Realm Personalization Value is too large"); + return -E2BIG; + } + + /* + * Parse as big-endian hexadecimal number (most significant byte on the + * left), store little-endian, zero-padded on the right. + */ + while (in_len) { + /* + * Do the lower nibble first to catch invalid inputs such as '2z', and + * to handle the last char. + */ + in_len--; + ret = sscanf(in + in_len, "%1hhx", out); + if (ret != 1) { + error_setg(errp, "Invalid Realm Personalization Value"); + return -EINVAL; + } + if (!in_len) { + break; + } + in_len--; + ret = sscanf(in + in_len, "%2hhx", out++); + if (ret != 1) { + error_setg(errp, "Invalid Realm Personalization Value"); + return -EINVAL; + } + }
I think this parsing is late, and should be done
+static void rme_set_rpv(Object *obj, const char *value, Error **errp) +{ + RmeGuest *guest = RME_GUEST(obj); + + g_free(guest->personalization_value); + guest->personalization_value = g_strdup(value); +}
here, when the value is set, so that the error is produced at the proper time. r~