Re: [PATCH] libfdt: fdt_path_offset_namelen: Reject empty path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Fri, Oct 06, 2023 at 07:22:14AM -0600, Simon Glass wrote:
> Hi Pierre-Clément,
> 
> On Fri, 6 Oct 2023 at 06:48, Pierre-Clément Tosi <ptosi@xxxxxxxxxx> wrote:
> >
> > Make empty paths result in FDT_ERR_BADPATH.
> >
> > Per the specification (v0.4-rc4):
> >
> > > The convention for specifying a device path is:
> > >     /node-name-1/node-name-2/node-name-N
> > >
> > > The path to the root node is /.
> > >
> > > A unit address may be omitted if the full path to the
> > > node is unambiguous.
> >
> > Signed-off-by: Pierre-Clément Tosi <ptosi@xxxxxxxxxx>
> > ---
> >  libfdt/fdt_ro.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> > index c4c520c..46b4ef5 100644
> > --- a/libfdt/fdt_ro.c
> > +++ b/libfdt/fdt_ro.c
> > @@ -255,6 +255,9 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
> >
> >         FDT_RO_PROBE(fdt);
> >
> > +       if (namelen < 1)
> > +               return -FDT_ERR_BADPATH;
> > +
> 
> This would be end == path, right? Would it be better to check that?

Not particularly, AFAICT.

> Are you worried about negative numbers?

If they're not, they probably should be..

> 
> >         /* see if we have an alias */
> >         if (*path != '/') {
> >                 const char *q = memchr(path, '/', end - p);
> >
> >
> >
> 
> Regards,
> Simon
> 

-- 
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: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux