mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
libfdt: Make fdt_check_header() more thorough
Currently fdt_check_header() performs only some rudimentary checks, which is not really what the name suggests. This strengthens fdt_check_header() to check as much about the blob as is possible from the header alone: as well as checking the magic number and version, it checks that the total size is sane, and that all the sub-blocks within the blob lie within the total size. * This broadens the meaning of FDT_ERR_TRUNCATED to cover all sorts of improperly terminated blocks as well as just a structure block without FDT_END. * This makes fdt_check_header() only succeed on "complete" blobs, not in-progress sequential write blobs. The only reason this didn't fail before was that this function used to be called by many RO functions which are supposed to also work on incomplete SW blobs. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
899d6fad93
commit
eb890c0f77
7 changed files with 198 additions and 8 deletions
|
@ -90,8 +90,9 @@
|
|||
|
||||
/* Error codes: codes for bad device tree blobs */
|
||||
#define FDT_ERR_TRUNCATED 8
|
||||
/* FDT_ERR_TRUNCATED: Structure block of the given device tree
|
||||
* ends without an FDT_END tag. */
|
||||
/* FDT_ERR_TRUNCATED: FDT or a sub-block is improperly
|
||||
* terminated (overflows, goes outside allowed bounds, or
|
||||
* isn't properly terminated). */
|
||||
#define FDT_ERR_BADMAGIC 9
|
||||
/* FDT_ERR_BADMAGIC: Given "device tree" appears not to be a
|
||||
* device tree at all - it is missing the flattened device
|
||||
|
@ -244,18 +245,20 @@ fdt_set_hdr_(size_dt_struct);
|
|||
#undef fdt_set_hdr_
|
||||
|
||||
/**
|
||||
* fdt_check_header - sanity check a device tree or possible device tree
|
||||
* fdt_check_header - sanity check a device tree header
|
||||
* @fdt: pointer to data which might be a flattened device tree
|
||||
*
|
||||
* fdt_check_header() checks that the given buffer contains what
|
||||
* appears to be a flattened device tree with sane information in its
|
||||
* header.
|
||||
* appears to be a flattened device tree, and that the header contains
|
||||
* valid information (to the extent that can be determined from the
|
||||
* header alone).
|
||||
*
|
||||
* returns:
|
||||
* 0, if the buffer appears to contain a valid device tree
|
||||
* -FDT_ERR_BADMAGIC,
|
||||
* -FDT_ERR_BADVERSION,
|
||||
* -FDT_ERR_BADSTATE, standard meanings, as above
|
||||
* -FDT_ERR_BADSTATE,
|
||||
* -FDT_ERR_TRUNCATED, standard meanings, as above
|
||||
*/
|
||||
int fdt_check_header(const void *fdt);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue