libfdt: Improve sequential write state checking

When creating a tree with the sequential write functions, certain things
have to be done in a certain order.  You must create the memory reserve map
and only then can you create the actual tree structure.

The -FDT_ERR_BADSTATE return code is for if you try to do things out of
order.  However, we weren't checking that very thoroughly, so it was
possible to generate a corrupted blob if, for example, you started calling
fdt_begin_node() etc. before calling fdt_finish_reservemap().

This makes the state checking more thorough disallow that.

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:
David Gibson 2018-04-10 17:06:18 +10:00
parent 04b5b4062c
commit 899d6fad93
5 changed files with 218 additions and 15 deletions

1
tests/.gitignore vendored
View file

@ -58,6 +58,7 @@ tmp.*
/subnode_offset
/supernode_atdepth_offset
/sw_tree1
/sw_states
/truncated_property
/utilfdt_test
/value-labels