devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Devicetree Discuss
	<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: Re: [PATCH v2 3/3] RFC: Check offset in fdt_string()
Date: Fri, 22 Feb 2013 10:35:03 +1100	[thread overview]
Message-ID: <20130221233503.GH21011@truffula.fritz.box> (raw)
In-Reply-To: <1360968578-18443-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 1998 bytes --]

On Fri, Feb 15, 2013 at 02:49:38PM -0800, Simon Glass wrote:
> (We probably don't want this patch, and certainly can't apply it as is,
> but I send it in order to find out the intent of fdt_string()).
> 
> At present fdt_string() says that returns:
> 
>    - a pointer to the string, on success
>    - NULL, if stroffset is out of bounds
> 
> However it does not in fact return NULL. Changing it to do so also
> breaks 15 tests (segfault).
> 
> What is the intended behaviour of this function, please?

Ah.  Yes.  So I'm guessing the tests that fail are all the tests of
the sequential write functions (fdt_sw.c).  When the blob is in
sequential write mode, the string offsets work differently - they're
negative from a strings block pointer which sits at the end of the
strings.  That's because as we add new properties, the strings block
grows downwards.  The offsets get fixed up again in fdt_finish().

So, fdt_string() would need a special case for trees in SW mode.  I
also have a vague recollection that there was another reason I didn't
implement the bounds checking, but I seem to have forgotton what it
was :(.


> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> ---
> Changes in v2:
> - Drop patch to replace fdtdump
> 
>  libfdt/fdt_ro.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index 50007f6..cba8772 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -77,6 +77,8 @@ static int _fdt_nodename_eq(const void *fdt, int offset,
>  
>  const char *fdt_string(const void *fdt, int stroffset)
>  {
> +	if (stroffset < 0 || stroffset >= fdt_size_dt_strings(fdt))
> +		return NULL;
>  	return (const char *)fdt + fdt_off_dt_strings(fdt) + stroffset;
>  }
>  

-- 
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 #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

  parent reply	other threads:[~2013-02-21 23:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15 22:49 [PATCH v2 0/3] Introduce fdtgrep for subsetting and hashing FDTs Simon Glass
     [not found] ` <1360968578-18443-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2013-02-15 22:49   ` [PATCH v2 1/3] libfdt: Add function to find regions in an FDT Simon Glass
     [not found]     ` <1360968578-18443-2-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2013-03-13  3:46       ` Simon Glass
     [not found]         ` <CAPnjgZ2uPRtDZXt1AwtAnp702sEya6OxtDpEy1kUD=Wox=0CfA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-03-22 13:18           ` David Gibson
     [not found]             ` <20130322131849.GH13838-W9XWwYn+TF0XU02nzanrWNbf9cGiqdzd@public.gmane.org>
2013-04-16  0:50               ` Simon Glass
2013-02-15 22:49   ` [PATCH v2 2/3] Add fdtgrep to grep and subset FDTs Simon Glass
     [not found]     ` <1360968578-18443-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2013-04-16  2:37       ` Mike Frysinger
2013-02-15 22:49   ` [PATCH v2 3/3] RFC: Check offset in fdt_string() Simon Glass
     [not found]     ` <1360968578-18443-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2013-02-21 23:35       ` David Gibson [this message]
     [not found]         ` <20130221233503.GH21011-W9XWwYn+TF0XU02nzanrWNbf9cGiqdzd@public.gmane.org>
2013-02-28  0:42           ` Simon Glass

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=20130221233503.GH21011@truffula.fritz.box \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@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).