On Mon, Sep 21, 2020 at 05:52:59PM +0100, Andre Przywara wrote: > With -Wsign-compare, compilers warn about a mismatching signedness > in a comparison in fdt_setprop_inplace_namelen_partial(). > > Since fdt_getprop_namelen() can return negative error values, check for > those first and bail out early. > Later on we can then safely cast the value to an unsigned type. > > Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx> > --- > libfdt/fdt_wip.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/libfdt/fdt_wip.c b/libfdt/fdt_wip.c > index f64139e..d1b4f1b 100644 > --- a/libfdt/fdt_wip.c > +++ b/libfdt/fdt_wip.c > @@ -20,10 +20,10 @@ int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, > > propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen, > &proplen); > - if (!propval) > + if (!propval || proplen < 0) > return proplen; We don't actually need that test - if proplen < 0 with propval non-NULL, that's a bug in fdt_getprop_namelen_w(). > - if (proplen < (len + idx)) > + if ((unsigned)proplen < (len + idx)) > return -FDT_ERR_NOSPACE; > > memcpy((char *)propval + idx, val, len); -- 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