2 * Copyright (C) 2016 The Android Open Source Project
4 * SPDX-License-Identifier: MIT
7 #include "avb_chain_partition_descriptor.h"
10 bool avb_chain_partition_descriptor_validate_and_byteswap(
11 const AvbChainPartitionDescriptor* src, AvbChainPartitionDescriptor* dest) {
12 uint64_t expected_size;
14 avb_memcpy(dest, src, sizeof(AvbChainPartitionDescriptor));
16 if (!avb_descriptor_validate_and_byteswap((const AvbDescriptor*)src,
17 (AvbDescriptor*)dest))
20 if (dest->parent_descriptor.tag != AVB_DESCRIPTOR_TAG_CHAIN_PARTITION) {
21 avb_error("Invalid tag for chain partition descriptor.\n");
25 dest->rollback_index_location = avb_be32toh(dest->rollback_index_location);
26 dest->partition_name_len = avb_be32toh(dest->partition_name_len);
27 dest->public_key_len = avb_be32toh(dest->public_key_len);
29 if (dest->rollback_index_location < 1) {
30 avb_error("Invalid rollback index location value.\n");
34 /* Check that partition_name and public_key are fully contained. */
35 expected_size = sizeof(AvbChainPartitionDescriptor) - sizeof(AvbDescriptor);
36 if (!avb_safe_add_to(&expected_size, dest->partition_name_len) ||
37 !avb_safe_add_to(&expected_size, dest->public_key_len)) {
38 avb_error("Overflow while adding up sizes.\n");
41 if (expected_size > dest->parent_descriptor.num_bytes_following) {
42 avb_error("Descriptor payload size overflow.\n");