unsigned int i;
int rc;
- if ( rec->length < sizeof(*hdr)
- || rec->length < sizeof(*hdr) + hdr->count * sizeof(*entry) )
+ if ( rec->length < sizeof(*hdr) )
{
- ERROR("hvm_params record is too short");
+ ERROR("HVM_PARAMS record truncated: length %u, header size %zu",
+ rec->length, sizeof(*hdr));
return -1;
}
+ if ( rec->length != (sizeof(*hdr) + hdr->count * sizeof(*entry)) )
+ {
+ ERROR("HVM_PARAMS record truncated: header %zu, count %u, "
+ "expected len %zu, got %u",
+ sizeof(*hdr), hdr->count, hdr->count * sizeof(*entry),
+ rec->length);
+ return -1;
+ }
+
+ /*
+ * Tolerate empty records. Older sending sides used to accidentally
+ * generate them.
+ */
+ if ( hdr->count == 0 )
+ {
+ DBGPRINTF("Skipping empty HVM_PARAMS record\n");
+ return 0;
+ }
+
for ( i = 0; i < hdr->count; i++, entry++ )
{
switch ( entry->index )
}
/* Confirm that there is a complete header. */
- if ( rec->length <= sizeof(*vhdr) )
+ if ( rec->length < sizeof(*vhdr) )
{
- ERROR("%s record truncated: length %u, min %zu",
- rec_name, rec->length, sizeof(*vhdr) + 1);
+ ERROR("%s record truncated: length %u, header size %zu",
+ rec_name, rec->length, sizeof(*vhdr));
goto out;
}
blobsz = rec->length - sizeof(*vhdr);
+ /*
+ * Tolerate empty records. Older sending sides used to accidentally
+ * generate them.
+ */
+ if ( blobsz == 0 )
+ {
+ DBGPRINTF("Skipping empty %s record for vcpu %u\n",
+ rec_type_to_str(rec->type), vhdr->vcpu_id);
+ goto out;
+ }
+
/* Check that the vcpu id is within range. */
if ( vhdr->vcpu_id >= ctx->x86_pv.restore.nr_vcpus )
{