]>
Commit | Line | Data |
---|---|---|
897a1d94 | 1 | // SPDX-License-Identifier: MIT |
d8f9d2af IO |
2 | /* |
3 | * Copyright (C) 2016 The Android Open Source Project | |
d8f9d2af IO |
4 | */ |
5 | ||
6 | #include "avb_kernel_cmdline_descriptor.h" | |
7 | #include "avb_util.h" | |
8 | ||
9 | bool avb_kernel_cmdline_descriptor_validate_and_byteswap( | |
10 | const AvbKernelCmdlineDescriptor* src, AvbKernelCmdlineDescriptor* dest) { | |
11 | uint64_t expected_size; | |
12 | ||
13 | avb_memcpy(dest, src, sizeof(AvbKernelCmdlineDescriptor)); | |
14 | ||
15 | if (!avb_descriptor_validate_and_byteswap((const AvbDescriptor*)src, | |
16 | (AvbDescriptor*)dest)) | |
17 | return false; | |
18 | ||
19 | if (dest->parent_descriptor.tag != AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE) { | |
20 | avb_error("Invalid tag for kernel cmdline descriptor.\n"); | |
21 | return false; | |
22 | } | |
23 | ||
24 | dest->flags = avb_be32toh(dest->flags); | |
25 | dest->kernel_cmdline_length = avb_be32toh(dest->kernel_cmdline_length); | |
26 | ||
27 | /* Check that kernel_cmdline is fully contained. */ | |
28 | expected_size = sizeof(AvbKernelCmdlineDescriptor) - sizeof(AvbDescriptor); | |
29 | if (!avb_safe_add_to(&expected_size, dest->kernel_cmdline_length)) { | |
30 | avb_error("Overflow while adding up sizes.\n"); | |
31 | return false; | |
32 | } | |
33 | if (expected_size > dest->parent_descriptor.num_bytes_following) { | |
34 | avb_error("Descriptor payload size overflow.\n"); | |
35 | return false; | |
36 | } | |
37 | ||
38 | return true; | |
39 | } |