devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Subject: Re: [PATCH 2/4] tests: Enhance truncated_memrsv to test fdt_open_into()
Date: Sat, 12 Jun 2021 12:26:20 +1000	[thread overview]
Message-ID: <YMQbTJfZsOW+wLO4@yekko> (raw)
In-Reply-To: <20210611115823.31583-3-andre.przywara-5wv7dgnIgG8@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1602 bytes --]

On Fri, Jun 11, 2021 at 12:58:21PM +0100, Andre Przywara wrote:
> We already check that libfdt's r/o functions can deal properly with
> malformed blobs, where the memreserve block is not correct.
> 
> Add a test for fdt_open_into(), which also queries the memreserve block,
> and uses the return value as an offset into a buffer.
> 
> Signed-off-by: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>

Reviewed-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>

> ---
>  tests/truncated_memrsv.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/truncated_memrsv.c b/tests/truncated_memrsv.c
> index d78036c..9defef3 100644
> --- a/tests/truncated_memrsv.c
> +++ b/tests/truncated_memrsv.c
> @@ -18,7 +18,8 @@
>  int main(int argc, char *argv[])
>  {
>  	void *fdt = &truncated_memrsv;
> -	int err;
> +	char *buf;
> +	int err, bufsize;
>  	uint64_t addr, size;
>  
>  	test_init(argc, argv);
> @@ -46,5 +47,12 @@ int main(int argc, char *argv[])
>  		FAIL("fdt_get_mem_rsv(1) returned %d instead of -FDT_ERR_BADOFFSET",
>  		     err);
>  
> +	bufsize = fdt_totalsize(fdt);
> +	buf = xmalloc(bufsize);
> +	err = fdt_open_into(fdt, buf, bufsize);
> +	if (err != -FDT_ERR_TRUNCATED)
> +		FAIL("fdt_open_into() returned %d instead of -FDT_ERR_TRUNCATED",
> +		     err);
> +
>  	PASS();
>  }

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2021-06-12  2:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11 11:58 [PATCH 0/4] libfdt: Check for integer overflows Andre Przywara
     [not found] ` <20210611115823.31583-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-11 11:58   ` [PATCH 1/4] libfdt: Check for invalid memreserve block Andre Przywara
     [not found]     ` <20210611115823.31583-2-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-12  2:25       ` David Gibson
2021-06-11 11:58   ` [PATCH 2/4] tests: Enhance truncated_memrsv to test fdt_open_into() Andre Przywara
     [not found]     ` <20210611115823.31583-3-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-12  2:26       ` David Gibson [this message]
2021-06-11 11:58   ` [PATCH 3/4] libfdt: Check DT struct size for integer overflow Andre Przywara
     [not found]     ` <20210611115823.31583-4-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-12  2:29       ` David Gibson
2021-06-11 11:58   ` [PATCH 4/4] libfdt: Protect buffer size checks against " Andre Przywara
     [not found]     ` <20210611115823.31583-5-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2021-06-15  0:42       ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YMQbTJfZsOW+wLO4@yekko \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=andre.przywara-5wv7dgnIgG8@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).